Class: Hibiki::Rails::Generators::PhlexGenerator
- Inherits:
-
Rails::Generators::NamedBase
- Object
- Rails::Generators::NamedBase
- Hibiki::Rails::Generators::PhlexGenerator
show all
- Includes:
- GeneratorHelpers
- Defined in:
- lib/generators/hibiki/rails/phlex/phlex_generator.rb
Overview
The Phlex component shape — the component owns the state
(Hibiki::Reactive), the channel owns the transport: one render
effect re-renders the same instance and transmits the HTML over
the channel's own subscription (no Turbo streams involved).
Emits a working mini-example: channel + component + an island
wrapper component renderable from any page.
Generated code needs the hibiki_phlex gem (and phlex-rails to
render components from views) — warn, don't fail, when it isn't
in the bundle, so the scaffold can come first.
Constant Summary
GeneratorHelpers::APPLICATION_HELPER, GeneratorHelpers::IMPORTMAP, GeneratorHelpers::INDEX_JS, GeneratorHelpers::REGISTER_FRAGMENT, GeneratorHelpers::SHIM
Instance Method Summary
collapse
Instance Method Details
#create_channel ⇒ Object
35
36
37
|
# File 'lib/generators/hibiki/rails/phlex/phlex_generator.rb', line 35
def create_channel
template "channel.rb.tt", "app/channels/#{file_path}_channel.rb"
end
|
#create_component ⇒ Object
39
40
41
|
# File 'lib/generators/hibiki/rails/phlex/phlex_generator.rb', line 39
def create_component
template "component.rb.tt", "app/components/#{file_path}.rb"
end
|
#create_island_component ⇒ Object
43
44
45
|
# File 'lib/generators/hibiki/rails/phlex/phlex_generator.rb', line 43
def create_island_component
template "island_component.rb.tt", "app/components/#{file_path}_island.rb"
end
|
#post_install ⇒ Object
47
48
49
50
51
52
53
54
55
56
|
# File 'lib/generators/hibiki/rails/phlex/phlex_generator.rb', line 47
def post_install
say <<~MSG
Render it from any page:
<%= render #{class_name}Island.new %>
MSG
register_hint
end
|
#warn_without_hibiki_phlex ⇒ Object
27
28
29
30
31
32
33
|
# File 'lib/generators/hibiki/rails/phlex/phlex_generator.rb', line 27
def warn_without_hibiki_phlex
require "hibiki/phlex"
rescue LoadError
say_status :warn, "hibiki_phlex is not in this bundle — the generated channel " \
"calls Hibiki::Phlex.render_effect. Add `gem \"hibiki_phlex\"` " \
"(and `gem \"phlex-rails\"` to render components from views).", :yellow
end
|