Class: Terrazzo::Generators::ViewsGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Defined in:
lib/generators/terrazzo/views/views_generator.rb

Instance Method Summary collapse

Instance Method Details

#create_components_barrelObject



19
20
21
22
23
24
25
# File 'lib/generators/terrazzo/views/views_generator.rb', line 19

def create_components_barrel
  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_barrelObject



11
12
13
14
15
16
17
# File 'lib/generators/terrazzo/views/views_generator.rb', line 11

def create_fields_barrel
  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_partialObject



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_navigation_partial
  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_stubsObject



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_barrelObject



27
28
29
30
31
32
33
# File 'lib/generators/terrazzo/views/views_generator.rb', line 27

def create_ui_barrel
  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