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

Test with Blacklight 8 #253

Closed
wants to merge 3 commits into from
Closed
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
16 changes: 13 additions & 3 deletions .github/workflows/ruby.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,33 @@ on:
jobs:
test:
runs-on: ubuntu-latest
name: test (ruby ${{ matrix.ruby }} / rails ${{ matrix.rails_version }})
name: test (ruby ${{ matrix.ruby }} / rails ${{ matrix.rails_version }} / blacklight ${{ matrix.blacklight_version }})
strategy:
matrix:
ruby: [2.7, '3.0']
rails_version: ['6.1.7.1', '7.0.4.1']
rails_version: ['6.1.7.1']
blacklight_version: ['~> 7.0']
additional_engine_cart_rails_options: ['']
include:
- ruby: '3.3'
rails_version: '7.1.3'
blacklight_version: '~> 7.0'
- ruby: '3.2'
rails_version: '7.0.4.1'
blacklight_version: '~> 7.0'
- ruby: '3.1'
rails_version: '7.0.4.1'
blacklight_version: '~> 7.0'
- ruby: '3.0'
rails_version: '7.0.4.1'
blacklight_version: '~> 7.0'
- ruby: '3.2'
rails_version: '7.1.3'
name: 'Blacklight 8'
blacklight_version: '8.1.0'

env:
BLACKLIGHT_VERSION: "~> 7.0" # only test on BL 7 for now
BLACKLIGHT_VERSION: ${{ matrix.blacklight_version }}
RAILS_VERSION: ${{ matrix.rails_version }}
ENGINE_CART_RAILS_OPTIONS: "--skip-git --skip-listen --skip-spring --skip-keeps --skip-coffee --skip-test ${{ matrix.engine_cart_rails_options }}"
steps:
Expand Down
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)
})
1 change: 1 addition & 0 deletions config/importmap.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pin_all_from File.expand_path('../app/assets/javascripts', __dir__)
9 changes: 9 additions & 0 deletions lib/blacklight_range_limit/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,14 @@ class Engine < Rails::Engine
config.before_configuration do
Blacklight::Configuration::FacetField.prepend BlacklightRangeLimit::FacetFieldConfigOverride
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

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
47 changes: 43 additions & 4 deletions lib/generators/blacklight_range_limit/assets_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module BlacklightRangeLimit
class AssetsGenerator < Rails::Generators::Base
source_root File.join(BlacklightRangeLimit::Engine.root, 'app', 'assets')

def assets
def copy_styles
application_css = Dir["app/assets/stylesheets/application{.css,.scss,.css.scss}"].first

if application_css
Expand All @@ -31,7 +31,49 @@ def assets
else
say_status "warning", "Can not find application.css, did not insert our require", :red
end
end

def assets
if using_importmap?
pin_javascript_dependencies
import_javascript
else
install_sprockets_dependencies
end
end


private

def root
@root ||= Pathname(destination_root)
end

def using_importmap?
@using_importmap ||= root.join('config/importmap.rb').exist?
end

def pin_javascript_dependencies
append_to_file 'config/importmap.rb', <<~RUBY
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', <<~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+
def install_sprockets_dependencies
append_to_file "app/assets/javascripts/application.js" do
%q{

Expand All @@ -42,8 +84,5 @@ def assets
}
end
end



end
end
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
7 changes: 6 additions & 1 deletion spec/test_app_templates/Gemfile.extra
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
gem 'rails-controller-testing'
gem 'blacklight', ENV['BLACKLIGHT_VERSION'] if ENV['BLACKLIGHT_VERSION']

if ENV['BLACKLIGHT_VERSION'] == 'github'
gem 'blacklight', github: 'projectblacklight/blacklight'
elsif ENV['BLACKLIGHT_VERSION'] && !ENV['BLACKLIGHT_VERSION'].empty?
gem 'blacklight', ENV['BLACKLIGHT_VERSION']
end
Loading