diff --git a/.github/workflows/ruby.yml b/.github/workflows/ruby.yml index 41fcc3306..1c49422bc 100644 --- a/.github/workflows/ruby.yml +++ b/.github/workflows/ruby.yml @@ -33,7 +33,7 @@ jobs: blacklight_version: "~> 8.0" bootstrap_version: ~> 4.0 additional_name: Blacklight 8 - additional_engine_cart_rails_options: "-j rollup -a sprockets" + additional_engine_cart_rails_options: "-j importmap -a sprockets" env: RAILS_VERSION: ${{ matrix.rails_version }} BLACKLIGHT_VERSION: ${{ matrix.blacklight_version }} diff --git a/app/views/layouts/spotlight/base.html.erb b/app/views/layouts/spotlight/base.html.erb index d386874b1..24699e5bc 100644 --- a/app/views/layouts/spotlight/base.html.erb +++ b/app/views/layouts/spotlight/base.html.erb @@ -13,7 +13,15 @@ <% else %> <%= stylesheet_link_tag "application" %> <% end %> - <%= javascript_include_tag "application" %> + <% if defined? Importmap %> + + <%= javascript_importmap_tags %> + <% else %> + <%= javascript_include_tag "application", "data-turbo-track": "reload", defer: true %> + <% end %> <%= csrf_meta_tags %> <%= content_for(:head) %> <%= description %> diff --git a/lib/generators/spotlight/install_generator.rb b/lib/generators/spotlight/install_generator.rb index 818ece397..d1c151d7c 100644 --- a/lib/generators/spotlight/install_generator.rb +++ b/lib/generators/spotlight/install_generator.rb @@ -11,11 +11,17 @@ class Install < Rails::Generators::Base class_option :mailer_default_url_host, type: :string, default: '' # e.g. localhost:3000 def add_manifest - append_to_file 'app/assets/javascripts/application.js', "\n//= require_tree .\n" append_to_file 'app/assets/config/manifest.js', "\n//= link spotlight/manifest.js" - # Rails installed importmap by default, but we don't have importmap + Blacklight 7 working yet. - remove_file 'app/javascript/application.js' + if Blacklight.version.to_i > 7 && defined? Importmap + append_to_file 'app/javascripts/application.js', "\nimport Spotlight from \"spotlight\"\n" + else + append_to_file 'app/assets/javascripts/application.js', "\n//= require_tree .\n" + + # Rails installed importmap by default, but Blacklight 7 doesn't support importmap. + # We must remove the importmap entrypoint or Sprockets will have a double link error with two files named application.js + remove_file 'app/javascript/application.js' + end end def inject_spotlight_routes diff --git a/spec/test_app_templates/lib/generators/test_app_generator.rb b/spec/test_app_templates/lib/generators/test_app_generator.rb index 10589f5ba..6059ba676 100644 --- a/spec/test_app_templates/lib/generators/test_app_generator.rb +++ b/spec/test_app_templates/lib/generators/test_app_generator.rb @@ -10,7 +10,7 @@ def use_capybara3 end def add_gems - gem 'blacklight', ENV['BLACKLIGHT_VERSION'] || '~> 7.17' unless Bundler.locked_gems.dependencies.key? 'blacklight' + gem 'blacklight', ENV['BLACKLIGHT_VERSION'] || '~> 8.4' unless Bundler.locked_gems.dependencies.key? 'blacklight' gem 'blacklight-gallery', '~> 4.5' unless Bundler.locked_gems.dependencies.key? 'blacklight-gallery' unless Bundler.locked_gems.dependencies.key? 'bootstrap_form'