Class: Terrazzo::Generators::DashboardGenerator

Inherits:
Rails::Generators::NamedBase
  • Object
show all
Includes:
Terrazzo::GeneratorHelpers
Defined in:
lib/generators/terrazzo/dashboard/dashboard_generator.rb

Instance Method Summary collapse

Methods included from Terrazzo::GeneratorHelpers

#column_to_field_type, #controller_name_for, #dashboard_name_for

Instance Method Details

#create_controllerObject



21
22
23
24
# File 'lib/generators/terrazzo/dashboard/dashboard_generator.rb', line 21

def create_controller
  template "controller.rb.erb",
    "app/controllers/#{options[:namespace]}/#{class_path.join('/')}/#{file_name.pluralize}_controller.rb".squeeze("/")
end

#create_dashboardObject



16
17
18
19
# File 'lib/generators/terrazzo/dashboard/dashboard_generator.rb', line 16

def create_dashboard
  template "dashboard.rb.erb",
    "app/dashboards/#{class_path.join('/')}/#{file_name}_dashboard.rb".squeeze("/")
end

#update_page_to_page_mappingObject



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/generators/terrazzo/dashboard/dashboard_generator.rb', line 26

def update_page_to_page_mapping
  return if options[:bundler] == "vite"

  mapping_path = "app/javascript/#{options[:namespace]}/page_to_page_mapping.js"
  return unless File.exist?(mapping_path)

  namespace_name = options[:namespace]
  action_to_component = {
    "index" => "AdminIndex",
    "show" => "AdminShow",
    "new" => "AdminNew",
    "edit" => "AdminEdit"
  }

  action_to_component.each do |action, component|
    key = "'#{namespace_name}/application/#{action}'"
    mapping_path_content = File.read(mapping_path)
    next if mapping_path_content.include?(key)

    inject_into_file mapping_path, before: "}" do
      "  #{key}: #{component},\n"
    end
  end
end