Class: ViewPrimitives::Generators::InstallGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- ViewPrimitives::Generators::InstallGenerator
show all
- Includes:
- Detector
- Defined in:
- lib/generators/view_primitives/install/install_generator.rb
Constant Summary
Constants included
from Detector
Detector::JS_CONTROLLER_DIRS, Detector::TAILWIND_ENTRIES
Instance Method Summary
collapse
Instance Method Details
#create_application_component ⇒ Object
20
21
22
23
24
25
26
27
28
|
# File 'lib/generators/view_primitives/install/install_generator.rb', line 20
def create_application_component
target = "app/components/application_component.rb"
if File.exist?(File.join(destination_root, target))
say " ApplicationComponent already exists. Add `include ViewPrimitives::ClassHelper` manually.", :yellow
else
template "application_component.rb.tt", target
end
end
|
#create_css_variables ⇒ Object
30
31
32
|
# File 'lib/generators/view_primitives/install/install_generator.rb', line 30
def create_css_variables
copy_file "view_primitives.css", css_dest_path
end
|
#inject_css_import ⇒ Object
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
# File 'lib/generators/view_primitives/install/install_generator.rb', line 34
def inject_css_import
entry = tailwind_entry_path
unless entry
say "\n Could not detect a Tailwind CSS entry point.", :yellow
say " Add this line to your main CSS file:\n"
say " @import \"./view_primitives\";\n"
say " Common locations: app/assets/tailwind/application.css, " \
"app/assets/stylesheets/application.tailwind.css, app/javascript/application.css\n", :cyan
return
end
entry_content = File.read(File.join(destination_root, entry))
if entry_content.include?("view_primitives")
say " #{entry} already imports view_primitives — skipping.", :yellow
return
end
import_line = "@import \"#{css_import_path}\";\n"
if entry_content.include?('@import "tailwindcss"')
inject_into_file entry, import_line, after: "@import \"tailwindcss\"\n"
elsif entry_content.include?("@import 'tailwindcss'")
inject_into_file entry, import_line, after: "@import 'tailwindcss'\n"
else
append_to_file entry, "\n#{import_line}"
end
end
|
#verify_ui_inflection ⇒ Object
12
13
14
15
16
17
18
|
# File 'lib/generators/view_primitives/install/install_generator.rb', line 12
def verify_ui_inflection
return if "ui/button".camelize == "UI::ButtonComponent"
say "\n Warning: ActiveSupport inflection for `UI` is not configured.", :yellow
say " ViewPrimitives expects `ui/button` to resolve to `UI::ButtonComponent`.", :yellow
say " The gem registers this automatically — restart the Rails server if you just installed.\n", :yellow
end
|