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
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/generators/terrazzo/views/views_generator.rb', line 36 def create_file "app/views/#{namespace_name}/application/_navigation.json.props", <<~RUBY resources = Terrazzo::Namespace.new(namespace).navigation_resources navigation_groups = resources.group_by(&:navigation_group).map do |label, items| { label: label, items: items } end json.array! navigation_groups do |group| json.label group[:label] json.items do json.array! group[:items] do |r| json.label r.navigation_label 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
56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/generators/terrazzo/views/views_generator.rb', line 56 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 34 |
# 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. // Ejected pages, fields, and components import this barrel. // To customize those app-owned files, run: rails g terrazzo:eject ui/<component_name> export * from "terrazzo/ui"; JS end |