Class: Spotlight::Install

Inherits:
Rails::Generators::Base
  • Object
show all
Defined in:
lib/generators/spotlight/install_generator.rb

Overview

spotlight:install generator

Instance Method Summary collapse

Instance Method Details

#add_controller_mixinObject



80
81
82
83
84
# File 'lib/generators/spotlight/install_generator.rb', line 80

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_controllerObject



123
124
125
# File 'lib/generators/spotlight/install_generator.rb', line 123

def add_example_catalog_controller
  copy_file 'catalog_controller.rb', 'app/controllers/catalog_controller.rb'
end

#add_helperObject



86
87
88
89
90
91
# File 'lib/generators/spotlight/install_generator.rb', line 86

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_jsObject

we’re not (yet) using webpacker, so we need to re-add sprockets functionality



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/generators/spotlight/install_generator.rb', line 14

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', "\n//= link_directory ../javascripts .js\n"
  append_to_file 'app/assets/javascripts/application.js', "\n//= require_tree .\n"
  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

#add_mailer_defaultsObject



139
140
141
142
143
144
145
146
147
148
149
150
# File 'lib/generators/spotlight/install_generator.rb', line 139

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: "[email protected]" }
      EOF
    end
  else
    say 'Please add a default configuration config.action_mailer.default_url_options for your environment', :red
  end
end

#add_model_mixinObject



93
94
95
96
97
98
99
100
101
# File 'lib/generators/spotlight/install_generator.rb', line 93

def add_model_mixin
  if File.exist? 'app/models/solr_document.rb'
    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_oembedObject



132
133
134
135
136
137
# File 'lib/generators/spotlight/install_generator.rb', line 132

def add_oembed
  gem 'blacklight-oembed', '~> 1.0'
  Bundler.with_clean_env { run 'bundle install' }
  generate 'blacklight_oembed:install'
  copy_file 'config/initializers/oembed.rb'
end

#add_osd_viewerObject



127
128
129
130
# File 'lib/generators/spotlight/install_generator.rb', line 127

def add_osd_viewer
  gem 'blacklight-gallery', '~> 3.0'
  generate 'blacklight_gallery:install'
end

#add_roles_to_userObject



74
75
76
77
78
# File 'lib/generators/spotlight/install_generator.rb', line 74

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_mixinObject



113
114
115
116
117
118
119
120
121
# File 'lib/generators/spotlight/install_generator.rb', line 113

def add_search_builder_mixin
  if File.exist? 'app/models/search_builder.rb'
    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_resourcesObject



156
157
158
159
# File 'lib/generators/spotlight/install_generator.rb', line 156

def add_solr_config_resources
  copy_file '.solr_wrapper.yml', '.solr_wrapper.yml'
  directory 'solr'
end

#add_solr_indexing_mixinObject



103
104
105
106
107
108
109
110
111
# File 'lib/generators/spotlight/install_generator.rb', line 103

def add_solr_indexing_mixin
  if File.exist? 'app/models/solr_document.rb'
    inject_into_file 'app/models/solr_document.rb', after: "include Spotlight::SolrDocument\n" do
      "\n  include #{options[:solr_update_class]}\n"
    end
  else
    say "Unable to find SolrDocument class; add `include #{options[:solr_update_class]}` to the class manually"
  end
end

#add_translationsObject



167
168
169
# File 'lib/generators/spotlight/install_generator.rb', line 167

def add_translations
  copy_file 'config/initializers/translation.rb'
end

#assetsObject



69
70
71
72
# File 'lib/generators/spotlight/install_generator.rb', line 69

def assets
  copy_file 'spotlight.scss', 'app/assets/stylesheets/spotlight.scss'
  copy_file 'spotlight.js', 'app/assets/javascripts/spotlight.js'
end

#friendly_idObject



40
41
42
43
44
45
# File 'lib/generators/spotlight/install_generator.rb', line 40

def friendly_id
  gem 'friendly_id'
  # we need to immediately run `bundle install` while pointing at github.
  Bundler.with_clean_env { run 'bundle install' }
  generate 'friendly_id'
end

#generate_configObject



152
153
154
# File 'lib/generators/spotlight/install_generator.rb', line 152

def generate_config
  directory 'config'
end

#generate_devise_invitableObject



161
162
163
164
165
# File 'lib/generators/spotlight/install_generator.rb', line 161

def generate_devise_invitable
  gem 'devise_invitable'
  generate 'devise_invitable:install'
  generate 'devise_invitable', 'User'
end

#inject_spotlight_routesObject



32
33
34
35
36
37
38
# File 'lib/generators/spotlight/install_generator.rb', line 32

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_trailObject



52
53
54
# File 'lib/generators/spotlight/install_generator.rb', line 52

def paper_trail
  generate 'paper_trail:install'
end

#riiifObject



47
48
49
50
# File 'lib/generators/spotlight/install_generator.rb', line 47

def riiif
  route "mount Riiif::Engine => '/images', as: 'riiif'"
  copy_file 'config/initializers/riiif.rb'
end

#sitemapsObject



56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/generators/spotlight/install_generator.rb', line 56

def sitemaps
  gem 'sitemap_generator'

  Bundler.with_clean_env { run 'bundle install' }

  copy_file 'config/sitemap.rb', 'config/sitemap.rb'

  say <<-EOS.strip_heredoc, :red
   Added a default sitemap_generator configuration in config/sitemap.rb; please
   update the default host to match your environment
  EOS
end