Class: Tailwindcss::Compiler::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/tailwindcss/compiler/runner.rb

Instance Method Summary collapse

Constructor Details

#initialize(watch: nil) ⇒ Runner

Returns a new instance of Runner.



12
13
14
# File 'lib/tailwindcss/compiler/runner.rb', line 12

def initialize(watch: nil)
  @watch = watch
end

Instance Method Details

#callObject

rubocop:disable Metrics/AbcSize, Metrics/MethodLength



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/tailwindcss/compiler/runner.rb', line 16

def call # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
  output = Output.new
  file_classes_extractor = FileClassesExtractor.new

  content.each do |location|
    if watch || (watch.nil? && Tailwindcss.config.watch_content)
      listener = Listen.to(File.dirname(location.to_s), only: /\.(rb|erb)$/) do |modified, added, removed|
        Tailwindcss.logger.info "Recompiling Tailwindcss..."
        Tailwindcss.logger.info "Modified: #{modified}"
        Tailwindcss.logger.info "Added: #{added}"
        Tailwindcss.logger.info "Removed: #{removed}"
        (modified + added + removed).compact.each do |file_path|
          next unless File.file?(file_path)

          classes = file_classes_extractor.call(file_path:)
          next unless classes.present?

          output.add_entry(file_path:, classes:)
        end

        Tailwindcss.compile_css!
      end

      listener.start
    end

    Dir.glob("#{location}/**/*").each do |file_path|
      next unless File.file?(file_path)

      classes = file_classes_extractor.call(file_path:)
      next unless classes.present?

      output.add_entry(file_path:, classes:)
    end
  end

  Tailwindcss.compile_css!
end