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



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

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



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

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



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

def allow_geoblacklight_params
  gbl_params = <<-PARAMS
    before_action :allow_geoblacklight_params

    def allow_geoblacklight_params
      # Blacklight::Parameters will pass these to params.permit
      blacklight_config.search_state_fields.append(Settings.GBL_PARAMS)
    end
  PARAMS

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

#bundle_installObject

Run bundle with vite install



138
139
140
141
142
143
# File 'lib/generators/geoblacklight/install_generator.rb', line 138

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

#copy_config_vite_jsonObject

Vite - Config files



131
132
133
134
135
# File 'lib/generators/geoblacklight/install_generator.rb', line 131

def copy_config_vite_json
  copy_file "vite.json", "config/vite.json"
  copy_file "vite.config.ts", "vite.config.ts"
  run "yarn install"
end

#copy_package_jsonObject



120
121
122
123
124
125
126
127
128
# File 'lib/generators/geoblacklight/install_generator.rb', line 120

def copy_package_json
  if options[:test]
    # If building engine cart test app, use specific package.json so the
    # locally built frontend javascript is used instead of the npm package.
    copy_file "package-test.json", "package.json"
  else
    copy_file "package.json", "package.json"
  end
end

#copy_vite_entrypointsObject

Vite - Copy over the Vite entrypoints



146
147
148
149
# File 'lib/generators/geoblacklight/install_generator.rb', line 146

def copy_vite_entrypoints
  copy_file "clover.js", "app/javascript/entrypoints/clover.js"
  copy_file "ol.js", "app/javascript/entrypoints/ol.js"
end

#create_blacklight_catalogObject



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

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



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

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



104
105
106
# File 'lib/generators/geoblacklight/install_generator.rb', line 104

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

#generate_assetsObject



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

def generate_assets
  generate "geoblacklight:assets"
end

#geoblacklight_base_layoutObject

Vite - GBL Base Layout with Vite Helper Tags



116
117
118
# File 'lib/generators/geoblacklight/install_generator.rb', line 116

def geoblacklight_base_layout
  copy_file "base.html.erb", "app/views/layouts/blacklight/base.html.erb"
end

#include_geoblacklight_solrdocumentObject



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

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



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

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



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

def inject_geoblacklight_routes
  routes = <<-ROUTES
    concern :gbl_exportable, Geoblacklight::Routes::Exportable.new
    resources :solr_documents, only: [:show], path: '/catalog', controller: 'catalog' do
      concerns :gbl_exportable
    end
    concern :gbl_wms, Geoblacklight::Routes::Wms.new
    namespace :wms do
      concerns :gbl_wms
    end
    concern :gbl_downloadable, Geoblacklight::Routes::Downloadable.new
    namespace :download do
      concerns :gbl_downloadable
    end
    resources :download, only: [:show]
  ROUTES

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

#install_vite_railsObject

Vite - Required for successful installation



109
110
111
112
113
# File 'lib/generators/geoblacklight/install_generator.rb', line 109

def install_vite_rails
  append_to_file "Gemfile" do
    "gem \"vite_rails\", \"~> 3.0\""
  end
end

#mount_geoblacklight_engineObject



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

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

#rails_configObject



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

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

#raise_unpermitted_paramsObject



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

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



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

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

#update_application_nameObject



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

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