Module: StimulusPlumbers::Tailwind::Generators::SourcesDirective

Defined in:
lib/stimulus_plumbers/tailwind/generators/sources_directive.rb

Constant Summary collapse

GEM_NAME =
"stimulus_plumbers_tailwind"
LIB_DIR =
File.expand_path("../../..", __dir__)
SOURCES_CSS_PATH =
"app/assets/builds/stimulus_plumbers/tailwind.css"

Class Method Summary collapse

Class Method Details

.anchor_patternObject



39
40
41
# File 'lib/stimulus_plumbers/tailwind/generators/sources_directive.rb', line 39

def anchor_pattern
  %r{@import "tailwindcss"[^;]*;}
end

.file_contents(from:) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/stimulus_plumbers/tailwind/generators/sources_directive.rb', line 27

def file_contents(from:)
  <<~CSS
    /*
     * Auto-generated by stimulus_plumbers:tailwind:install.
     * Holds a single @source pointing to the stimulus_plumbers_tailwind gem so the Tailwind CLI can scan its component class lists.
     * The path is absolute to this machine, so this file is git-ignored and regenerated on assets:precompile / tailwindcss:build.
     * Do not edit by hand.
     */
    #{source_line(from: from)}
  CSS
end

.import_directive(from:, destination_root:) ⇒ Object



15
16
17
18
19
20
# File 'lib/stimulus_plumbers/tailwind/generators/sources_directive.rb', line 15

def import_directive(from:, destination_root:)
  path = Pathname.new(destination_root).join(SOURCES_CSS_PATH)
  rel  = path.relative_path_from(Pathname.new(from))
  rel  = "./#{rel}" unless rel.to_s.start_with?(".", "/")
  %(@import "#{rel}";)
end

.removal_pattern(from:) ⇒ Object



51
52
53
# File 'lib/stimulus_plumbers/tailwind/generators/sources_directive.rb', line 51

def removal_pattern(from:)
  Regexp.union(stale_pattern, Regexp.new(Regexp.escape(source_line(from: from))))
end

.source_line(from:) ⇒ Object



22
23
24
25
# File 'lib/stimulus_plumbers/tailwind/generators/sources_directive.rb', line 22

def source_line(from:)
  rel = Pathname.new(LIB_DIR).relative_path_from(Pathname.new(from))
  %(@source "#{rel}/**/*.rb";)
end

.stale_patternObject



43
44
45
46
47
48
49
# File 'lib/stimulus_plumbers/tailwind/generators/sources_directive.rb', line 43

def stale_pattern
  Regexp.union(
    %r{@source "[^"]*#{Regexp.escape(GEM_NAME)}[^"]*";},
    %r{@import "[^"]*#{Regexp.escape(SOURCES_CSS_PATH)}";},
    %r{@import "[^"]*stimulus_plumbers/tailwind/sources\.css";}
  )
end