Skip to content

Commit 3e05ec1

Browse files
committed
Make files with class names configurable
1 parent a83bff4 commit 3e05ec1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+935
-6
lines changed

lib/tailwindcss/compressor.rb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,8 @@ def call(input)
2525
end
2626

2727
private
28+
2829
def files_with_class_names
29-
Rails.root.glob("app/views/**/*.*") +
30-
Rails.root.glob("app/helpers/**/*.rb") +
31-
Rails.root.glob("app/javascript/**/*.js")
30+
Rails.application.config.tailwind.files_with_class_names
3231
end
3332
end

lib/tailwindcss/engine.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22

33
module Tailwindcss
44
class Engine < ::Rails::Engine
5+
config.tailwind = ActiveSupport::OrderedOptions.new
6+
config.tailwind.files_with_class_names = []
7+
8+
initializer "set files with class names" do
9+
config.tailwind.files_with_class_names += Rails.root.glob("app/views/**/*.*") + Rails.root.glob("app/helpers/**/*.rb") + Rails.root.glob("app/javascript/**/*.js")
10+
end
11+
512
initializer "tailwindcss.compressor" do
613
Sprockets.register_compressor "text/css", :purger, Tailwindcss::Compressor
714
end

lib/tasks/tailwindcss_tasks.rake

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ namespace :tailwindcss do
55
end
66

77
desc "Show the list of class names being kept in Tailwind CSS"
8-
task :keeping_class_names do
8+
task keeping_class_names: :environment do
99
puts Tailwindcss::Purger.extract_class_names_from(default_files_with_class_names)
1010
end
1111

@@ -16,7 +16,7 @@ namespace :tailwindcss do
1616
end
1717

1818
def default_files_with_class_names
19-
Rails.root.glob("app/views/**/*.*") + Rails.root.glob("app/helpers/**/*.rb")
19+
Rails.application.config.tailwind.files_with_class_names
2020
end
2121

2222
def tailwind_css

test/compressor_test.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
require "test_helper"
2+
3+
class Tailwindcss::CompressorTest < ActiveSupport::TestCase
4+
test "files_with_class_names on default configuration" do
5+
default_files_with_class_names = Rails.root.glob("app/views/**/*.*") + Rails.root.glob("app/helpers/**/*.rb")
6+
7+
assert_equal default_files_with_class_names, Tailwindcss::Compressor.new.instance_variable_get(:@options)[:files_with_class_names]
8+
end
9+
10+
test "files_with_class_names on custom configuration" do
11+
files_with_class_names = Rails.application.config.tailwind.files_with_class_names + Rails.root.glob("app/custom_views/**/*.*")
12+
with_files_with_class_names_configuration(files_with_class_names) do
13+
assert_equal files_with_class_names, Tailwindcss::Compressor.new.instance_variable_get(:@options)[:files_with_class_names]
14+
end
15+
end
16+
end

test/dummy/Rakefile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Add your own tasks in files placed in lib/tasks ending in .rake,
2+
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3+
4+
require_relative "config/application"
5+
6+
Rails.application.load_tasks
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
//= link_tree ../images
2+
//= link_directory ../stylesheets .css

test/dummy/app/assets/images/.keep

Whitespace-only changes.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/*
2+
* This is a manifest file that'll be compiled into application.css, which will include all the files
3+
* listed below.
4+
*
5+
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6+
* or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
7+
*
8+
* You're free to add application-wide styles to this file and they'll appear at the bottom of the
9+
* compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS
10+
* files in this directory. Styles in this file should be added after the last require_* statement.
11+
* It is generally better to create a new file per style scope.
12+
*
13+
*= require_tree .
14+
*= require_self
15+
*/
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module ApplicationCable
2+
class Channel < ActionCable::Channel::Base
3+
end
4+
end
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module ApplicationCable
2+
class Connection < ActionCable::Connection::Base
3+
end
4+
end
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
class ApplicationController < ActionController::Base
2+
end

test/dummy/app/controllers/concerns/.keep

Whitespace-only changes.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
class PostsController < ApplicationController
2+
def index; end
3+
end
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<h1 class="font-bold text-red-500">Posts</h1>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
module ApplicationHelper
2+
end
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// This is a manifest file that'll be compiled into application.js, which will include all the files
2+
// listed below.
3+
//
4+
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5+
// or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
6+
//
7+
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8+
// compiled file. JavaScript code in this file should be added after the last require_* statement.
9+
//
10+
// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
11+
// about supported directives.
12+
//
13+
//= require rails-ujs
14+
//= require activestorage
15+
//= require_tree .
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
class ApplicationJob < ActiveJob::Base
2+
# Automatically retry jobs that encountered a deadlock
3+
# retry_on ActiveRecord::Deadlocked
4+
5+
# Most jobs are safe to ignore if the underlying records are no longer available
6+
# discard_on ActiveJob::DeserializationError
7+
end
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
class ApplicationMailer < ActionMailer::Base
2+
default from: 'from@example.com'
3+
layout 'mailer'
4+
end
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
class ApplicationRecord < ActiveRecord::Base
2+
self.abstract_class = true
3+
end

test/dummy/app/models/concerns/.keep

Whitespace-only changes.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>Dummy</title>
5+
<meta name="viewport" content="width=device-width,initial-scale=1">
6+
<%= csrf_meta_tags %>
7+
<%= csp_meta_tag %>
8+
<%= stylesheet_link_tag "inter-font", "data-turbo-track": "reload" %>
9+
<%= stylesheet_link_tag "tailwind", "data-turbo-track": "reload" %>
10+
11+
<%= stylesheet_link_tag 'application', media: 'all' %>
12+
</head>
13+
14+
<body>
15+
<%= yield %>
16+
</body>
17+
</html>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5+
<style>
6+
/* Email styles need to be inline */
7+
</style>
8+
</head>
9+
10+
<body>
11+
<%= yield %>
12+
</body>
13+
</html>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<%= yield %>

test/dummy/bin/rails

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/usr/bin/env ruby
2+
APP_PATH = File.expand_path('../config/application', __dir__)
3+
require_relative "../config/boot"
4+
require "rails/commands"

test/dummy/bin/rake

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/usr/bin/env ruby
2+
require_relative "../config/boot"
3+
require "rake"
4+
Rake.application.run

test/dummy/bin/setup

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/usr/bin/env ruby
2+
require "fileutils"
3+
4+
# path to your application root.
5+
APP_ROOT = File.expand_path('..', __dir__)
6+
7+
def system!(*args)
8+
system(*args) || abort("\n== Command #{args} failed ==")
9+
end
10+
11+
FileUtils.chdir APP_ROOT do
12+
# This script is a way to set up or update your development environment automatically.
13+
# This script is idempotent, so that you can run it at any time and get an expectable outcome.
14+
# Add necessary setup steps to this file.
15+
16+
puts '== Installing dependencies =='
17+
system! 'gem install bundler --conservative'
18+
system('bundle check') || system!('bundle install')
19+
20+
# puts "\n== Copying sample files =="
21+
# unless File.exist?('config/database.yml')
22+
# FileUtils.cp 'config/database.yml.sample', 'config/database.yml'
23+
# end
24+
25+
puts "\n== Preparing database =="
26+
system! 'bin/rails db:prepare'
27+
28+
puts "\n== Removing old logs and tempfiles =="
29+
system! 'bin/rails log:clear tmp:clear'
30+
31+
puts "\n== Restarting application server =="
32+
system! 'bin/rails restart'
33+
end

test/dummy/config.ru

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# This file is used by Rack-based servers to start the application.
2+
3+
require_relative "config/environment"
4+
5+
run Rails.application
6+
Rails.application.load_server

test/dummy/config/application.rb

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
require_relative "boot"
2+
3+
require "rails/all"
4+
5+
# Require the gems listed in Gemfile, including any gems
6+
# you've limited to :test, :development, or :production.
7+
Bundler.require(*Rails.groups)
8+
require "tailwindcss-rails"
9+
10+
module Dummy
11+
class Application < Rails::Application
12+
config.load_defaults Rails::VERSION::STRING.to_f
13+
14+
config.paths["app/views"].unshift("#{Rails.root}/app/custom_views")
15+
16+
# Configuration to set custom_views as another files_with_class_names for Tailwindcss
17+
# config.tailwind.files_with_class_names += Rails.root.glob("app/custom_views/**/*.*")
18+
19+
# Configuration for the application, engines, and railties goes here.
20+
#
21+
# These settings can be overridden in specific environments using the files
22+
# in config/environments, which are processed later.
23+
#
24+
# config.time_zone = "Central Time (US & Canada)"
25+
# config.eager_load_paths << Rails.root.join("extras")
26+
end
27+
end

test/dummy/config/boot.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Set up gems listed in the Gemfile.
2+
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../../Gemfile', __dir__)
3+
4+
require "bundler/setup" if File.exist?(ENV["BUNDLE_GEMFILE"])
5+
$LOAD_PATH.unshift File.expand_path('../../../lib', __dir__)

test/dummy/config/cable.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
development:
2+
adapter: async
3+
4+
test:
5+
adapter: test
6+
7+
production:
8+
adapter: redis
9+
url: <%= ENV.fetch("REDIS_URL") { "redis://localhost:6379/1" } %>
10+
channel_prefix: dummy_production

test/dummy/config/database.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# SQLite. Versions 3.8.0 and up are supported.
2+
# gem install sqlite3
3+
#
4+
# Ensure the SQLite 3 gem is defined in your Gemfile
5+
# gem 'sqlite3'
6+
#
7+
default: &default
8+
adapter: sqlite3
9+
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
10+
timeout: 5000
11+
12+
development:
13+
<<: *default
14+
database: db/development.sqlite3
15+
16+
# Warning: The database defined as "test" will be erased and
17+
# re-generated from your development database when you run "rake".
18+
# Do not set this db to the same as development or production.
19+
test:
20+
<<: *default
21+
database: db/test.sqlite3
22+
23+
production:
24+
<<: *default
25+
database: db/production.sqlite3

test/dummy/config/environment.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Load the Rails application.
2+
require_relative "application"
3+
4+
# Initialize the Rails application.
5+
Rails.application.initialize!
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
require "active_support/core_ext/integer/time"
2+
3+
Rails.application.configure do
4+
# Settings specified here will take precedence over those in config/application.rb.
5+
6+
# In the development environment your application's code is reloaded any time
7+
# it changes. This slows down response time but is perfect for development
8+
# since you don't have to restart the web server when you make code changes.
9+
config.cache_classes = false
10+
11+
# Do not eager load code on boot.
12+
config.eager_load = false
13+
14+
# Show full error reports.
15+
config.consider_all_requests_local = true
16+
17+
# Enable/disable caching. By default caching is disabled.
18+
# Run rails dev:cache to toggle caching.
19+
if Rails.root.join('tmp', 'caching-dev.txt').exist?
20+
config.action_controller.perform_caching = true
21+
config.action_controller.enable_fragment_cache_logging = true
22+
23+
config.cache_store = :memory_store
24+
config.public_file_server.headers = {
25+
'Cache-Control' => "public, max-age=#{2.days.to_i}"
26+
}
27+
else
28+
config.action_controller.perform_caching = false
29+
30+
config.cache_store = :null_store
31+
end
32+
33+
# Store uploaded files on the local file system (see config/storage.yml for options).
34+
config.active_storage.service = :local
35+
36+
# Don't care if the mailer can't send.
37+
config.action_mailer.raise_delivery_errors = false
38+
39+
config.action_mailer.perform_caching = false
40+
41+
# Print deprecation notices to the Rails logger.
42+
config.active_support.deprecation = :log
43+
44+
# Raise exceptions for disallowed deprecations.
45+
config.active_support.disallowed_deprecation = :raise
46+
47+
# Tell Active Support which deprecation messages to disallow.
48+
config.active_support.disallowed_deprecation_warnings = []
49+
50+
# Raise an error on page load if there are pending migrations.
51+
config.active_record.migration_error = :page_load
52+
53+
# Highlight code that triggered database queries in logs.
54+
config.active_record.verbose_query_logs = true
55+
56+
# Debug mode disables concatenation and preprocessing of assets.
57+
# This option may cause significant delays in view rendering with a large
58+
# number of complex assets.
59+
config.assets.debug = true
60+
61+
# Suppress logger output for asset requests.
62+
config.assets.quiet = true
63+
64+
# Raises error for missing translations.
65+
# config.i18n.raise_on_missing_translations = true
66+
67+
# Annotate rendered view with file names.
68+
# config.action_view.annotate_rendered_view_with_filenames = true
69+
70+
# Use an evented file watcher to asynchronously detect changes in source code,
71+
# routes, locales, etc. This feature depends on the listen gem.
72+
# config.file_watcher = ActiveSupport::EventedFileUpdateChecker
73+
74+
# Uncomment if you wish to allow Action Cable access from any origin.
75+
# config.action_cable.disable_request_forgery_protection = true
76+
end

0 commit comments

Comments
 (0)