Class: Geoblacklight::Install

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

Instance Method Summary collapse

Instance Method Details

#add_spatial_search_behaviorObject



81
82
83
84
85
# File 'lib/generators/geoblacklight/install_generator.rb', line 81

def add_spatial_search_behavior
  inject_into_file "app/models/search_builder.rb", after: "include Blacklight::Solr::SearchBuilderBehavior" do
    "\n  include Geoblacklight::SuppressedRecordsSearchBehavior"
  end
end

#add_unique_keyObject



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

def add_unique_key
  inject_into_file "app/models/solr_document.rb", after: "# self.unique_key = 'id'" do
    "\n  self.unique_key = Settings.FIELDS.UNIQUE_KEY"
  end
end

#allow_geoblacklight_paramsObject



11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/generators/geoblacklight/install_generator.rb', line 11

def allow_geoblacklight_params
  gbl_params = "before_action :allow_geoblacklight_params\n\ndef allow_geoblacklight_params\n# Blacklight::Parameters will pass these to params.permit\nblacklight_config.search_state_fields.append(Settings.GBL_PARAMS)\nend\n"

  inject_into_file "app/controllers/application_controller.rb", gbl_params, before: /^end/
end

#bundle_installObject



111
112
113
114
115
# File 'lib/generators/geoblacklight/install_generator.rb', line 111

def bundle_install
  Bundler.with_clean_env do
    run "bundle install"
  end
end

#create_blacklight_catalogObject



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

def create_blacklight_catalog
  remove_file "app/controllers/catalog_controller.rb"
  copy_file "catalog_controller.rb", "app/controllers/catalog_controller.rb"
end

#create_downloads_directoryObject



94
95
96
# File 'lib/generators/geoblacklight/install_generator.rb', line 94

def create_downloads_directory
  FileUtils.mkdir_p("tmp/cache/downloads") unless File.directory?("tmp/cache/downloads")
end

#create_image_assets_directoryObject

Ensure that assets/images exists



107
108
109
# File 'lib/generators/geoblacklight/install_generator.rb', line 107

def create_image_assets_directory
  FileUtils.mkdir_p("app/assets/images") unless File.directory?("app/assets/images")
end


98
99
100
# File 'lib/generators/geoblacklight/install_generator.rb', line 98

def disable_turbolinks
  gsub_file("app/assets/javascripts/application.js", %r{//= require turbolinks}, "")
end

#generate_assetsObject



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

def generate_assets
  generate "geoblacklight:assets"
end

#include_geoblacklight_solrdocumentObject



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

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

#inject_disable_jquery_animationsObject

Turn off JQuery animations during testing



88
89
90
91
92
# File 'lib/generators/geoblacklight/install_generator.rb', line 88

def inject_disable_jquery_animations
  inject_into_file "app/views/layouts/application.html.erb", before: "</head>" do
    "  <%= javascript_tag '$.fx.off = true;' if Rails.env.test? %>\n"
  end
end

#inject_geoblacklight_routesObject



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/generators/geoblacklight/install_generator.rb', line 32

def inject_geoblacklight_routes
  routes = "concern :gbl_exportable, Geoblacklight::Routes::Exportable.new\nresources :solr_documents, only: [:show], path: '/catalog', controller: 'catalog' do\nconcerns :gbl_exportable\nend\nconcern :gbl_wms, Geoblacklight::Routes::Wms.new\nnamespace :wms do\nconcerns :gbl_wms\nend\nconcern :gbl_downloadable, Geoblacklight::Routes::Downloadable.new\nnamespace :download do\nconcerns :gbl_downloadable\nend\nresources :download, only: [:show]\n"

  inject_into_file "config/routes.rb", routes, before: /^end/
end

#mount_geoblacklight_engineObject



28
29
30
# File 'lib/generators/geoblacklight/install_generator.rb', line 28

def mount_geoblacklight_engine
  inject_into_file "config/routes.rb", "mount Geoblacklight::Engine => 'geoblacklight'\n", before: /^end/
end

#rails_configObject



61
62
63
# File 'lib/generators/geoblacklight/install_generator.rb', line 61

def rails_config
  copy_file "settings.yml", "config/settings.yml"
end

#raise_unpermitted_paramsObject



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

def raise_unpermitted_params
  inject_into_file "config/environments/test.rb", "config.action_controller.action_on_unpermitted_parameters = :raise\n", before: /^end/
end

#solr_configObject



65
66
67
# File 'lib/generators/geoblacklight/install_generator.rb', line 65

def solr_config
  directory "../../../../solr", "solr"
end

#update_application_nameObject



102
103
104
# File 'lib/generators/geoblacklight/install_generator.rb', line 102

def update_application_name
  gsub_file("config/locales/blacklight.en.yml", "Blacklight", "GeoBlacklight")
end