Class: BlacklightMaps::Install

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

Instance Method Summary collapse

Instance Method Details

#assetsObject



18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/generators/blacklight_maps/install_generator.rb', line 18

def assets
  copy_file 'blacklight_maps.css.scss', 'app/assets/stylesheets/blacklight_maps.css.scss'
  return if IO.read('app/assets/javascripts/application.js').include?('blacklight-maps')

  marker = '//= require blacklight/blacklight'
  insert_into_file 'app/assets/javascripts/application.js', after: marker do
    "\n// Required by BlacklightMaps" \
    "\n//= require blacklight-maps"
  end
  append_to_file 'config/initializers/assets.rb',
                 "\nRails.application.config.assets.paths << Rails.root.join('vendor', 'assets', 'images')\n"
end

#inject_search_builderObject



31
32
33
34
35
36
# File 'lib/generators/blacklight_maps/install_generator.rb', line 31

def inject_search_builder
  inject_into_file 'app/models/search_builder.rb',
                   after: /include Blacklight::Solr::SearchBuilderBehavior.*$/ do
    "\n  include BlacklightMaps::MapsSearchBuilderBehavior\n"
  end
end

#inject_solr_configurationObject

TODO: inject Solr configuration (if needed)



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

def inject_solr_configuration
  target_file = 'solr/conf/schema.xml'
  return unless File.exist?(target_file)

  inject_into_file target_file,
                   after: %r{<copyField source="title_tsim" dest="title_spell"/>} do
    "\n  <copyField source=\"coordinates_srpt\" dest=\"coordinates_ssim\" />\n"
  end
end

#install_catalog_controller_mixinObject



38
39
40
41
42
43
# File 'lib/generators/blacklight_maps/install_generator.rb', line 38

def install_catalog_controller_mixin
  inject_into_file 'app/controllers/catalog_controller.rb',
                   after: /include Blacklight::Catalog.*$/ do
    "\n  include BlacklightMaps::Controller\n"
  end
end

#install_search_history_controllerObject



45
46
47
48
49
50
51
52
53
54
55
# File 'lib/generators/blacklight_maps/install_generator.rb', line 45

def install_search_history_controller
  target_file = 'app/controllers/search_history_controller.rb'
  if File.exist?(target_file)
    inject_into_file target_file,
                     after: /include Blacklight::SearchHistory/ do
      "\n  helper BlacklightMaps::RenderConstraintsOverride\n"
    end
  else
    copy_file 'search_history_controller.rb', target_file
  end
end

#verify_blacklight_installedObject



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

def verify_blacklight_installed
  return if IO.read('app/controllers/application_controller.rb').include?('include Blacklight::Controller')

  say_status('info', 'BLACKLIGHT NOT INSTALLED; GENERATING BLACKLIGHT', :blue)
  generate 'blacklight:install'
end