blacklight 7.40.0 → 7.42.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/matrix.json +71 -0
- data/.github/workflows/build.yml +16 -0
- data/.github/workflows/lint.yml +23 -0
- data/.github/workflows/main.yml +23 -0
- data/.github/workflows/test.yml +52 -0
- data/.rubocop.yml +1 -1
- data/.rubocop_todo.yml +2 -2
- data/.solr_wrapper.yml +3 -1
- data/VERSION +1 -1
- data/app/components/blacklight/document/action_component.rb +1 -3
- data/app/components/blacklight/search_context/server_item_pagination_component.html.erb +10 -0
- data/app/components/blacklight/search_context/server_item_pagination_component.rb +15 -0
- data/app/components/blacklight/search_context_component.rb +1 -0
- data/app/controllers/concerns/blacklight/search_fields.rb +1 -1
- data/app/helpers/blacklight/catalog_helper_behavior.rb +1 -1
- data/app/helpers/blacklight/url_helper_behavior.rb +2 -2
- data/app/presenters/blacklight/json_presenter.rb +1 -3
- data/app/views/catalog/_previous_next_doc.html.erb +1 -1
- data/blacklight.gemspec +1 -1
- data/config/importmap.rb +3 -0
- data/docker-compose.yml +1 -0
- data/lib/blacklight/configuration/field.rb +6 -6
- data/lib/blacklight/configuration/sort_field.rb +2 -2
- data/lib/blacklight/engine.rb +9 -4
- data/lib/blacklight/nested_open_struct_with_hash_access.rb +1 -1
- data/lib/generators/blacklight/assets/importmap_generator.rb +56 -0
- data/lib/generators/blacklight/assets/propshaft_generator.rb +34 -0
- data/lib/generators/blacklight/assets/sprockets_generator.rb +100 -0
- data/lib/generators/blacklight/assets_generator.rb +9 -86
- data/lib/generators/blacklight/controller_generator.rb +1 -1
- data/lib/generators/blacklight/install_generator.rb +2 -2
- data/lib/generators/blacklight/templates/solr/conf/solrconfig.xml +4 -8
- data/lib/generators/blacklight/test_support_generator.rb +1 -1
- data/package.json +1 -1
- data/spec/components/blacklight/search_context/server_item_pagination_component_spec.rb +35 -0
- data/spec/components/blacklight/search_context_component_spec.rb +31 -0
- data/spec/controllers/blacklight/base_spec.rb +1 -1
- data/spec/features/facets_spec.rb +3 -5
- data/spec/features/search_context_spec.rb +1 -1
- data/spec/helpers/blacklight/facets_helper_behavior_spec.rb +1 -2
- data/spec/models/solr_document_spec.rb +3 -1
- data/spec/spec_helper.rb +5 -2
- data/spec/test_app_templates/lib/generators/test_app_generator.rb +1 -1
- data/tasks/blacklight.rake +1 -1
- metadata +20 -6
- data/.github/workflows/ruby.yml +0 -159
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 52a04abd135541f36cb96f7e8538c190b034ca08d2a66a52b46bc7ac22c1ee21
|
|
4
|
+
data.tar.gz: 26250b77f584c4b7d7316dd51a86fb465444e30c91f3c3bcd6ff5899a8012b65
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b9c4b32a75d4bbefe63e2cb4e54d2e221d110a152014b7150c124950c8a457da8059ab5ed87a0bbe2a7e0d754914abad0457745366a4060b62878284e95076b6
|
|
7
|
+
data.tar.gz: aa0a5810de6e1b1eb19a611061b310e093f57179261c3eff3f8e6a8830cb03ef47f5ce22800f2a9a3653a1867842d12786a1d805ee3d3e26e856c5e85d753574
|
data/.github/matrix.json
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
{
|
|
2
|
+
"ruby": ["3.3"],
|
|
3
|
+
"rails_version": [
|
|
4
|
+
"7.1.5.1",
|
|
5
|
+
"7.2.2.1"
|
|
6
|
+
],
|
|
7
|
+
"bootstrap_version": [
|
|
8
|
+
null
|
|
9
|
+
],
|
|
10
|
+
"view_component_version": [
|
|
11
|
+
"~> 3.12"
|
|
12
|
+
],
|
|
13
|
+
"api": [
|
|
14
|
+
null
|
|
15
|
+
],
|
|
16
|
+
"additional_engine_cart_rails_options": [
|
|
17
|
+
""
|
|
18
|
+
],
|
|
19
|
+
"additional_name": [
|
|
20
|
+
""
|
|
21
|
+
],
|
|
22
|
+
"include": [
|
|
23
|
+
{
|
|
24
|
+
"ruby": "3.2",
|
|
25
|
+
"rails_version": "7.1.5.1"
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
"ruby": "3.3",
|
|
29
|
+
"rails_version": "7.1.5.1",
|
|
30
|
+
"bootstrap_version": "~> 5.0",
|
|
31
|
+
"additional_name": "| bootstrap 5"
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
"ruby": "3.4",
|
|
35
|
+
"rails_version": "7.2.2.1"
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
"ruby": "3.4",
|
|
39
|
+
"rails_version": "8.0.2"
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
"ruby": "3.4",
|
|
43
|
+
"rails_version": "8.1.3"
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
"ruby": "3.4",
|
|
47
|
+
"rails_version": "8.1.3",
|
|
48
|
+
"bootstrap_version": "~> 4.0"
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
"ruby": "3.3",
|
|
52
|
+
"rails_version": "7.1.5.1",
|
|
53
|
+
"view_component_version": "~> 2.74",
|
|
54
|
+
"additional_name": "| View Component 2"
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
"ruby": "3.2",
|
|
58
|
+
"rails_version": "7.1.5.1",
|
|
59
|
+
"api": "true",
|
|
60
|
+
"additional_engine_cart_rails_options": "--api --skip-yarn",
|
|
61
|
+
"additional_name": "| API"
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
"ruby": "3.3",
|
|
65
|
+
"rails_version": "7.1.5.1",
|
|
66
|
+
"api:": "true",
|
|
67
|
+
"additional_engine_cart_rails_options": "--api --skip-yarn",
|
|
68
|
+
"additional_name": "| API"
|
|
69
|
+
}
|
|
70
|
+
]
|
|
71
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
on:
|
|
2
|
+
workflow_call:
|
|
3
|
+
inputs:
|
|
4
|
+
ref:
|
|
5
|
+
required: false
|
|
6
|
+
type: string
|
|
7
|
+
default: ''
|
|
8
|
+
jobs:
|
|
9
|
+
build:
|
|
10
|
+
runs-on: ubuntu-latest
|
|
11
|
+
steps:
|
|
12
|
+
- uses: actions/checkout@v4
|
|
13
|
+
with:
|
|
14
|
+
ref: ${{ inputs.ref }}
|
|
15
|
+
- name: Build docker image
|
|
16
|
+
run: docker compose build app
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
on:
|
|
2
|
+
workflow_call:
|
|
3
|
+
inputs:
|
|
4
|
+
ref:
|
|
5
|
+
required: false
|
|
6
|
+
type: string
|
|
7
|
+
default: ''
|
|
8
|
+
jobs:
|
|
9
|
+
lint:
|
|
10
|
+
runs-on: ubuntu-latest
|
|
11
|
+
steps:
|
|
12
|
+
- uses: actions/checkout@v4
|
|
13
|
+
with:
|
|
14
|
+
ref: ${{ inputs.ref }}
|
|
15
|
+
- name: Set up Ruby
|
|
16
|
+
uses: ruby/setup-ruby@v1
|
|
17
|
+
with:
|
|
18
|
+
ruby-version: 3.2
|
|
19
|
+
bundler: "default"
|
|
20
|
+
- name: Install dependencies
|
|
21
|
+
run: bundle install
|
|
22
|
+
- name: Run linter
|
|
23
|
+
run: bundle exec rake rubocop
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# This workflow uses actions that are not certified by GitHub.
|
|
2
|
+
# They are provided by a third-party and are governed by
|
|
3
|
+
# separate terms of service, privacy policy, and support
|
|
4
|
+
# documentation.
|
|
5
|
+
# This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
|
|
6
|
+
# For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
|
|
7
|
+
|
|
8
|
+
name: CI
|
|
9
|
+
|
|
10
|
+
on:
|
|
11
|
+
push:
|
|
12
|
+
branches:
|
|
13
|
+
- main
|
|
14
|
+
- 'release-*'
|
|
15
|
+
pull_request:
|
|
16
|
+
|
|
17
|
+
jobs:
|
|
18
|
+
lint:
|
|
19
|
+
uses: ./.github/workflows/lint.yml
|
|
20
|
+
test:
|
|
21
|
+
uses: ./.github/workflows/test.yml
|
|
22
|
+
docker_build:
|
|
23
|
+
uses: ./.github/workflows/build.yml
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
on:
|
|
2
|
+
workflow_call:
|
|
3
|
+
inputs:
|
|
4
|
+
ref:
|
|
5
|
+
required: false
|
|
6
|
+
type: string
|
|
7
|
+
default: ""
|
|
8
|
+
description: The branch or reference to run the workflow against
|
|
9
|
+
jobs:
|
|
10
|
+
set_matrix:
|
|
11
|
+
runs-on: ubuntu-latest
|
|
12
|
+
outputs:
|
|
13
|
+
matrix: ${{ steps.matrix.outputs.matrix }}
|
|
14
|
+
steps:
|
|
15
|
+
- name: Checkout repository
|
|
16
|
+
uses: actions/checkout@v3
|
|
17
|
+
with:
|
|
18
|
+
ref: ${{ inputs.ref }}
|
|
19
|
+
- name: Echo ./.github/matrix.json
|
|
20
|
+
id: matrix
|
|
21
|
+
run: |
|
|
22
|
+
echo "matrix<<EOF" >> $GITHUB_OUTPUT
|
|
23
|
+
cat ./.github/matrix.json >> $GITHUB_OUTPUT
|
|
24
|
+
echo "EOF" >> $GITHUB_OUTPUT
|
|
25
|
+
test:
|
|
26
|
+
needs: set_matrix
|
|
27
|
+
runs-on: ubuntu-latest
|
|
28
|
+
name: ruby ${{ matrix.ruby }} | rails ${{ matrix.rails_version }} ${{ matrix.additional_name }}
|
|
29
|
+
strategy:
|
|
30
|
+
fail-fast: false
|
|
31
|
+
matrix: ${{fromJson(needs.set_matrix.outputs.matrix)}}
|
|
32
|
+
env:
|
|
33
|
+
RAILS_VERSION: ${{ matrix.rails_version }}
|
|
34
|
+
SOLR_VERSION: ${{ matrix.solr_version || 'latest' }}
|
|
35
|
+
VIEW_COMPONENT_VERSION: ${{ matrix.view_component_version }}
|
|
36
|
+
BOOTSTRAP_VERSION: ${{ matrix.bootstrap_version }}
|
|
37
|
+
BLACKLIGHT_API_TEST: ${{ matrix.api }}
|
|
38
|
+
ENGINE_CART_RAILS_OPTIONS: "--skip-git --skip-listen --skip-spring --skip-keeps --skip-kamal --skip-solid --skip-coffee --skip-test ${{ matrix.additional_engine_cart_rails_options }}"
|
|
39
|
+
steps:
|
|
40
|
+
- uses: actions/checkout@v4
|
|
41
|
+
with:
|
|
42
|
+
ref: ${{ inputs.ref }}
|
|
43
|
+
- name: Set up Ruby
|
|
44
|
+
uses: ruby/setup-ruby@v1
|
|
45
|
+
with:
|
|
46
|
+
ruby-version: ${{ matrix.ruby }}
|
|
47
|
+
- name: Change permissions
|
|
48
|
+
run: "chmod -f -R o-w /opt/hostedtoolcache/Ruby/3.2.5/x64/lib/ruby/gems/3.2.0/gems | :"
|
|
49
|
+
- name: Install dependencies
|
|
50
|
+
run: bundle install
|
|
51
|
+
- name: Run tests
|
|
52
|
+
run: bundle exec rake ci
|
data/.rubocop.yml
CHANGED
data/.rubocop_todo.yml
CHANGED
|
@@ -8,12 +8,12 @@
|
|
|
8
8
|
|
|
9
9
|
# Offense count: 4
|
|
10
10
|
# This cop supports safe autocorrection (--autocorrect).
|
|
11
|
-
Capybara/CurrentPathExpectation:
|
|
11
|
+
Capybara/RSpec/CurrentPathExpectation:
|
|
12
12
|
Exclude:
|
|
13
13
|
- 'spec/features/alternate_controller_spec.rb'
|
|
14
14
|
|
|
15
15
|
# Offense count: 20
|
|
16
|
-
Capybara/VisibilityMatcher:
|
|
16
|
+
Capybara/RSpec/VisibilityMatcher:
|
|
17
17
|
Exclude:
|
|
18
18
|
- 'spec/features/facets_spec.rb'
|
|
19
19
|
- 'spec/features/search_filters_spec.rb'
|
data/.solr_wrapper.yml
CHANGED
data/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
7.
|
|
1
|
+
7.42.0
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Blacklight
|
|
4
|
+
module SearchContext
|
|
5
|
+
class ServerItemPaginationComponent < Blacklight::SearchContextComponent
|
|
6
|
+
with_collection_parameter :search_context
|
|
7
|
+
|
|
8
|
+
def initialize(search_context:, search_session:, current_document:)
|
|
9
|
+
@search_context = search_context
|
|
10
|
+
@search_session = search_session
|
|
11
|
+
@current_document_id = current_document.id
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
@@ -5,6 +5,7 @@ module Blacklight
|
|
|
5
5
|
with_collection_parameter :search_context
|
|
6
6
|
|
|
7
7
|
def initialize(search_context:, search_session:)
|
|
8
|
+
Deprecation.warn("Blacklight::SearchContextComponent is deprecated and will be moved to Blacklight::SearchContext::ServerItemPaginationComponent in Blacklight 8.0.0")
|
|
8
9
|
@search_context = search_context
|
|
9
10
|
@search_session = search_session
|
|
10
11
|
end
|
|
@@ -40,7 +40,7 @@ module Blacklight::SearchFields
|
|
|
40
40
|
# if not set in blacklight_config, defaults to first field listed in #search_field_list
|
|
41
41
|
# @deprecated
|
|
42
42
|
def default_search_field
|
|
43
|
-
blacklight_config.default_search_field ||
|
|
43
|
+
blacklight_config.default_search_field || Deprecation.silence(Blacklight::SearchFields) { search_field_list.first }
|
|
44
44
|
end
|
|
45
45
|
deprecation_deprecate default_search_field: 'Use Blacklight::Configuration#default_search_field'
|
|
46
46
|
end
|
|
@@ -106,7 +106,7 @@ module Blacklight::CatalogHelperBehavior
|
|
|
106
106
|
total: number_with_delimiter(search_session['total']),
|
|
107
107
|
count: search_session['total'].to_i).html_safe
|
|
108
108
|
end
|
|
109
|
-
deprecation_deprecate item_page_entry_info: 'Use Blacklight::
|
|
109
|
+
deprecation_deprecate item_page_entry_info: 'Use Blacklight::SearchContext::ServerItemPaginationComponent methods instead'
|
|
110
110
|
|
|
111
111
|
##
|
|
112
112
|
# Look up search field user-displayable label
|
|
@@ -58,7 +58,7 @@ module Blacklight::UrlHelperBehavior
|
|
|
58
58
|
tag.span raw(t('views.pagination.previous')), class: 'previous'
|
|
59
59
|
end
|
|
60
60
|
end
|
|
61
|
-
deprecation_deprecate link_to_previous_document: 'Moving to Blacklight::
|
|
61
|
+
deprecation_deprecate link_to_previous_document: 'Moving to Blacklight::SearchContext::ServerItemPaginationComponent'
|
|
62
62
|
|
|
63
63
|
##
|
|
64
64
|
# Link to the next document in the current search context
|
|
@@ -69,7 +69,7 @@ module Blacklight::UrlHelperBehavior
|
|
|
69
69
|
tag.span raw(t('views.pagination.next')), class: 'next'
|
|
70
70
|
end
|
|
71
71
|
end
|
|
72
|
-
deprecation_deprecate link_to_previous_document: 'Moving to Blacklight::
|
|
72
|
+
deprecation_deprecate link_to_previous_document: 'Moving to Blacklight::SearchContext::ServerItemPaginationComponent'
|
|
73
73
|
|
|
74
74
|
##
|
|
75
75
|
# Attributes for a link that gives a URL we can use to track clicks for the current search session
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
<% Deprecation.warn(self, 'The partial _previous_next_doc.html.erb will be removed in 8.0. Render Blacklight::
|
|
1
|
+
<% Deprecation.warn(self, 'The partial _previous_next_doc.html.erb will be removed in 8.0. Render Blacklight::SearchContext::ServerItemPaginationComponent instead.') %>
|
|
2
2
|
<%= render(Blacklight::SearchContextComponent.new(search_context: @search_context, search_session: search_session)) %>
|
data/blacklight.gemspec
CHANGED
|
@@ -25,7 +25,7 @@ Gem::Specification.new do |s|
|
|
|
25
25
|
|
|
26
26
|
s.required_ruby_version = '>= 2.7'
|
|
27
27
|
|
|
28
|
-
s.add_dependency "rails", '>= 6.1', '<
|
|
28
|
+
s.add_dependency "rails", '>= 6.1', '< 9'
|
|
29
29
|
s.add_dependency "globalid"
|
|
30
30
|
s.add_dependency "jbuilder", '~> 2.7'
|
|
31
31
|
s.add_dependency "kaminari", ">= 0.15" # the pagination (page 1,2,3, etc..) of our search results
|
data/config/importmap.rb
ADDED
data/docker-compose.yml
CHANGED
|
@@ -23,6 +23,7 @@ services:
|
|
|
23
23
|
environment:
|
|
24
24
|
- SOLR_PORT # Set via environment variable or use default defined in .env file
|
|
25
25
|
- SOLR_VERSION # Set via environment variable or use default defined in .env file
|
|
26
|
+
- SOLR_MODULES=analysis-extras
|
|
26
27
|
image: "solr:${SOLR_VERSION}"
|
|
27
28
|
volumes:
|
|
28
29
|
- $PWD/lib/generators/blacklight/templates/solr/conf:/opt/solr/conf
|
|
@@ -16,20 +16,20 @@ module Blacklight
|
|
|
16
16
|
|
|
17
17
|
def normalize! _blacklight_config = nil
|
|
18
18
|
self.field ||= key
|
|
19
|
-
self.key ||=
|
|
19
|
+
self.key ||= field
|
|
20
20
|
|
|
21
21
|
self.label ||= default_label
|
|
22
22
|
|
|
23
23
|
self.if = true if self.if.nil?
|
|
24
24
|
self.unless = false if self.unless.nil?
|
|
25
25
|
|
|
26
|
-
self.field &&=
|
|
26
|
+
self.field &&= field.to_s
|
|
27
27
|
|
|
28
28
|
self
|
|
29
29
|
end
|
|
30
30
|
|
|
31
31
|
def validate!
|
|
32
|
-
raise ArgumentError, "Must supply a field name" if
|
|
32
|
+
raise ArgumentError, "Must supply a field name" if field.nil?
|
|
33
33
|
end
|
|
34
34
|
|
|
35
35
|
def display_label(context = nil, **options)
|
|
@@ -43,10 +43,10 @@ module Blacklight
|
|
|
43
43
|
end
|
|
44
44
|
|
|
45
45
|
def default_label
|
|
46
|
-
if
|
|
47
|
-
|
|
46
|
+
if key.respond_to?(:titleize)
|
|
47
|
+
key.titleize
|
|
48
48
|
else
|
|
49
|
-
|
|
49
|
+
key.to_s.titleize
|
|
50
50
|
end
|
|
51
51
|
end
|
|
52
52
|
|
|
@@ -9,13 +9,13 @@ module Blacklight
|
|
|
9
9
|
self.field ||= label&.parameterize
|
|
10
10
|
self.field ||= sort
|
|
11
11
|
|
|
12
|
-
self.sort ||=
|
|
12
|
+
self.sort ||= field
|
|
13
13
|
|
|
14
14
|
self
|
|
15
15
|
end
|
|
16
16
|
|
|
17
17
|
def validate!
|
|
18
|
-
raise ArgumentError.new, "Must supply a sort string" if
|
|
18
|
+
raise ArgumentError.new, "Must supply a sort string" if sort.nil?
|
|
19
19
|
end
|
|
20
20
|
end
|
|
21
21
|
end
|
data/lib/blacklight/engine.rb
CHANGED
|
@@ -38,13 +38,18 @@ module Blacklight
|
|
|
38
38
|
end
|
|
39
39
|
end
|
|
40
40
|
|
|
41
|
-
initializer "blacklight.assets.precompile" do
|
|
41
|
+
initializer "blacklight.assets.precompile" do |app|
|
|
42
42
|
PRECOMPILE_ASSETS = %w(favicon.ico blacklight/blacklight.js blacklight/blacklight.js.map).freeze
|
|
43
43
|
|
|
44
44
|
# When Rails has been generated in API mode, it does not have sprockets available
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
45
|
+
next unless app.config.respond_to?(:assets)
|
|
46
|
+
|
|
47
|
+
app.config.assets.paths << Engine.root.join("app/javascript")
|
|
48
|
+
app.config.assets.precompile += PRECOMPILE_ASSETS
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
initializer "blacklight.importmap", before: "importmap" do |app|
|
|
52
|
+
app.config.importmap.paths << Engine.root.join("config/importmap.rb") if app.config.respond_to?(:importmap)
|
|
48
53
|
end
|
|
49
54
|
|
|
50
55
|
bl_global_config = OpenStructWithHashAccess.new
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Blacklight
|
|
4
|
+
module Assets
|
|
5
|
+
class ImportmapGenerator < Rails::Generators::Base
|
|
6
|
+
class_option :'bootstrap-version', type: :string, default: ENV.fetch('BOOTSTRAP_VERSION', '~> 5.1'), desc: "Set the generated app's bootstrap version"
|
|
7
|
+
|
|
8
|
+
# This could be skipped if you want to use webpacker
|
|
9
|
+
def add_javascript_dependencies
|
|
10
|
+
gem 'bootstrap', options[:'bootstrap-version'].presence # in rails 7, only for stylesheets
|
|
11
|
+
gem 'jquery-rails' if bootstrap_4? # Bootstrap 4 has a dependency on jquery
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def import_javascript_assets
|
|
15
|
+
append_to_file 'config/importmap.rb' do
|
|
16
|
+
<<~CONTENT
|
|
17
|
+
pin "@github/auto-complete-element", to: "https://cdn.skypack.dev/@github/auto-complete-element"
|
|
18
|
+
pin "@popperjs/core", to: "https://ga.jspm.io/npm:@popperjs/core@2.11.6/dist/umd/popper.min.js"
|
|
19
|
+
pin "bootstrap", to: "https://ga.jspm.io/npm:bootstrap@#{(defined?(Bootstrap) && Bootstrap::VERSION) || '5.2.2'}/dist/js/bootstrap.js"
|
|
20
|
+
CONTENT
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
append_to_file 'app/assets/config/manifest.js' do
|
|
24
|
+
<<~CONTENT
|
|
25
|
+
//= link blacklight/manifest.js
|
|
26
|
+
CONTENT
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def append_blacklight_javascript
|
|
31
|
+
append_to_file 'app/javascript/application.js' do
|
|
32
|
+
<<~CONTENT
|
|
33
|
+
import bootstrap from "bootstrap"
|
|
34
|
+
import githubAutoCompleteElement from "@github/auto-complete-element"
|
|
35
|
+
import Blacklight from "blacklight"
|
|
36
|
+
CONTENT
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def add_stylesheet
|
|
41
|
+
gem "sassc-rails", "~> 2.1" if Rails.version > '7'
|
|
42
|
+
|
|
43
|
+
create_file 'app/assets/stylesheets/blacklight.scss' do
|
|
44
|
+
<<~CONTENT
|
|
45
|
+
@import 'bootstrap';
|
|
46
|
+
@import 'blacklight/blacklight';
|
|
47
|
+
CONTENT
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def bootstrap_4?
|
|
52
|
+
options[:'bootstrap-version'].match?(/\A[^0-9]*4\./)
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Blacklight
|
|
4
|
+
module Assets
|
|
5
|
+
class PropshaftGenerator < Rails::Generators::Base
|
|
6
|
+
def add_package
|
|
7
|
+
if ENV['CI']
|
|
8
|
+
run "yarn add blacklight-frontend:#{Blacklight::Engine.root}"
|
|
9
|
+
else
|
|
10
|
+
run 'yarn add blacklight-frontend'
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def add_third_party_packages
|
|
15
|
+
run 'yarn add @github/auto-complete-element'
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def add_package_assets
|
|
19
|
+
append_to_file 'app/assets/stylesheets/application.bootstrap.scss' do
|
|
20
|
+
<<~CONTENT
|
|
21
|
+
@import "blacklight-frontend/app/assets/stylesheets/blacklight/blacklight";
|
|
22
|
+
CONTENT
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
append_to_file 'app/javascript/application.js' do
|
|
26
|
+
<<~CONTENT
|
|
27
|
+
import Blacklight from "blacklight-frontend";
|
|
28
|
+
import githubAutoCompleteElement from "@github/auto-complete-element";
|
|
29
|
+
CONTENT
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Blacklight
|
|
4
|
+
module Assets
|
|
5
|
+
class SprocketsGenerator < Rails::Generators::Base
|
|
6
|
+
class_option :'bootstrap-version', type: :string, default: ENV.fetch('BOOTSTRAP_VERSION', '~> 4.0'), desc: "Set the generated app's bootstrap version"
|
|
7
|
+
|
|
8
|
+
def replace_propshaft_with_sprockets
|
|
9
|
+
return if defined?(Sprockets)
|
|
10
|
+
|
|
11
|
+
# Rails 8+ defaults to Propshaft, but Blacklight 7.x JS requires Sprockets
|
|
12
|
+
gsub_file 'Gemfile', /^gem ['"]propshaft['"].*$/, '# \0'
|
|
13
|
+
gem 'sprockets-rails'
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def add_javascript_dependencies
|
|
17
|
+
gem 'bootstrap', options[:'bootstrap-version'].presence
|
|
18
|
+
gem 'jquery-rails'
|
|
19
|
+
gem 'twitter-typeahead-rails', '0.11.1.pre.corejavascript'
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def add_sass_support
|
|
23
|
+
gem "sassc-rails", "~> 2.1" if Rails.version > '7'
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def setup_sprockets_manifest
|
|
27
|
+
if !defined?(Sprockets)
|
|
28
|
+
# Rails 8+ with Propshaft replaced: create Sprockets config from scratch
|
|
29
|
+
directory = File.expand_path('app/assets/config', destination_root)
|
|
30
|
+
FileUtils.mkdir_p(directory)
|
|
31
|
+
create_file 'app/assets/config/manifest.js' do
|
|
32
|
+
<<~CONTENT
|
|
33
|
+
//= link_tree ../images
|
|
34
|
+
//= link_directory ../stylesheets .css
|
|
35
|
+
//= link application.js
|
|
36
|
+
CONTENT
|
|
37
|
+
end
|
|
38
|
+
empty_directory 'app/assets/images'
|
|
39
|
+
elsif defined?(Sprockets::VERSION) && Sprockets::VERSION >= '4'
|
|
40
|
+
append_to_file 'app/assets/config/manifest.js', "\n//= link application.js"
|
|
41
|
+
empty_directory 'app/assets/images'
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def assets # rubocop:disable Metrics/MethodLength
|
|
46
|
+
create_file 'app/assets/stylesheets/blacklight.scss' do
|
|
47
|
+
<<~CONTENT
|
|
48
|
+
@import 'bootstrap';
|
|
49
|
+
@import 'blacklight/blacklight';
|
|
50
|
+
CONTENT
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
# Ensure application.css is a proper Sprockets manifest that loads blacklight styles
|
|
54
|
+
application_css = File.expand_path('app/assets/stylesheets/application.css', destination_root)
|
|
55
|
+
if File.exist?(application_css)
|
|
56
|
+
content = File.read(application_css)
|
|
57
|
+
unless content.include?('require blacklight')
|
|
58
|
+
create_file 'app/assets/stylesheets/application.css', force: true do
|
|
59
|
+
<<~CONTENT
|
|
60
|
+
/*
|
|
61
|
+
*= require blacklight
|
|
62
|
+
*= require_self
|
|
63
|
+
*/
|
|
64
|
+
CONTENT
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
# Ensure this method is idempotent
|
|
70
|
+
return if has_blacklight_assets?
|
|
71
|
+
|
|
72
|
+
create_file 'app/assets/javascripts/application.js' do
|
|
73
|
+
<<~CONTENT
|
|
74
|
+
//= require jquery3
|
|
75
|
+
//= require rails-ujs
|
|
76
|
+
|
|
77
|
+
// Required by Blacklight
|
|
78
|
+
//= require popper
|
|
79
|
+
// Twitter Typeahead for autocomplete
|
|
80
|
+
//= require twitter/typeahead
|
|
81
|
+
//= require bootstrap
|
|
82
|
+
//= require blacklight/blacklight
|
|
83
|
+
CONTENT
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
private
|
|
88
|
+
|
|
89
|
+
def has_blacklight_assets?
|
|
90
|
+
application_js.include?('blacklight/blacklight')
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
def application_js
|
|
94
|
+
path = File.expand_path("app/assets/javascripts/application.js", destination_root)
|
|
95
|
+
|
|
96
|
+
File.exist?(path) ? File.read(path) : ''
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
end
|