Skip to content

Commit 5befb55

Browse files
committed
Support Importmap
1 parent a51fcd5 commit 5befb55

File tree

4 files changed

+20
-6
lines changed

4 files changed

+20
-6
lines changed

.github/workflows/ruby.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ jobs:
3333
blacklight_version: "~> 8.0"
3434
bootstrap_version: ~> 4.0
3535
additional_name: Blacklight 8
36-
additional_engine_cart_rails_options: "-j rollup -a sprockets"
36+
additional_engine_cart_rails_options: "-j importmap -a sprockets"
3737
env:
3838
RAILS_VERSION: ${{ matrix.rails_version }}
3939
BLACKLIGHT_VERSION: ${{ matrix.blacklight_version }}

app/views/layouts/spotlight/base.html.erb

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,15 @@
1313
<% else %>
1414
<%= stylesheet_link_tag "application" %>
1515
<% end %>
16-
<%= javascript_include_tag "application" %>
16+
<% if defined? Importmap %>
17+
<script
18+
src="https://code.jquery.com/jquery-3.7.1.slim.min.js"
19+
integrity="sha256-kmHvs0B+OpCW5GVHUNjv9rOmY0IvSIRcf7zGUDTDQM8="
20+
crossorigin="anonymous"></script>
21+
<%= javascript_importmap_tags %>
22+
<% else %>
23+
<%= javascript_include_tag "application", "data-turbo-track": "reload", defer: true %>
24+
<% end %>
1725
<%= csrf_meta_tags %>
1826
<%= content_for(:head) %>
1927
<%= description %>

lib/generators/spotlight/install_generator.rb

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,17 @@ class Install < Rails::Generators::Base
1111
class_option :mailer_default_url_host, type: :string, default: '' # e.g. localhost:3000
1212

1313
def add_manifest
14-
append_to_file 'app/assets/javascripts/application.js', "\n//= require_tree .\n"
1514
append_to_file 'app/assets/config/manifest.js', "\n//= link spotlight/manifest.js"
1615

17-
# Rails installed importmap by default, but we don't have importmap + Blacklight 7 working yet.
18-
remove_file 'app/javascript/application.js'
16+
if Blacklight.version.to_i > 7 && defined? Importmap
17+
append_to_file 'app/javascripts/application.js', "\nimport Spotlight from \"spotlight\"\n"
18+
else
19+
append_to_file 'app/assets/javascripts/application.js', "\n//= require_tree .\n"
20+
21+
# Rails installed importmap by default, but Blacklight 7 doesn't support importmap.
22+
# We must remove the importmap entrypoint or Sprockets will have a double link error with two files named application.js
23+
remove_file 'app/javascript/application.js'
24+
end
1925
end
2026

2127
def inject_spotlight_routes

spec/test_app_templates/lib/generators/test_app_generator.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ def use_capybara3
1010
end
1111

1212
def add_gems
13-
gem 'blacklight', ENV['BLACKLIGHT_VERSION'] || '~> 7.17' unless Bundler.locked_gems.dependencies.key? 'blacklight'
13+
gem 'blacklight', ENV['BLACKLIGHT_VERSION'] || '~> 8.4' unless Bundler.locked_gems.dependencies.key? 'blacklight'
1414
gem 'blacklight-gallery', '~> 4.5' unless Bundler.locked_gems.dependencies.key? 'blacklight-gallery'
1515

1616
unless Bundler.locked_gems.dependencies.key? 'bootstrap_form'

0 commit comments

Comments
 (0)