Class: Spotlight::ScaffoldResource

Inherits:
Rails::Generators::NamedBase
  • Object
show all
Defined in:
lib/generators/spotlight/scaffold_resource_generator.rb

Overview

spotlight:scaffold_resource generator

Instance Method Summary collapse

Instance Method Details

#create_controllerObject



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/generators/spotlight/scaffold_resource_generator.rb', line 23

def create_controller
  create_file "app/controllers/#{file_name}_resources_controller.rb", <<~FILE
    class #{class_name}ResourcesController < Spotlight::ResourcesController
      private

      def resource_class
        #{class_name}Resource
      end
    end
  FILE
end

#create_formObject



35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/generators/spotlight/scaffold_resource_generator.rb', line 35

def create_form
  create_file "app/views/#{file_name}_resources/_form.html.erb", <<~FILE
    <%= bootstrap_form_for([current_exhibit, @resource.becomes(#{class_name}Resource)], as: :resource) do |f| %>
      <%= f.text_field :url  %>
      <div class="form-actions">
        <div class="primary-actions">
          <%= cancel_link @resource, :back, class: 'btn btn-secondary' %>
          <%= f.submit t('.add_item'), class: 'btn btn-primary' %>
        </div>
      </div>
    <% end if can? :manage, @resource %>
  FILE
end

#create_modelObject



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/generators/spotlight/scaffold_resource_generator.rb', line 11

def create_model
  create_file "app/models/#{file_name}_resource.rb", <<~FILE
    class #{class_name}Resource < Spotlight::Resource
      def self.indexing_pipeline
        @indexing_pipeline ||= super.dup.tap do |pipeline|
          # your pipeline here...
        end
      end
    end
  FILE
end