diff --git a/lib/generators/blacklight/allmaps/blacklight_generator.rb b/lib/generators/blacklight/allmaps/blacklight_generator.rb new file mode 100644 index 0000000..c5ad56c --- /dev/null +++ b/lib/generators/blacklight/allmaps/blacklight_generator.rb @@ -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 diff --git a/lib/generators/blacklight/allmaps/config_generator.rb b/lib/generators/blacklight/allmaps/config_generator.rb index b56502a..acbd020 100644 --- a/lib/generators/blacklight/allmaps/config_generator.rb +++ b/lib/generators/blacklight/allmaps/config_generator.rb @@ -52,20 +52,6 @@ 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 @@ -73,48 +59,6 @@ def set_routes 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 diff --git a/lib/generators/blacklight/allmaps/geoblacklight_generator.rb b/lib/generators/blacklight/allmaps/geoblacklight_generator.rb new file mode 100644 index 0000000..fbb6169 --- /dev/null +++ b/lib/generators/blacklight/allmaps/geoblacklight_generator.rb @@ -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 diff --git a/lib/generators/blacklight/allmaps/install_generator.rb b/lib/generators/blacklight/allmaps/install_generator.rb index f8db41e..a0e069e 100644 --- a/lib/generators/blacklight/allmaps/install_generator.rb +++ b/lib/generators/blacklight/allmaps/install_generator.rb @@ -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