Skip to content

Commit

Permalink
Support Importmap
Browse files Browse the repository at this point in the history
  • Loading branch information
jcoyne committed Oct 18, 2024
1 parent a51fcd5 commit 79ef657
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ruby.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
10 changes: 9 additions & 1 deletion app/views/layouts/spotlight/base.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,15 @@
<% else %>
<%= stylesheet_link_tag "application" %>
<% end %>
<%= javascript_include_tag "application" %>
<% if defined? Importmap %>
<script
src="https://code.jquery.com/jquery-3.7.1.slim.min.js"
integrity="sha256-kmHvs0B+OpCW5GVHUNjv9rOmY0IvSIRcf7zGUDTDQM8="
crossorigin="anonymous"></script>
<%= javascript_importmap_tags %>
<% else %>
<%= javascript_include_tag "application", "data-turbo-track": "reload", defer: true %>
<% end %>
<%= csrf_meta_tags %>
<%= content_for(:head) %>
<%= description %>
Expand Down
12 changes: 9 additions & 3 deletions lib/generators/spotlight/install_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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/javascript/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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down

0 comments on commit 79ef657

Please sign in to comment.