lib/generators/spotlight/install_generator.rb in blacklight-spotlight-3.0.0.alpha.10 vs lib/generators/spotlight/install_generator.rb in blacklight-spotlight-3.0.0.rc1
- old
+ new
@@ -8,10 +8,29 @@
class Install < Rails::Generators::Base
source_root File.expand_path('templates', __dir__)
class_option :solr_update_class, type: :string, default: 'Spotlight::SolrDocument::AtomicUpdates'
class_option :mailer_default_url_host, type: :string, default: '' # e.g. localhost:3000
+ # we're not (yet) using webpacker, so we need to re-add sprockets functionality
+ def add_js
+ return unless Rails.version.to_i == 6
+
+ gem 'coffee-rails', '~> 4.2'
+ gem 'uglifier', '>= 1.3.0'
+
+ append_to_file 'app/assets/config/manifest.js', '//= link_directory ../javascripts .js'
+ append_to_file 'app/assets/javascripts/application.js', '//= require_tree .'
+ gsub_file 'app/views/layouts/application.html.erb', /pack/, 'include'
+ inject_into_file 'config/environments/production.rb', after: ' # config.assets.css_compressor = :sass' do
+ "\n config.assets.js_compressor = :uglifier"
+ end
+
+ # but since webpacker exists in the gemfile, we still need to run the
+ # install before rails will start
+ run 'bundle exec rails webpacker:install'
+ end
+
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
@@ -51,10 +70,12 @@
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'
+ inject_into_file 'app/models/user.rb', after: 'include Blacklight::User' do
+ "\n include Spotlight::User\n"
+ end
end
def add_controller_mixin
inject_into_file 'app/controllers/application_controller.rb', after: 'include Blacklight::Controller' do
"\n include Spotlight::Controller\n"