Class: AmberComponentGenerator

Inherits:
Rails::Generators::NamedBase
  • Object
show all
Defined in:
lib/generators/amber_component_generator.rb

Overview

A Rails generator which creates a new Amber component.

Direct Known Subclasses

ComponentGenerator

Instance Method Summary collapse

Instance Method Details

#file_nameString

Returns:

  • (String)


40
41
42
43
44
45
# File 'lib/generators/amber_component_generator.rb', line 40

def file_name
  name = super
  return name if name.end_with? '_component'

  "#{name}_component"
end

#generate_componentObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/generators/amber_component_generator.rb', line 20

def generate_component
  set_view_format
  set_stylesheet_format

  unless ::AmberComponent::Configuration::ALLOWED_VIEWS.include? @view_format
    raise ::ArgumentError, "No such view format as `#{@view_format}`"
  end

  unless ::AmberComponent::Configuration::ALLOWED_STYLES.include?(@stylesheet_format)
    raise ::ArgumentError, "No such css/style format as `#{@stylesheet_format}`"
  end

  template 'component.rb.erb', "app/components/#{file_path}.rb"
  template 'component_test.rb.erb', "test/components/#{file_path}_test.rb"
  create_stylesheet
  create_view
  create_stimulus_controller
end