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.
Files changed (47) hide show
  1. checksums.yaml +4 -4
  2. data/.github/matrix.json +71 -0
  3. data/.github/workflows/build.yml +16 -0
  4. data/.github/workflows/lint.yml +23 -0
  5. data/.github/workflows/main.yml +23 -0
  6. data/.github/workflows/test.yml +52 -0
  7. data/.rubocop.yml +1 -1
  8. data/.rubocop_todo.yml +2 -2
  9. data/.solr_wrapper.yml +3 -1
  10. data/VERSION +1 -1
  11. data/app/components/blacklight/document/action_component.rb +1 -3
  12. data/app/components/blacklight/search_context/server_item_pagination_component.html.erb +10 -0
  13. data/app/components/blacklight/search_context/server_item_pagination_component.rb +15 -0
  14. data/app/components/blacklight/search_context_component.rb +1 -0
  15. data/app/controllers/concerns/blacklight/search_fields.rb +1 -1
  16. data/app/helpers/blacklight/catalog_helper_behavior.rb +1 -1
  17. data/app/helpers/blacklight/url_helper_behavior.rb +2 -2
  18. data/app/presenters/blacklight/json_presenter.rb +1 -3
  19. data/app/views/catalog/_previous_next_doc.html.erb +1 -1
  20. data/blacklight.gemspec +1 -1
  21. data/config/importmap.rb +3 -0
  22. data/docker-compose.yml +1 -0
  23. data/lib/blacklight/configuration/field.rb +6 -6
  24. data/lib/blacklight/configuration/sort_field.rb +2 -2
  25. data/lib/blacklight/engine.rb +9 -4
  26. data/lib/blacklight/nested_open_struct_with_hash_access.rb +1 -1
  27. data/lib/generators/blacklight/assets/importmap_generator.rb +56 -0
  28. data/lib/generators/blacklight/assets/propshaft_generator.rb +34 -0
  29. data/lib/generators/blacklight/assets/sprockets_generator.rb +100 -0
  30. data/lib/generators/blacklight/assets_generator.rb +9 -86
  31. data/lib/generators/blacklight/controller_generator.rb +1 -1
  32. data/lib/generators/blacklight/install_generator.rb +2 -2
  33. data/lib/generators/blacklight/templates/solr/conf/solrconfig.xml +4 -8
  34. data/lib/generators/blacklight/test_support_generator.rb +1 -1
  35. data/package.json +1 -1
  36. data/spec/components/blacklight/search_context/server_item_pagination_component_spec.rb +35 -0
  37. data/spec/components/blacklight/search_context_component_spec.rb +31 -0
  38. data/spec/controllers/blacklight/base_spec.rb +1 -1
  39. data/spec/features/facets_spec.rb +3 -5
  40. data/spec/features/search_context_spec.rb +1 -1
  41. data/spec/helpers/blacklight/facets_helper_behavior_spec.rb +1 -2
  42. data/spec/models/solr_document_spec.rb +3 -1
  43. data/spec/spec_helper.rb +5 -2
  44. data/spec/test_app_templates/lib/generators/test_app_generator.rb +1 -1
  45. data/tasks/blacklight.rake +1 -1
  46. metadata +20 -6
  47. data/.github/workflows/ruby.yml +0 -159
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4e1a5889b0f9dee50b64165ffe292482619e54780bac24b14af00b3b1cba2fdd
4
- data.tar.gz: 0ed718e93da4bca43bb242e5a97c6ced3546aa8ec9f17d18ce00a444dca95d93
3
+ metadata.gz: 52a04abd135541f36cb96f7e8538c190b034ca08d2a66a52b46bc7ac22c1ee21
4
+ data.tar.gz: 26250b77f584c4b7d7316dd51a86fb465444e30c91f3c3bcd6ff5899a8012b65
5
5
  SHA512:
6
- metadata.gz: ee5a1dc4ddb014510defa98a6c36a3d0e3ef9913c5cce5195878c688d062f7b95e3b30b376558adbc300ce4586f894e2e2af75dac933bc621c5401e2f7cf1eff
7
- data.tar.gz: 0cd9ec1e44e68aeae47dbc86f95e18f1402831579b94d942c6ed4e9b264eab2b1f698bbe776616f962b4f6f28b4fe0fedb1e8e6d37aeb4b5be376425cd7d795d
6
+ metadata.gz: b9c4b32a75d4bbefe63e2cb4e54d2e221d110a152014b7150c124950c8a457da8059ab5ed87a0bbe2a7e0d754914abad0457745366a4060b62878284e95076b6
7
+ data.tar.gz: aa0a5810de6e1b1eb19a611061b310e093f57179261c3eff3f8e6a8830cb03ef47f5ce22800f2a9a3653a1867842d12786a1d805ee3d3e26e856c5e85d753574
@@ -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
@@ -1,4 +1,4 @@
1
- require:
1
+ plugins:
2
2
  - rubocop-capybara
3
3
  - rubocop-rails
4
4
  - rubocop-rspec
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
@@ -1,5 +1,7 @@
1
1
  # Place any default configuration for solr_wrapper here
2
2
  # port: 8983
3
+ env:
4
+ SOLR_MODULES: analysis-extras
3
5
  collection:
4
- dir: lib/generators/blacklight/templates/solr/conf
6
+ dir: lib/generators/blacklight/templates/solr/
5
7
  name: blacklight-core
data/VERSION CHANGED
@@ -1 +1 @@
1
- 7.40.0
1
+ 7.42.0
@@ -60,9 +60,7 @@ module Blacklight
60
60
  end
61
61
  end
62
62
 
63
- def key
64
- @action.key
65
- end
63
+ delegate :key, to: :@action
66
64
  end
67
65
  end
68
66
  end
@@ -0,0 +1,10 @@
1
+ <div class='pagination-search-widgets'>
2
+
3
+ <div class="page-links">
4
+ <%= link_to_previous_document %> |
5
+
6
+ <%= item_page_entry_info %> |
7
+
8
+ <%= link_to_next_document %>
9
+ </div>
10
+ </div>
@@ -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 || (Deprecation.silence(Blacklight::SearchFields) { search_field_list.first })
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::SearchContextComponent methods instead'
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::SearchContextComponent'
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::SearchContextComponent'
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
@@ -12,9 +12,7 @@ module Blacklight
12
12
 
13
13
  attr_reader :blacklight_config
14
14
 
15
- def documents
16
- @response.documents
17
- end
15
+ delegate :documents, to: :@response
18
16
 
19
17
  # @return [Array<Blacklight::Solr::Response::Facets::FacetField>]
20
18
  def search_facets
@@ -1,2 +1,2 @@
1
- <% Deprecation.warn(self, 'The partial _previous_next_doc.html.erb will be removed in 8.0. Render Blacklight::SearchContextComponent instead.') %>
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', '< 7.3'
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
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ pin_all_from File.expand_path("../app/javascript/blacklight", __dir__), under: "blacklight"
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 ||= self.field
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 &&= self.field.to_s
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 self.field.nil?
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 self.key.respond_to?(:titleize)
47
- self.key.titleize
46
+ if key.respond_to?(:titleize)
47
+ key.titleize
48
48
  else
49
- self.key.to_s.titleize
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 ||= self.field
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 self.sort.nil?
18
+ raise ArgumentError.new, "Must supply a sort string" if sort.nil?
19
19
  end
20
20
  end
21
21
  end
@@ -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
- if Rails.application.config.respond_to?(:assets)
46
- Rails.application.config.assets.precompile += PRECOMPILE_ASSETS
47
- end
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
@@ -120,7 +120,7 @@ module Blacklight
120
120
 
121
121
  def set_default_proc!
122
122
  self.default_proc = lambda do |hash, key|
123
- hash[key] = nested_class.new(key: key)
123
+ hash[key] = nested_class.new({ key: key })
124
124
  end
125
125
  end
126
126
  end
@@ -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