Class: Blacklight::Allmaps::ConfigGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Defined in:
lib/generators/blacklight/allmaps/config_generator.rb

Instance Method Summary collapse

Instance Method Details

#add_assets_initialierObject



19
20
21
22
23
24
25
26
27
# File 'lib/generators/blacklight/allmaps/config_generator.rb', line 19

def add_assets_initialier
  append_to_file "config/initializers/assets.rb" do
    "
    # Blacklight Allmaps
    Rails.application.config.assets.paths << Rails.root.join('node_modules')
    Rails.application.config.assets.paths << Rails.root.join('vendor', 'assets', 'images')
    Rails.application.config.assets.precompile += %w( blacklight/allmaps/allmaps-logo.svg )"
  end
end

#add_importmap_pinsObject



38
39
40
41
42
43
44
45
46
47
# File 'lib/generators/blacklight/allmaps/config_generator.rb', line 38

def add_importmap_pins
  append_to_file "config/importmap.rb" do
    <<~CONTENT
      pin "leaflet", to: "https://cdn.jsdelivr.net/npm/[email protected]/dist/leaflet.js", preload: true
      pin "leaflet-fullscreen", to: "https://cdn.jsdelivr.net/npm/[email protected]/dist/Leaflet.fullscreen.min.js", preload: true
      pin "@allmaps/leaflet", to: "https://cdn.jsdelivr.net/npm/@allmaps/leaflet/dist/bundled/allmaps-leaflet-1.9.umd.js", preload: true
      pin_all_from File.expand_path("../app/javascript/blacklight/allmaps", __dir__), under: "blacklight-allmaps"
    CONTENT
  end
end

#add_javascriptObject



49
50
51
52
53
54
55
# File 'lib/generators/blacklight/allmaps/config_generator.rb', line 49

def add_javascript
  inject_into_file "app/assets/javascripts/application.js", after: "//= require blacklight/blacklight" do
    "\n
    // Required by Blacklight::Allmaps
    //= require blacklight-allmaps/app/assets/javascripts/blacklight/allmaps/blacklight-allmaps.js"
  end
end

#add_yarn_packageObject



57
58
59
# File 'lib/generators/blacklight/allmaps/config_generator.rb', line 57

def add_yarn_package
  run "yarn add blacklight-allmaps"
end

#asset_config_manifestObject



15
16
17
# File 'lib/generators/blacklight/allmaps/config_generator.rb', line 15

def asset_config_manifest
  copy_file "manifest.js", "app/assets/config/manifest.js", force: true
end

#copy_rake_tasksObject



29
30
31
# File 'lib/generators/blacklight/allmaps/config_generator.rb', line 29

def copy_rake_tasks
  append_to_file "Rakefile", "require 'blacklight/allmaps/rake_task'\n"
end

#prioritize_blacklight_allmaps_viewsObject



33
34
35
36
# File 'lib/generators/blacklight/allmaps/config_generator.rb', line 33

def prioritize_blacklight_allmaps_views
  inject_into_file "config/application.rb", "\nrequire \"blacklight/allmaps/engine\"\n", before: "# Require the gems listed in Gemfile"
  inject_into_file "config/application.rb", "\n    config.railties_order = [Blacklight::Allmaps::Engine, :main_app, :all]\n", after: "class Application < Rails::Application\n"
end

#set_active_job_configObject



65
66
67
# File 'lib/generators/blacklight/allmaps/config_generator.rb', line 65

def set_active_job_config
  inject_into_file "config/environments/development.rb", "  config.active_job.queue_adapter = :inline\n", after: "Rails.application.configure do\n"
end

#set_routesObject



61
62
63
# File 'lib/generators/blacklight/allmaps/config_generator.rb', line 61

def set_routes
  inject_into_file "config/routes.rb", "mount Blacklight::Allmaps::Engine => '/'\n", before: /^end/
end