Skip to content
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
9 changes: 9 additions & 0 deletions .github/matrix.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,15 @@
"ruby": "3.4",
"rails_version": "8.0.2"
},
{
"ruby": "3.4",
"rails_version": "8.1.3"
},
{
"ruby": "3.4",
"rails_version": "8.1.3",
"bootstrap_version": "~> 4.0"
},
{
"ruby": "3.3",
"rails_version": "7.1.5.1",
Expand Down
2 changes: 1 addition & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require:
plugins:
- rubocop-capybara
- rubocop-rails
- rubocop-rspec
Expand Down
4 changes: 2 additions & 2 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@

# Offense count: 4
# This cop supports safe autocorrection (--autocorrect).
Capybara/CurrentPathExpectation:
Capybara/RSpec/CurrentPathExpectation:
Exclude:
- 'spec/features/alternate_controller_spec.rb'

# Offense count: 20
Capybara/VisibilityMatcher:
Capybara/RSpec/VisibilityMatcher:
Exclude:
- 'spec/features/facets_spec.rb'
- 'spec/features/search_filters_spec.rb'
Expand Down
4 changes: 3 additions & 1 deletion .solr_wrapper.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Place any default configuration for solr_wrapper here
# port: 8983
env:
SOLR_MODULES: analysis-extras
collection:
dir: lib/generators/blacklight/templates/solr/conf
dir: lib/generators/blacklight/templates/solr/
name: blacklight-core
2 changes: 1 addition & 1 deletion blacklight.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Gem::Specification.new do |s|

s.required_ruby_version = '>= 2.7'

s.add_dependency "rails", '>= 6.1', '< 8.1'
s.add_dependency "rails", '>= 6.1', '< 9'
s.add_dependency "globalid"
s.add_dependency "jbuilder", '~> 2.7'
s.add_dependency "kaminari", ">= 0.15" # the pagination (page 1,2,3, etc..) of our search results
Expand Down
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/javascript/blacklight", __dir__), under: "blacklight"
12 changes: 6 additions & 6 deletions lib/blacklight/configuration/field.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,20 @@ class Configuration::Field < OpenStructWithHashAccess

def normalize! _blacklight_config = nil
self.field ||= key
self.key ||= self.field
self.key ||= field

self.label ||= default_label

self.if = true if self.if.nil?
self.unless = false if self.unless.nil?

self.field &&= self.field.to_s
self.field &&= field.to_s

self
end

def validate!
raise ArgumentError, "Must supply a field name" if self.field.nil?
raise ArgumentError, "Must supply a field name" if field.nil?
end

def display_label(context = nil, **options)
Expand All @@ -43,10 +43,10 @@ def display_label(context = nil, **options)
end

def default_label
if self.key.respond_to?(:titleize)
self.key.titleize
if key.respond_to?(:titleize)
key.titleize
else
self.key.to_s.titleize
key.to_s.titleize
end
end

Expand Down
4 changes: 2 additions & 2 deletions lib/blacklight/configuration/sort_field.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ def normalize! blacklight_config = nil
self.field ||= label&.parameterize
self.field ||= sort

self.sort ||= self.field
self.sort ||= field

self
end

def validate!
raise ArgumentError.new, "Must supply a sort string" if self.sort.nil?
raise ArgumentError.new, "Must supply a sort string" if sort.nil?
end
end
end
13 changes: 9 additions & 4 deletions lib/blacklight/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,18 @@ class Engine < Rails::Engine
end
end

initializer "blacklight.assets.precompile" do
initializer "blacklight.assets.precompile" do |app|
PRECOMPILE_ASSETS = %w(favicon.ico blacklight/blacklight.js blacklight/blacklight.js.map).freeze

# When Rails has been generated in API mode, it does not have sprockets available
if Rails.application.config.respond_to?(:assets)
Rails.application.config.assets.precompile += PRECOMPILE_ASSETS
end
next unless app.config.respond_to?(:assets)

app.config.assets.paths << Engine.root.join("app/javascript")
app.config.assets.precompile += PRECOMPILE_ASSETS
end

initializer "blacklight.importmap", before: "importmap" do |app|
app.config.importmap.paths << Engine.root.join("config/importmap.rb") if app.config.respond_to?(:importmap)
end

bl_global_config = OpenStructWithHashAccess.new
Expand Down
56 changes: 56 additions & 0 deletions lib/generators/blacklight/assets/importmap_generator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# frozen_string_literal: true

module Blacklight
module Assets
class ImportmapGenerator < Rails::Generators::Base
class_option :'bootstrap-version', type: :string, default: ENV.fetch('BOOTSTRAP_VERSION', '~> 5.1'), desc: "Set the generated app's bootstrap version"

# This could be skipped if you want to use webpacker
def add_javascript_dependencies
gem 'bootstrap', options[:'bootstrap-version'].presence # in rails 7, only for stylesheets
gem 'jquery-rails' if bootstrap_4? # Bootstrap 4 has a dependency on jquery
end

def import_javascript_assets
append_to_file 'config/importmap.rb' do
<<~CONTENT
pin "@github/auto-complete-element", to: "https://cdn.skypack.dev/@github/auto-complete-element"
pin "@popperjs/core", to: "https://ga.jspm.io/npm:@popperjs/core@2.11.6/dist/umd/popper.min.js"
pin "bootstrap", to: "https://ga.jspm.io/npm:bootstrap@#{(defined?(Bootstrap) && Bootstrap::VERSION) || '5.2.2'}/dist/js/bootstrap.js"
CONTENT
end

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

def append_blacklight_javascript
append_to_file 'app/javascript/application.js' do
<<~CONTENT
import bootstrap from "bootstrap"
import githubAutoCompleteElement from "@github/auto-complete-element"
import Blacklight from "blacklight"
CONTENT
end
end

def add_stylesheet
gem "sassc-rails", "~> 2.1" if Rails.version > '7'

create_file 'app/assets/stylesheets/blacklight.scss' do
<<~CONTENT
@import 'bootstrap';
@import 'blacklight/blacklight';
CONTENT
end
end

def bootstrap_4?
options[:'bootstrap-version'].match?(/\A[^0-9]*4\./)
end
end
end
end
34 changes: 34 additions & 0 deletions lib/generators/blacklight/assets/propshaft_generator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# frozen_string_literal: true

module Blacklight
module Assets
class PropshaftGenerator < Rails::Generators::Base
def add_package
if ENV['CI']
run "yarn add blacklight-frontend:#{Blacklight::Engine.root}"
else
run 'yarn add blacklight-frontend'
end
end

def add_third_party_packages
run 'yarn add @github/auto-complete-element'
end

def add_package_assets
append_to_file 'app/assets/stylesheets/application.bootstrap.scss' do
<<~CONTENT
@import "blacklight-frontend/app/assets/stylesheets/blacklight/blacklight";
CONTENT
end

append_to_file 'app/javascript/application.js' do
<<~CONTENT
import Blacklight from "blacklight-frontend";
import githubAutoCompleteElement from "@github/auto-complete-element";
CONTENT
end
end
end
end
end
100 changes: 100 additions & 0 deletions lib/generators/blacklight/assets/sprockets_generator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
# frozen_string_literal: true

module Blacklight
module Assets
class SprocketsGenerator < Rails::Generators::Base
class_option :'bootstrap-version', type: :string, default: ENV.fetch('BOOTSTRAP_VERSION', '~> 4.0'), desc: "Set the generated app's bootstrap version"

def replace_propshaft_with_sprockets
return if defined?(Sprockets)

# Rails 8+ defaults to Propshaft, but Blacklight 7.x JS requires Sprockets
gsub_file 'Gemfile', /^gem ['"]propshaft['"].*$/, '# \0'
gem 'sprockets-rails'
end

def add_javascript_dependencies
gem 'bootstrap', options[:'bootstrap-version'].presence
gem 'jquery-rails'
gem 'twitter-typeahead-rails', '0.11.1.pre.corejavascript'
end

def add_sass_support
gem "sassc-rails", "~> 2.1" if Rails.version > '7'
end

def setup_sprockets_manifest
if !defined?(Sprockets)
# Rails 8+ with Propshaft replaced: create Sprockets config from scratch
directory = File.expand_path('app/assets/config', destination_root)
FileUtils.mkdir_p(directory)
create_file 'app/assets/config/manifest.js' do
<<~CONTENT
//= link_tree ../images
//= link_directory ../stylesheets .css
//= link application.js
CONTENT
end
empty_directory 'app/assets/images'
elsif defined?(Sprockets::VERSION) && Sprockets::VERSION >= '4'
append_to_file 'app/assets/config/manifest.js', "\n//= link application.js"
empty_directory 'app/assets/images'
end
end

def assets # rubocop:disable Metrics/MethodLength
create_file 'app/assets/stylesheets/blacklight.scss' do
<<~CONTENT
@import 'bootstrap';
@import 'blacklight/blacklight';
CONTENT
end

# Ensure application.css is a proper Sprockets manifest that loads blacklight styles
application_css = File.expand_path('app/assets/stylesheets/application.css', destination_root)
if File.exist?(application_css)
content = File.read(application_css)
unless content.include?('require blacklight')
create_file 'app/assets/stylesheets/application.css', force: true do
<<~CONTENT
/*
*= require blacklight
*= require_self
*/
CONTENT
end
end
end

# Ensure this method is idempotent
return if has_blacklight_assets?

create_file 'app/assets/javascripts/application.js' do
<<~CONTENT
//= require jquery3
//= require rails-ujs

// Required by Blacklight
//= require popper
// Twitter Typeahead for autocomplete
//= require twitter/typeahead
//= require bootstrap
//= require blacklight/blacklight
CONTENT
end
end

private

def has_blacklight_assets?
application_js.include?('blacklight/blacklight')
end

def application_js
path = File.expand_path("app/assets/javascripts/application.js", destination_root)

File.exist?(path) ? File.read(path) : ''
end
end
end
end
Loading
Loading