Class: Spotlight::Install

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

Instance Method Summary collapse

Instance Method Details

#add_controller_mixinObject



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

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_helperObject



39
40
41
42
# File 'lib/generators/spotlight/install_generator.rb', line 39

def add_helper
  copy_file "spotlight_helper.rb", "app/helpers/spotlight_helper.rb"
  inject_into_class 'app/helpers/application_helper.rb', ApplicationHelper, "  include SpotlightHelper"
end

#add_mailer_defaultsObject



64
65
66
67
68
69
70
71
72
73
74
# File 'lib/generators/spotlight/install_generator.rb', line 64

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



44
45
46
47
48
# File 'lib/generators/spotlight/install_generator.rb', line 44

def add_model_mixin
  inject_into_file 'app/models/solr_document.rb', after: "include Blacklight::Solr::Document" do
   "\n  include Spotlight::SolrDocument\n"
  end
end

#add_oembedObject



60
61
62
# File 'lib/generators/spotlight/install_generator.rb', line 60

def add_oembed
  generate 'blacklight_oembed:install'
end

#add_osd_viewerObject



56
57
58
# File 'lib/generators/spotlight/install_generator.rb', line 56

def add_osd_viewer
  generate 'blacklight_gallery:install'
end

#add_roles_to_userObject



29
30
31
# File 'lib/generators/spotlight/install_generator.rb', line 29

def add_roles_to_user
  inject_into_class 'app/models/user.rb', User, "  include Spotlight::User"
end

#add_solr_indexing_mixinObject



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

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

#assetsObject



24
25
26
27
# File 'lib/generators/spotlight/install_generator.rb', line 24

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

#friendly_idObject



19
20
21
22
# File 'lib/generators/spotlight/install_generator.rb', line 19

def friendly_id
  gem "friendly_id"
  generate "friendly_id"
end

#generate_social_share_button_initializerObject



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

def generate_social_share_button_initializer
  gem 'social-share-button'
  directory 'config'
end

#inject_spotlight_routesObject



10
11
12
13
14
15
16
17
# File 'lib/generators/spotlight/install_generator.rb', line 10

def inject_spotlight_routes
  route "mount Spotlight::Engine, at: 'spotlight'"
  gsub_file 'config/routes.rb', /^\s*root.*/ do |match|
    "#" + match + " # replaced by spotlight_root"
  end

  route "spotlight_root"
end