Class: DsfrComponentGenerator
- Inherits:
-
Rails::Generators::NamedBase
- Object
- Rails::Generators::NamedBase
- DsfrComponentGenerator
- Defined in:
- lib/generators/dsfr_component/dsfr_component_generator.rb
Constant Summary collapse
- COMPONENT_FOLDER =
"app/components/dsfr_component/".freeze
Instance Method Summary collapse
- #append_guide_helper ⇒ Object
- #map_component_helper ⇒ Object
- #write_component ⇒ Object
- #write_component_spec ⇒ Object
- #write_guide_helper ⇒ Object
- #write_guide_page ⇒ Object
Instance Method Details
#append_guide_helper ⇒ Object
34 35 36 37 38 |
# File 'lib/generators/dsfr_component/dsfr_component_generator.rb', line 34 def append_guide_helper destination = "guide/lib/helpers.rb" append_to_file destination, "use_helper Examples::#{name}Helpers\n" # trailing new line end |
#map_component_helper ⇒ Object
40 41 42 43 44 45 46 47 48 49 |
# File 'lib/generators/dsfr_component/dsfr_component_generator.rb', line 40 def map_component_helper destination = "app/helpers/dsfr_components_helper.rb" marker = "# DO NOT REMOVE: new component mapping here" mapping = "dsfr_#{file_name}: 'DsfrComponent::#{name}Component'," gsub_file(destination, marker, [mapping, marker].join("\n")) run "rubocop --format quiet -A #{destination}" end |
#write_component ⇒ Object
8 9 10 11 12 13 |
# File 'lib/generators/dsfr_component/dsfr_component_generator.rb', line 8 def write_component destination = File.join(COMPONENT_FOLDER, "#{file_name}_component.rb") template "component.rb.erb", destination run "rubocop --format quiet -A #{destination}" end |
#write_component_spec ⇒ Object
15 16 17 18 19 20 |
# File 'lib/generators/dsfr_component/dsfr_component_generator.rb', line 15 def write_component_spec destination = "spec/components/dsfr_component/#{file_name}_component_spec.rb" template "component_spec.rb.erb", destination run "rubocop --format quiet -A #{destination}" end |
#write_guide_helper ⇒ Object
28 29 30 31 32 |
# File 'lib/generators/dsfr_component/dsfr_component_generator.rb', line 28 def write_guide_helper destination = "guide/lib/examples/#{file_name}_helpers.rb" template "component_helper.rb.erb", destination end |
#write_guide_page ⇒ Object
22 23 24 25 26 |
# File 'lib/generators/dsfr_component/dsfr_component_generator.rb', line 22 def write_guide_page destination = "guide/content/components/#{file_name}.haml" template "component.haml.erb", destination end |