Class: Terrazzo::Generators::ViewsGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- Terrazzo::Generators::ViewsGenerator
- Defined in:
- lib/generators/terrazzo/views/views_generator.rb
Instance Method Summary collapse
- #create_components_barrel ⇒ Object
- #create_fields_barrel ⇒ Object
- #create_navigation_partial ⇒ Object
- #create_page_stubs ⇒ Object
- #create_ui_barrel ⇒ Object
Instance Method Details
#create_components_barrel ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/generators/terrazzo/views/views_generator.rb', line 19 def create_file "app/views/#{namespace_name}/components/index.js", <<~JS // Re-export all components from the terrazzo package. // To customize, run: rails g terrazzo:eject components/<component_name> export * from "terrazzo/components"; JS end |
#create_fields_barrel ⇒ Object
11 12 13 14 15 16 17 |
# File 'lib/generators/terrazzo/views/views_generator.rb', line 11 def create_file "app/views/#{namespace_name}/fields/index.js", <<~JS // Re-export all fields from the terrazzo package. // To customize a field, run: rails g terrazzo:eject fields/<field_type> export * from "terrazzo/fields"; JS end |
#create_navigation_partial ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/generators/terrazzo/views/views_generator.rb', line 35 def create_file "app/views/#{namespace_name}/application/_navigation.json.props", <<~RUBY resources = Terrazzo::Namespace.new(namespace).resources_with_index_route json.array! [{ label: "Resources", resources: resources }] do |group| json.label group[:label] json.items do json.array! group[:resources] do |r| json.label r.resource_name.humanize.pluralize json.path url_for(controller: "/\#{r.controller_path}", action: :index, only_path: true) json.active r.controller_path == controller_path end end end RUBY end |
#create_page_stubs ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/generators/terrazzo/views/views_generator.rb', line 52 def create_page_stubs { "index" => "AdminIndex", "show" => "AdminShow", "new" => "AdminNew", "edit" => "AdminEdit", }.each do |page, component| create_file "app/views/#{namespace_name}/application/#{page}.jsx", "export { #{component} as default } from \"terrazzo/pages\";\n" end end |
#create_ui_barrel ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/generators/terrazzo/views/views_generator.rb', line 27 def create_file "app/views/#{namespace_name}/components/ui/index.js", <<~JS // Re-export all UI primitives from the terrazzo package. // To customize, run: rails g terrazzo:eject ui/<component_name> export * from "terrazzo/ui"; JS end |