Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Importmap #3210

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading