Sha256: 937649a66ca5a41de01214114e8c165884bb167e9fc15b439d85b5e75b98c510

Contents?: true

Size: 1.31 KB

Versions: 74

Compression:

Stored size: 1.31 KB

Contents

# frozen_string_literal: true
module Blacklight
  class ControllerGenerator < Rails::Generators::Base
    source_root File.expand_path('../templates', __FILE__)

    argument :controller_name, type: :string, default: "catalog"

    desc <<-EOS
      This generator makes the following changes to your application:
       1. Injects behavior into your user application_controller.rb
       2. Creates a Blacklight::Catalog-based controller
       3. Adds routes for your controller
    EOS

    # Add Blacklight to the application controller
    def inject_blacklight_controller_behavior
      inject_into_class "app/controllers/application_controller.rb", "ApplicationController" do
        "  # Adds a few additional behaviors into the application controller\n" \
        "  include Blacklight::Controller\n" \
        "  layout :determine_layout if respond_to? :layout\n\n"
      end
    end

    # Generate blacklight catalog controller
    def create_blacklight_catalog
      template "catalog_controller.rb", "app/controllers/#{controller_name}_controller.rb"
    end

    def inject_blacklight_routes
      route <<-EOF
  concern :searchable, Blacklight::Routes::Searchable.new

  resource :catalog, only: [:index], as: 'catalog', path: '/catalog', controller: 'catalog' do
    concerns :searchable
  end
      EOF
    end
  end
end

Version data entries

74 entries across 74 versions & 2 rubygems

Version Path
blacklight-7.40.0 lib/generators/blacklight/controller_generator.rb
blacklight-7.39.0 lib/generators/blacklight/controller_generator.rb
blacklight-7.38.0 lib/generators/blacklight/controller_generator.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/blacklight-7.37.0/lib/generators/blacklight/controller_generator.rb
blacklight-7.37.0 lib/generators/blacklight/controller_generator.rb
blacklight-7.36.2 lib/generators/blacklight/controller_generator.rb
blacklight-7.36.1 lib/generators/blacklight/controller_generator.rb
blacklight-7.36.0 lib/generators/blacklight/controller_generator.rb
blacklight-7.35.0 lib/generators/blacklight/controller_generator.rb
blacklight-7.34.0 lib/generators/blacklight/controller_generator.rb
blacklight-7.33.1 lib/generators/blacklight/controller_generator.rb
blacklight-7.33.0 lib/generators/blacklight/controller_generator.rb
blacklight-7.32.0 lib/generators/blacklight/controller_generator.rb
blacklight-7.31.0 lib/generators/blacklight/controller_generator.rb
blacklight-7.30.0 lib/generators/blacklight/controller_generator.rb
blacklight-7.29.0 lib/generators/blacklight/controller_generator.rb
blacklight-7.28.0 lib/generators/blacklight/controller_generator.rb
blacklight-7.27.1 lib/generators/blacklight/controller_generator.rb
blacklight-7.27.0 lib/generators/blacklight/controller_generator.rb
blacklight-7.26.1 lib/generators/blacklight/controller_generator.rb