Module: UiComponents::Config

Defined in:
lib/ui_components/config.rb,
lib/ui_components/config/daisy_ui_class_names.rb,
lib/ui_components/config/tailwind_class_names.rb

Defined Under Namespace

Modules: DaisyUiClassNames, TailwindClassNames

Class Method Summary collapse

Class Method Details

.inject_into_file(file_path:, file_data:) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/ui_components/config.rb', line 8

def inject_into_file(file_path:, file_data:)
  return unless File.exist?(file_path)

  file_content = File.read(file_path)

  return if file_content.include?(file_data)

  File.open(file_path, "a") do |file|
    file.puts file_data
  end
end

.inject_into_routes(file_path:, route_line:) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/ui_components/config.rb', line 20

def inject_into_routes(file_path:, route_line:)
  return unless File.exist?(file_path)

  file_content = File.read(file_path)

  return if file_content.include?(route_line.strip)

  updated_content = file_content.gsub(
    /Rails\.application\.routes\.draw do\n/,
    "Rails.application.routes.draw do\n  #{route_line}\n"
  )

  File.open(file_path, "w") { |file| file.write(updated_content) }
end

.js_controllers_pathObject



35
36
37
# File 'lib/ui_components/config.rb', line 35

def js_controllers_path
  UiComponents::Engine.root.join("app/assets/javascripts/ui_components/controllers")
end

.safelist!Object



39
40
41
42
43
44
45
46
47
48
49
# File 'lib/ui_components/config.rb', line 39

def safelist!
  file_content =(
    UiComponents::Config::DaisyUiClassNames.all +
    UiComponents::Config::TailwindClassNames.all +
    DocumentationComponent::CSS_CLASSES
  ).uniq.sort.join(" ")

  File.write(Rails.root.join("safelist.txt"), file_content)

  file_content
end