Skip to content

Commit

Permalink
Setup importmap
Browse files Browse the repository at this point in the history
  • Loading branch information
jcoyne committed Jul 19, 2024
1 parent 790177c commit 4c1eae2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
6 changes: 5 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,11 @@
<% else %>
<%= stylesheet_link_tag "application" %>
<% end %>
<%= javascript_include_tag "application" %>
<% if defined? Importmap %>
<%= javascript_importmap_tags %>
<% else %>
<%= javascript_include_tag "application" %>
<% end %>
<%= csrf_meta_tags %>
<%= content_for(:head) %>
<%= description %>
Expand Down
20 changes: 14 additions & 6 deletions lib/generators/spotlight/install_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,21 @@ def add_js_rails6
end

def add_manifest
# Blacklight 8 does not use this directory by default.
return unless File.exist?('app/assets/javascripts')

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'

# Blacklight 8 does not use this directory by default.
if File.exist?('app/assets/javascripts')
append_to_file 'app/assets/javascripts/application.js', "\n//= require_tree .\n"
# Rails installed importmap by default, but we don't have importmap + Blacklight 7 working yet.
remove_file 'app/javascript/application.js'
else
# install via importmap
append_to_file 'app/javascript/application.js' do
<<~CONTENT
import Spotlight from "spotlight.esm"
CONTENT
end
end
end

def inject_spotlight_routes
Expand Down

0 comments on commit 4c1eae2

Please sign in to comment.