Class: Spotlight::Install
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- Spotlight::Install
- Defined in:
- lib/generators/spotlight/install_generator.rb
Overview
spotlight:install generator
Instance Method Summary collapse
- #add_controller_mixin ⇒ Object
- #add_example_catalog_controller ⇒ Object
- #add_helper ⇒ Object
- #add_mailer_defaults ⇒ Object
- #add_manifest ⇒ Object
- #add_model_mixin ⇒ Object
- #add_oembed ⇒ Object
- #add_osd_viewer ⇒ Object
- #add_roles_to_user ⇒ Object
- #add_search_builder_mixin ⇒ Object
- #add_solr_config_resources ⇒ Object
- #add_solr_indexing_mixin ⇒ Object
- #assets ⇒ Object
- #configure_logging ⇒ Object
- #friendly_id ⇒ Object
- #generate_config ⇒ Object
- #generate_devise_invitable ⇒ Object
- #inject_spotlight_routes ⇒ Object
- #paper_trail ⇒ Object
- #riiif ⇒ Object
- #sitemaps ⇒ Object
Instance Method Details
#add_controller_mixin ⇒ Object
70 71 72 73 74 |
# File 'lib/generators/spotlight/install_generator.rb', line 70 def add_controller_mixin inject_into_file 'app/controllers/application_controller.rb', after: 'include Blacklight::Controller' do "\n include Spotlight::Controller\n" end end |
#add_example_catalog_controller ⇒ Object
113 114 115 |
# File 'lib/generators/spotlight/install_generator.rb', line 113 def add_example_catalog_controller copy_file 'catalog_controller.rb', 'app/controllers/catalog_controller.rb' end |
#add_helper ⇒ Object
76 77 78 79 80 81 |
# File 'lib/generators/spotlight/install_generator.rb', line 76 def add_helper copy_file 'spotlight_helper.rb', 'app/helpers/spotlight_helper.rb' inject_into_file 'app/helpers/application_helper.rb', after: 'module ApplicationHelper' do "\n include SpotlightHelper" end end |
#add_mailer_defaults ⇒ Object
134 135 136 137 138 139 140 141 142 143 144 145 |
# File 'lib/generators/spotlight/install_generator.rb', line 134 def add_mailer_defaults if [: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: "#{[:mailer_default_url_host]}", from: "[email protected]" } EOF end else say 'Please add a default configuration config.action_mailer.default_url_options for your environment', :red end end |
#add_manifest ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/generators/spotlight/install_generator.rb', line 13 def add_manifest append_to_file 'app/assets/javascripts/application.js', "\n//= require_tree .\n" append_to_file 'app/assets/config/manifest.js', "\n//= link spotlight/manifest.js" # Rails installed importmap by default, but we don't have importmap + Blacklight 7 working yet. remove_file 'app/javascript/application.js' end |
#add_model_mixin ⇒ Object
83 84 85 86 87 88 89 90 91 |
# File 'lib/generators/spotlight/install_generator.rb', line 83 def add_model_mixin if File.exist? File.('app/models/solr_document.rb', destination_root) inject_into_file 'app/models/solr_document.rb', after: 'include Blacklight::Solr::Document' do "\n include Spotlight::SolrDocument\n" end else say 'Unable to find SolrDocument class; add `include Spotlight::SolrDocument` to the class manually' end end |
#add_oembed ⇒ Object
125 126 127 128 129 130 131 132 |
# File 'lib/generators/spotlight/install_generator.rb', line 125 def unless Bundler.locked_gems.dependencies.key? 'blacklight-oembed' gem 'blacklight-oembed', '~> 1.0' bundle_install end generate 'blacklight_oembed:install' copy_file 'config/initializers/oembed.rb' end |
#add_osd_viewer ⇒ Object
117 118 119 120 121 122 123 |
# File 'lib/generators/spotlight/install_generator.rb', line 117 def add_osd_viewer unless Bundler.locked_gems.dependencies.key? 'blacklight-gallery' gem 'blacklight-gallery', '~> 4.0' bundle_install end generate 'blacklight_gallery:install' end |
#add_roles_to_user ⇒ Object
64 65 66 67 68 |
# File 'lib/generators/spotlight/install_generator.rb', line 64 def add_roles_to_user inject_into_file 'app/models/user.rb', after: 'include Blacklight::User' do "\n include Spotlight::User\n" end end |
#add_search_builder_mixin ⇒ Object
103 104 105 106 107 108 109 110 111 |
# File 'lib/generators/spotlight/install_generator.rb', line 103 def add_search_builder_mixin if File.exist? File.('app/models/search_builder.rb', destination_root) inject_into_file 'app/models/search_builder.rb', after: "include Blacklight::Solr::SearchBuilderBehavior\n" do "\n include Spotlight::SearchBuilder\n" end else say 'Unable to find SearchBuilder class; add `include Spotlight::SearchBuilder` to the class manually.' end end |
#add_solr_config_resources ⇒ Object
158 159 160 161 |
# File 'lib/generators/spotlight/install_generator.rb', line 158 def add_solr_config_resources copy_file '.solr_wrapper.yml', '.solr_wrapper.yml' directory 'solr' end |
#add_solr_indexing_mixin ⇒ Object
93 94 95 96 97 98 99 100 101 |
# File 'lib/generators/spotlight/install_generator.rb', line 93 def add_solr_indexing_mixin if File.exist? File.('app/models/solr_document.rb', destination_root) inject_into_file 'app/models/solr_document.rb', after: "include Spotlight::SolrDocument\n" do "\n include #{[:solr_update_class]}\n" end else say "Unable to find SolrDocument class; add `include #{[:solr_update_class]}` to the class manually" end end |
#assets ⇒ Object
59 60 61 62 |
# File 'lib/generators/spotlight/install_generator.rb', line 59 def assets copy_file 'spotlight.scss', 'app/assets/stylesheets/spotlight.scss' copy_file 'spotlight.js', 'app/assets/javascripts/spotlight.js' end |
#configure_logging ⇒ Object
163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 |
# File 'lib/generators/spotlight/install_generator.rb', line 163 def configure_logging insert_into_file 'config/application.rb', after: "< Rails::Application\n" do <<-EOF # Logging if ENV["RAILS_LOG_TO_STDOUT"].present? config.log_level = :debug config.log_formatter = ::Logger::Formatter.new # log to stdout logger = ActiveSupport::Logger.new(STDOUT) logger.formatter = config.log_formatter config.logger = ActiveSupport::TaggedLogging.new(logger) # Print deprecation notices to the Rails logger. config.active_support.deprecation = :log # Raise an error on page load if there are pending migrations. config.active_record.migration_error = :page_load # Highlight code that triggered database queries in logs. config.active_record.verbose_query_logs = true end EOF end end |
#friendly_id ⇒ Object
29 30 31 32 33 |
# File 'lib/generators/spotlight/install_generator.rb', line 29 def friendly_id gem 'friendly_id' bundle_install generate 'friendly_id' end |
#generate_config ⇒ Object
154 155 156 |
# File 'lib/generators/spotlight/install_generator.rb', line 154 def generate_config directory 'config' end |
#generate_devise_invitable ⇒ Object
147 148 149 150 151 152 |
# File 'lib/generators/spotlight/install_generator.rb', line 147 def generate_devise_invitable gem 'devise_invitable' bundle_install generate 'devise_invitable:install' generate 'devise_invitable', 'User' end |
#inject_spotlight_routes ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/generators/spotlight/install_generator.rb', line 21 def inject_spotlight_routes route "mount Spotlight::Engine, at: 'spotlight'" gsub_file 'config/routes.rb', /^\s*root.*/ do |match| '# ' + match.strip + ' # replaced by spotlight root path' end route "root to: 'spotlight/exhibits#index'" end |
#paper_trail ⇒ Object
42 43 44 |
# File 'lib/generators/spotlight/install_generator.rb', line 42 def paper_trail generate 'paper_trail:install' end |
#riiif ⇒ Object
35 36 37 38 39 40 |
# File 'lib/generators/spotlight/install_generator.rb', line 35 def riiif gem 'riiif' Bundler.with_unbundled_env { run 'bundle install' } route "mount Riiif::Engine => '/images', as: 'riiif'" copy_file 'config/initializers/riiif.rb' end |
#sitemaps ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/generators/spotlight/install_generator.rb', line 46 def sitemaps gem 'sitemap_generator' bundle_install copy_file 'config/sitemap.rb', 'config/sitemap.rb' say <<~EOS, :red Added a default sitemap_generator configuration in config/sitemap.rb; please update the default host to match your environment EOS end |