Skip to content

Commit

Permalink
Generators: cleanup and separate paths for BL and GBL
Browse files Browse the repository at this point in the history
Had to do it.
  • Loading branch information
ewlarson committed Apr 24, 2024
1 parent 48d2785 commit 57c0ddd
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 56 deletions.
46 changes: 46 additions & 0 deletions lib/generators/blacklight/allmaps/blacklight_generator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# frozen_string_literal: true

require "rails/generators"

module Blacklight
module Allmaps
class BlacklightGenerator < Rails::Generators::Base
source_root File.expand_path("templates", __dir__)

desc <<-DESCRIPTION
This generator makes the following changes to your application:
1. Copies stylesheets to Blacklight app
2. Adds Blacklight::Allmaps viewer to CatalogController
3. Adds georeferenced facet to CatalogController
4. Includes Blacklight::Allmaps::SolrDocument in SolrDocument
DESCRIPTION

def add_bl_stylesheets
append_to_file "app/assets/stylesheets/blacklight.scss" do
"@import 'blacklight/allmaps/base';"
end
end

def add_bl_allmaps_viewer
# Use the allmaps viewer
inject_into_file "app/controllers/catalog_controller.rb", after: "#config.show.thumbnail_field = 'thumbnail_path_ss'" do
"\n
# Blacklight::Allmaps Viewer
config.show.partials.insert(1, :blacklight_allmaps)"
end
end

def add_bl_georeferenced_facet
inject_into_file "app/controllers/catalog_controller.rb", after: "config.add_facet_field 'subject_era_ssim', label: 'Era'" do
"\n config.add_facet_field 'bl_georeferenced_bsi', label: I18n.t('allmaps.bl_facet_label')"
end
end

def include_blacklight_allmaps_solrdocument
inject_into_file "app/models/solr_document.rb", after: "include Blacklight::Solr::Document" do
"\n include Blacklight::Allmaps::SolrDocument"
end
end
end
end
end
56 changes: 0 additions & 56 deletions lib/generators/blacklight/allmaps/config_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,69 +52,13 @@ def add_javascript
end
end

def add_bl_stylesheets
return unless ENV["LIGHT"] == "blacklight"
append_to_file "app/assets/stylesheets/blacklight.scss" do
"@import 'blacklight/allmaps/base';"
end
end

def add_gbl_stylesheets
return unless ENV["LIGHT"] == "geoblacklight"
append_to_file "app/assets/stylesheets/application.scss" do
"@import 'blacklight/allmaps/base';"
end
end

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

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

def add_geoblacklight
return unless ENV["LIGHT"] == "geoblacklight"
append_to_file "Gemfile", '"geoblacklight", "~> 4.4"'
end

def include_blacklight_allmaps_solrdocument
return unless ENV["LIGHT"] == "blacklight"
inject_into_file "app/models/solr_document.rb", after: "include Blacklight::Solr::Document" do
"\n include Blacklight::Allmaps::SolrDocument"
end
end

def add_gbl_tabbed_viewer
return unless ENV["LIGHT"] == "geoblacklight"
# Use the tabbed viewer
inject_into_file "app/controllers/catalog_controller.rb", after: "config.show.partials << \"show_default_viewer_container\"" do
"\n
# Blacklight::Allmaps Tabbed Viewer
config.show.partials << \"show_allmaps_tabbed_viewer_container\""
end

# Remove the default viewer
gsub_file("app/controllers/catalog_controller.rb", "config.show.partials << \"show_default_viewer_container\"", "#config.show.partials << \"show_default_viewer_container\"")
end

def add_bl_allmaps_viewer
return unless ENV["LIGHT"] == "blacklight"
# Use the allmaps viewer
inject_into_file "app/controllers/catalog_controller.rb", after: "#config.show.thumbnail_field = 'thumbnail_path_ss'" do
"\n
# Blacklight::Allmaps Viewer
config.show.partials.insert(1, :blacklight_allmaps)"
end
end

def add_bl_georeferenced_facet
return unless ENV["LIGHT"] == "blacklight"
inject_into_file "app/controllers/catalog_controller.rb", after: "config.add_facet_field 'subject_era_ssim', label: 'Era'" do
"\n config.add_facet_field 'bl_georeferenced_bsi', label: I18n.t('allmaps.bl_facet_label')"
end
end
end
end
end
40 changes: 40 additions & 0 deletions lib/generators/blacklight/allmaps/geoblacklight_generator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# frozen_string_literal: true

require "rails/generators"

module Blacklight
module Allmaps
class GeoblacklightGenerator < Rails::Generators::Base
source_root File.expand_path("templates", __dir__)

desc <<-DESCRIPTION
This generator makes the following changes to your application:
1. Adds stylesheets to application.scss
2. Adds GeoBlacklight to Gemfile
3. Adds Blacklight::Allmaps Tabbed Viewer to CatalogController
DESCRIPTION

def add_gbl_stylesheets
append_to_file "app/assets/stylesheets/application.scss" do
"@import 'blacklight/allmaps/base';"
end
end

def add_geoblacklight
append_to_file "Gemfile", '"geoblacklight", "~> 4.4"'
end

def add_gbl_tabbed_viewer
# Use the tabbed viewer
inject_into_file "app/controllers/catalog_controller.rb", after: "config.show.partials << \"show_default_viewer_container\"" do
"\n
# Blacklight::Allmaps Tabbed Viewer
config.show.partials << \"show_allmaps_tabbed_viewer_container\""
end

# Remove the default viewer
gsub_file("app/controllers/catalog_controller.rb", "config.show.partials << \"show_default_viewer_container\"", "#config.show.partials << \"show_default_viewer_container\"")
end
end
end
end
10 changes: 10 additions & 0 deletions lib/generators/blacklight/allmaps/install_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,16 @@ def generate_config
generate "blacklight:allmaps:config"
end

def generate_blacklight_config
return unless ENV["LIGHT"] == "blacklight"
generate "blacklight:allmaps:blacklight"
end

def generate_geoblacklight_config
return unless ENV["LIGHT"] == "geoblacklight"
generate "blacklight:allmaps:geoblacklight"
end

def generate_models
generate "blacklight:allmaps:models"
end
Expand Down

0 comments on commit 57c0ddd

Please sign in to comment.