Skip to content

Commit

Permalink
Add importmap
Browse files Browse the repository at this point in the history
  • Loading branch information
jcoyne committed Feb 5, 2024
1 parent 9f19dff commit 02dd19e
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 13 deletions.
3 changes: 3 additions & 0 deletions config/importmap.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# frozen_string_literal: true

pin_all_from File.expand_path("../app/assets/javascripts/", __dir__)
4 changes: 4 additions & 0 deletions lib/blacklight_range_limit/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,9 @@ class Engine < Rails::Engine
config.before_configuration do
Blacklight::Configuration::FacetField.prepend BlacklightRangeLimit::FacetFieldConfigOverride
end

initializer 'blacklight_range_limit.importmap', before: "importmap" do |app|
app.config.importmap.paths << Engine.root.join("config/importmap.rb") if app.config.respond_to?(:importmap)
end
end
end
30 changes: 19 additions & 11 deletions lib/generators/blacklight_range_limit/assets_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,26 @@ def assets
say_status "warning", "Can not find application.css, did not insert our require", :red
end

append_to_file "app/assets/javascripts/application.js" do
%q{
// For blacklight_range_limit built-in JS, if you don't want it you don't need
// this:
//= require 'blacklight_range_limit'
}
if defined?(Importmap)
run 'bin/importmap pin jquery'
append_to_file "app/javascript/application.js" do
<<~CONTENT
import jQuery from "jquery"
window.jQuery = jQuery
window.$ = jQuery
import BlacklightRangeLimit from "blacklight_range_limit"
Blacklight.onLoad(() => BlacklightRangeLimit.initialize())
CONTENT
end
else
append_to_file "app/assets/javascripts/application.js" do
<<~CONTENT
// For blacklight_range_limit built-in JS, if you don't want it you don't need
// this:
//= require 'blacklight_range_limit'
CONTENT
end
end
end



end
end
3 changes: 2 additions & 1 deletion spec/features/a_javascript_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@

require 'spec_helper'

describe 'JavaScript', js: true do
RSpec.describe 'JavaScript', js: true do
it 'initializes canvas chart' do
visit search_catalog_path

click_button 'Publication Date Sort'
debugger
expect(page).to have_css '.flot-base'
end
it 'has a View larger modal' do
Expand Down
2 changes: 1 addition & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
require 'capybara/rspec'
require 'selenium-webdriver'

Capybara.javascript_driver = :headless_chrome
Capybara.javascript_driver = :selenium#:headless_chrome

Capybara.register_driver :headless_chrome do |app|
Capybara::Selenium::Driver.load_selenium
Expand Down

0 comments on commit 02dd19e

Please sign in to comment.