From fff6a0a1435b370299332ae59b46b0249bebb18c Mon Sep 17 00:00:00 2001 From: andresgutgon Date: Tue, 12 Oct 2021 10:41:36 +0200 Subject: [PATCH] DRY default_files_with_class_names list of folders --- lib/tailwindcss/compressor.rb | 9 +-------- lib/tailwindcss/purger.rb | 6 ++++++ lib/tasks/tailwindcss_tasks.rake | 2 +- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/lib/tailwindcss/compressor.rb b/lib/tailwindcss/compressor.rb index f8c3889f..6b631643 100644 --- a/lib/tailwindcss/compressor.rb +++ b/lib/tailwindcss/compressor.rb @@ -11,7 +11,7 @@ def self.call(input) def initialize(options = {}) @options = { - files_with_class_names: files_with_class_names, + files_with_class_names: Tailwindcss::Purger.default_files_with_class_names, only_purge: %w[ tailwind ] }.merge(options).freeze end @@ -23,11 +23,4 @@ def call(input) input[:data] end end - - private - def files_with_class_names - Rails.root.glob("app/views/**/*.*") + - Rails.root.glob("app/helpers/**/*.rb") + - Rails.root.glob("app/javascript/**/*.js") - end end diff --git a/lib/tailwindcss/purger.rb b/lib/tailwindcss/purger.rb index 1c535e41..85860869 100644 --- a/lib/tailwindcss/purger.rb +++ b/lib/tailwindcss/purger.rb @@ -39,6 +39,12 @@ def extract_class_names_from(files) def escape_class_selector(class_name) class_name.gsub(/\A\d|[^-_a-z0-9]/, '\\\\\0') end + + def default_files_with_class_names + Rails.root.glob("app/views/**/*.*") + + Rails.root.glob("app/helpers/**/*.rb") + + Rails.root.glob("app/javascript/**/*.js") + end end def initialize(keep_these_class_names) diff --git a/lib/tasks/tailwindcss_tasks.rake b/lib/tasks/tailwindcss_tasks.rake index f568e76f..545acdca 100644 --- a/lib/tasks/tailwindcss_tasks.rake +++ b/lib/tasks/tailwindcss_tasks.rake @@ -16,7 +16,7 @@ namespace :tailwindcss do end def default_files_with_class_names - Rails.root.glob("app/views/**/*.*") + Rails.root.glob("app/helpers/**/*.rb") + Tailwindcss::Purger.default_files_with_class_names end def tailwind_css