lib/generators/spotlight/install_generator.rb in blacklight-spotlight-0.1.0 vs lib/generators/spotlight/install_generator.rb in blacklight-spotlight-0.2.0
- old
+ new
@@ -2,10 +2,12 @@
module Spotlight
class Install < Rails::Generators::Base
source_root File.expand_path('../templates', __FILE__)
+ class_option :solr_update_class, type: :string , default: "Spotlight::SolrDocument::AtomicUpdates"
+ class_option :mailer_default_url_host, type: :string, default: '' # e.g. localhost:3000
def inject_spotlight_routes
route "mount Spotlight::Engine, at: 'spotlight'"
gsub_file 'config/routes.rb', /^\s*root.*/ do |match|
"#" + match + " # replaced by spotlight_root"
@@ -18,11 +20,11 @@
gem "friendly_id"
generate "friendly_id"
end
def assets
- copy_file "spotlight.css.scss", "app/assets/stylesheets/spotlight.css.scss"
+ copy_file "spotlight.scss", "app/assets/stylesheets/spotlight.scss"
copy_file "spotlight.js", "app/assets/javascripts/spotlight.js"
end
def add_roles_to_user
inject_into_class 'app/models/user.rb', User, " include Spotlight::User"
@@ -39,13 +41,37 @@
inject_into_class 'app/helpers/application_helper.rb', ApplicationHelper, " include SpotlightHelper"
end
def add_model_mixin
inject_into_file 'app/models/solr_document.rb', after: "include Blacklight::Solr::Document" do
- "\n include Spotlight::SolrDocument\n" +
- "include Spotlight::SolrDocument::AtomicUpdates\n" +
- "include Spotlight::SolrDocument::Openseadragon\n"
- end
+ "\n include Spotlight::SolrDocument\n"
+ end
+ end
+
+ def add_solr_indexing_mixin
+ inject_into_file 'app/models/solr_document.rb', after: "include Spotlight::SolrDocument\n" do
+ "\n include #{options[:solr_update_class]}\n"
+ end
+ end
+
+ def add_osd_viewer
+ generate 'blacklight_gallery:install'
+ end
+
+ def add_oembed
+ generate 'blacklight_oembed:install'
+ end
+
+ def add_mailer_defaults
+ if options[:mailer_default_url_host].present?
+ say "Injecting a placeholder config.action_mailer.default_url_options; be sure to update it for your environment", :yellow
+ insert_into_file 'config/application.rb', after: "< Rails::Application\n" do <<-EOF
+ config.action_mailer.default_url_options = { host: "#{options[:mailer_default_url_host]}", from: "noreply@example.com" }
+ EOF
+ end
+ else
+ say "Please add a default configuration config.action_mailer.default_url_options for your environment", :red
+ end
end
def generate_social_share_button_initializer
gem 'social-share-button'
directory 'config'