Skip to content

Commit

Permalink
Fix importmap
Browse files Browse the repository at this point in the history
  • Loading branch information
jcoyne committed Feb 27, 2024
1 parent 2c4cf8d commit 64b74a3
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 9 deletions.
2 changes: 2 additions & 0 deletions app/assets/config/blacklight_range_limit/manifest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
//= link_directory ../../stylesheets .css
//= link_tree ../../javascripts .js
6 changes: 3 additions & 3 deletions app/assets/javascripts/blacklight_range_limit.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
//= require 'bootstrap-slider'

//= require 'blacklight_range_limit/blacklight_range_limit.umd'
import Blacklight from 'blacklight'
import modal from 'blacklight/modal'

Blacklight.onLoad(function() {
// Support for Blacklight 7 and 8:
modalSelector = Blacklight.modal?.modalSelector || Blacklight.Modal.modalSelector
BlacklightRangeLimit.initialize(modalSelector)
BlacklightRangeLimit.initialize(modal.modalSelector)
})
2 changes: 1 addition & 1 deletion config/importmap.rb
Original file line number Diff line number Diff line change
@@ -1 +1 @@
pin_all_from File.expand_path('../app/assets/javascript', __dir__)
pin_all_from File.expand_path('../app/assets/javascripts', __dir__)
1 change: 1 addition & 0 deletions lib/blacklight_range_limit/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class Engine < Rails::Engine
end

initializer 'blacklight_range_limit.assets', before: 'assets' do |app|
app.config.assets.paths << Engine.root.join("app/assets/javascript")
app.config.assets.precompile << 'blacklight_range_limit/blacklight_range_limit.esm.js'
end

Expand Down
15 changes: 11 additions & 4 deletions lib/generators/blacklight_range_limit/assets_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,22 @@ def using_importmap?
end

def pin_javascript_dependencies
say 'blacklight-range-limit importmap asset generation'

append_to_file 'config/importmap.rb', <<~RUBY
pin "blacklight-range-limit", to: "blacklight-range-limit/blacklight-range-limit.esm.js"
pin "jquery", to: "https://cdn.jsdelivr.net/npm/jquery@3.7.1/dist/jquery.js"
RUBY
end

def import_javascript
append_to_file 'app/javascript/application.js', "\nimport \"blacklight-range-limit\""
append_to_file 'app/javascript/application.js', <<~JS
import "jquery"
import "blacklight_range_limit"
JS

append_to_file 'app/assets/config/manifest.js' do
<<~CONTENT
//= link blacklight_range_limit/manifest.js
CONTENT
end
end

# NOTE: This is expected to fail in Rails 7.1+
Expand Down
2 changes: 1 addition & 1 deletion rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const ESM = process.env.ESM === 'true'

const fileDest = `blacklight_range_limit${ESM ? '.esm' : '.umd'}`
const external = []
const globals = {}
const globals = { "blacklight_frontend": "Blacklight" }

let includePathOptions = {
include: {},
Expand Down

0 comments on commit 64b74a3

Please sign in to comment.