Class: Phlex::Reactive::Generators::ComponentGenerator
- Inherits:
-
Rails::Generators::NamedBase
- Object
- Rails::Generators::NamedBase
- Phlex::Reactive::Generators::ComponentGenerator
- Defined in:
- lib/generators/phlex/reactive/component/component_generator.rb
Overview
‘rails g phlex:reactive:component Counter [actions] [options]`
Examples:
rails g phlex:reactive:component Counter increment decrement
→ state-backed component with two actions
rails g phlex:reactive:component Todos::Item toggle rename --record=todo
→ record-backed component (signed GlobalID) with two actions
Generates the component under app/components and a matching spec under spec/components (or test/components for Minitest apps).
Instance Method Summary collapse
Instance Method Details
#create_component ⇒ Object
29 30 31 32 |
# File 'lib/generators/phlex/reactive/component/component_generator.rb', line 29 def create_component @component_path = File.join("app/components", class_path, "#{file_name}.rb") template "component.rb.erb", File.join(destination_root, @component_path) end |
#create_spec ⇒ Object
34 35 36 37 38 39 |
# File 'lib/generators/phlex/reactive/component/component_generator.rb', line 34 def create_spec return unless defined_rspec? @spec_path = File.join("spec/components", class_path, "#{file_name}_spec.rb") template "component_spec.rb.erb", File.join(destination_root, @spec_path) end |