Class: PhlexKit::Generators::InstallGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- PhlexKit::Generators::InstallGenerator
- Defined in:
- lib/generators/phlex_kit/install/install_generator.rb
Overview
rails g phlex_kit:install — wires PhlexKit into a host app:
- drops an initializer,
- adds the manifest @import to application.css (url() form),
- prints the Stimulus registration snippet.
Constant Summary collapse
- IMPORT_LINE =
%(@import url("phlex_kit/phlex_kit.css");\n)
Instance Method Summary collapse
Instance Method Details
#add_stylesheet_import ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/generators/phlex_kit/install/install_generator.rb', line 20 def add_stylesheet_import css = "app/assets/stylesheets/application.css" unless File.exist?(css) say_status :skip, "#{css} not found — add `#{IMPORT_LINE.strip}` to your main stylesheet", :yellow return end if File.read(css).include?("phlex_kit/phlex_kit.css") say_status :identical, css, :blue else # @import must precede every rule, so prepend it. prepend_to_file css, IMPORT_LINE end end |
#create_initializer ⇒ Object
16 17 18 |
# File 'lib/generators/phlex_kit/install/install_generator.rb', line 16 def create_initializer template "phlex_kit.rb", "config/initializers/phlex_kit.rb" end |
#print_stimulus_instructions ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/generators/phlex_kit/install/install_generator.rb', line 34 def print_stimulus_instructions say <<~MSG PhlexKit installed. To enable the interactive components (Dialog, Dropdown, Select, Avatar), register the Stimulus controllers: import { registerPhlexKitControllers } from "phlex_kit/controllers" registerPhlexKitControllers(application) Render a component anywhere a Phlex view is allowed: render PhlexKit::Button.new(variant: :primary) { "Save" } MSG end |