Sha256: 7fe30e22706f02802fd2a724e677118a9c4335fa388fe4bb8265a34bf7039cb3

Contents?: true

Size: 1.88 KB

Versions: 6

Compression:

Stored size: 1.88 KB

Contents

require 'rails/generators'

module BlacklightRangeLimit
  class InstallGenerator < Rails::Generators::Base
    source_root File.expand_path('../templates', __FILE__)

    def copy_public_assets
      generate 'blacklight_range_limit:assets'
    end

    def install_catalog_controller_mixin
      inject_into_file 'app/controllers/catalog_controller.rb', after: /include Blacklight::Catalog.*$/ do
        "\n  include BlacklightRangeLimit::ControllerOverride\n"
      end
    end

    def install_search_builder
      path = 'app/models/search_builder.rb'
      if File.exist? path
        inject_into_file path, after: /include Blacklight::Solr::SearchBuilderBehavior.*$/ do
          "\n  include BlacklightRangeLimit::RangeLimitBuilder\n"
        end
      else
        say_status("error", "Unable to find #{path}. You must manually add the 'include BlacklightRangeLimit::RangeLimitBuilder' to your SearchBuilder", :red)
      end
    end

    # Adds range limit behavior to search history controller
    def install_search_history_controller
      path = 'app/controllers/search_history_controller.rb'

      # If local copy of search history controller exists, add range limit helpers
      if File.exist? path
        inject_into_file path, after: /include Blacklight::SearchHistory.*$/ do
          "\n  helper BlacklightRangeLimit::ViewHelperOverride"\
          "\n  helper RangeLimitHelper"
        end
      # Otherwise copies search history controller to application
      else
        copy_file 'search_history_controller.rb', path
      end
    end

    def install_routing_concern
      route('concern :range_searchable, BlacklightRangeLimit::Routes::RangeSearchable.new')
    end

    def add_range_limit_concern_to_catalog
      sentinel = /concerns :searchable.*$/

      inject_into_file 'config/routes.rb', after: sentinel do
        "\n    concerns :range_searchable\n"
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
blacklight_range_limit-8.1.0 lib/generators/blacklight_range_limit/install_generator.rb
blacklight_range_limit-8.0.1 lib/generators/blacklight_range_limit/install_generator.rb
blacklight_range_limit-8.0.0 lib/generators/blacklight_range_limit/install_generator.rb
blacklight_range_limit-7.9.1 lib/generators/blacklight_range_limit/install_generator.rb
blacklight_range_limit-7.9.0 lib/generators/blacklight_range_limit/install_generator.rb
blacklight_range_limit-7.8.2 lib/generators/blacklight_range_limit/install_generator.rb