Class: Solidstats::Generators::FeatureGenerator
- Inherits:
-
Rails::Generators::NamedBase
- Object
- Rails::Generators::NamedBase
- Solidstats::Generators::FeatureGenerator
- Defined in:
- lib/generators/solidstats/feature/feature_generator.rb
Instance Method Summary collapse
- #add_route ⇒ Object
- #create_component_helper ⇒ Object
- #create_component_partial ⇒ Object
- #create_component_styles ⇒ Object
- #create_component_test ⇒ Object
- #create_controller ⇒ Object
- #create_controller_test ⇒ Object
- #create_detail_view ⇒ Object
- #create_directory_structure ⇒ Object
- #create_preview ⇒ Object
- #create_service ⇒ Object
- #create_service_test ⇒ Object
- #integrate_with_dashboard ⇒ Object
- #show_next_steps ⇒ Object
- #update_dashboard_view ⇒ Object
Instance Method Details
#add_route ⇒ Object
55 56 57 58 59 60 |
# File 'lib/generators/solidstats/feature/feature_generator.rb', line 55 def add_route route_content = " get \"#{file_name}\", to: \"#{file_name}#index\", as: :#{file_name}" inject_into_file "config/routes.rb", after: "Solidstats::Engine.routes.draw do\n" do "#{route_content}\n" end end |
#create_component_helper ⇒ Object
19 20 21 |
# File 'lib/generators/solidstats/feature/feature_generator.rb', line 19 def create_component_helper template "component.rb.erb", "app/helpers/solidstats/#{file_name}_helper.rb" end |
#create_component_partial ⇒ Object
23 24 25 |
# File 'lib/generators/solidstats/feature/feature_generator.rb', line 23 def create_component_partial template "component.html.erb", "app/views/solidstats/dashboard/_#{file_name}_summary.html.erb" end |
#create_component_styles ⇒ Object
27 28 29 |
# File 'lib/generators/solidstats/feature/feature_generator.rb', line 27 def create_component_styles template "component.scss", "app/assets/stylesheets/solidstats/#{file_name}_component.scss" end |
#create_component_test ⇒ Object
47 48 49 |
# File 'lib/generators/solidstats/feature/feature_generator.rb', line 47 def create_component_test template "component_test.rb.erb", "test/helpers/solidstats/#{file_name}_helper_test.rb" end |
#create_controller ⇒ Object
39 40 41 |
# File 'lib/generators/solidstats/feature/feature_generator.rb', line 39 def create_controller template "controller.rb.erb", "app/controllers/solidstats/#{file_name}_controller.rb" end |
#create_controller_test ⇒ Object
51 52 53 |
# File 'lib/generators/solidstats/feature/feature_generator.rb', line 51 def create_controller_test template "controller_test.rb.erb", "test/controllers/solidstats/#{file_name}_controller_test.rb" end |
#create_detail_view ⇒ Object
35 36 37 |
# File 'lib/generators/solidstats/feature/feature_generator.rb', line 35 def create_detail_view template "detail_view.html.erb", "app/views/solidstats/#{file_name}/index.html.erb" end |
#create_directory_structure ⇒ Object
140 141 142 |
# File 'lib/generators/solidstats/feature/feature_generator.rb', line 140 def create_directory_structure empty_directory "app/views/solidstats/#{file_name}" end |
#create_preview ⇒ Object
31 32 33 |
# File 'lib/generators/solidstats/feature/feature_generator.rb', line 31 def create_preview template "preview.rb.erb", "app/views/solidstats/#{file_name}/preview.html.erb" end |
#create_service ⇒ Object
15 16 17 |
# File 'lib/generators/solidstats/feature/feature_generator.rb', line 15 def create_service template "service.rb.erb", "app/services/solidstats/#{file_name}_service.rb" end |
#create_service_test ⇒ Object
43 44 45 |
# File 'lib/generators/solidstats/feature/feature_generator.rb', line 43 def create_service_test template "service_test.rb.erb", "test/services/solidstats/#{file_name}_service_test.rb" end |
#integrate_with_dashboard ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/generators/solidstats/feature/feature_generator.rb', line 62 def integrate_with_dashboard # Add instance variable to dashboard controller inject_into_file "app/controllers/solidstats/dashboard_controller.rb", after: "def index\n" do " @#{file_name}_data = #{class_name}Service.new.summary\n" end # Add to refresh method inject_into_file "app/controllers/solidstats/dashboard_controller.rb", after: "def refresh\n" do " #{file_name}_data = #{class_name}Service.new.fetch(true)\n" end # Add to refresh JSON response inject_into_file "app/controllers/solidstats/dashboard_controller.rb", after: "render json: {\n" do " #{file_name}_data: #{file_name}_data,\n" end end |
#show_next_steps ⇒ Object
144 145 146 147 148 149 150 151 152 153 |
# File 'lib/generators/solidstats/feature/feature_generator.rb', line 144 def show_next_steps say "\n" + set_color("#{human_name} feature generated successfully!", :green, :bold) say "\nNext steps:" say " 1. Implement data collection logic in #{set_color("app/services/solidstats/#{file_name}_service.rb", :yellow)}" say " 2. Customize the component template in #{set_color("app/components/solidstats/#{file_name}_component.html.erb", :yellow)}" say " 3. Add any required styling in #{set_color("app/components/solidstats/#{file_name}_component.scss", :yellow)}" say " 4. Run tests: #{set_color("rails test test/services/solidstats/#{file_name}_service_test.rb", :cyan)}" say " 5. Visit #{set_color("http://localhost:3000/rails/view_components", :cyan)} to preview the component" say "\nThe feature will appear in the #{set_color([:section], :blue)} section of the dashboard." end |
#update_dashboard_view ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/generators/solidstats/feature/feature_generator.rb', line 82 def update_dashboard_view # Add summary card to overview section card_partial = <<~ERB <div class="summary-card <%= @#{file_name}_data&.dig(:status) || 'status-ok' %>" data-section="#{[:section]}" data-tab="#{file_name.dasherize}"> <div class="summary-icon">#{[:icon]}</div> <div class="summary-data"> <div class="summary-value"><%= @#{file_name}_data&.dig(:value) || 0 %></div> <div class="summary-label">#{human_name}</div> </div> </div> ERB inject_into_file "app/views/solidstats/dashboard/index.html.erb", after: '<div class="stats-summary">' do card_partial end # Add section if it doesn't exist for metrics if [:section] == "metrics" section_content = <<~ERB <!-- #{human_name} Section --> <section id="#{file_name.dasherize}" class="dashboard-section"> <h2 class="section-title">#{human_name}</h2> <%= render Solidstats::#{class_name}Component.new(data: @#{file_name}_data) %> </section> ERB inject_into_file "app/views/solidstats/dashboard/index.html.erb", before: " <!-- Floating quick navigation -->" do section_content end # Add to navigation nav_item = <<~ERB <li><a href="##{file_name.dasherize}" class="nav-item" data-section="#{file_name.dasherize}">#{human_name}</a></li> ERB inject_into_file "app/views/solidstats/dashboard/index.html.erb", after: '<nav class="dashboard-nav">' do " <ul>#{nav_item}" end # Add to quick nav quick_nav_item = <<~ERB <a href="##{file_name.dasherize}" class="quick-nav-item">#{human_name}</a> ERB inject_into_file "app/views/solidstats/dashboard/index.html.erb", after: '<div class="quick-nav-menu">' do quick_nav_item end end end |