Sha256: 7a4ce03aa957fa8264de0b4754b42140ed8b0bfe960abcd75a48c893e27fdad9

Contents?: true

Size: 833 Bytes

Versions: 5

Compression:

Stored size: 833 Bytes

Contents

module SpotlightSearch
  module Generators
    class FilterGenerator < Rails::Generators::Base
      source_root File.expand_path('templates', __dir__)

      argument :model,                type: :string, required: true, desc: "Pass a model name"
      class_option :filters,          aliases: "-f", type: :array, desc: "Pass filters and scopes as an array. E.x: date_filter:datetime search:input"

      def copy_filter_contents_to_app
        if @options.filters?
          inject_into_file "app/models/#{model.singularize}.rb", after: "ApplicationRecord" do
            "\n  include SpotlightSearch\n"
          end
          template 'filters.html.erb', "app/views/admin/#{model}/_filters.html.slim"
          template 'controller.rb.erb', "app/controllers/admin/#{model}_controller.rb"
        end
      end

    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
spotlight_search-0.3.4 lib/generators/spotlight_search/filter_generator.rb
spotlight_search-0.3.3 lib/generators/spotlight_search/filter_generator.rb
spotlight_search-0.3.2 lib/generators/spotlight_search/filter_generator.rb
spotlight_search-0.3.1 lib/generators/spotlight_search/filter_generator.rb
spotlight_search-0.3.0 lib/generators/spotlight_search/filter_generator.rb