blacklight 7.39.0 → 7.40.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3f22fe88564a62b7817f8f70d715f3bb41c52e742e397a5276e7b6adb5fd82c4
4
- data.tar.gz: 556f88d174f56f549955b8d505446f2ee06f75738bac240ba69658bea52f40d0
3
+ metadata.gz: 4e1a5889b0f9dee50b64165ffe292482619e54780bac24b14af00b3b1cba2fdd
4
+ data.tar.gz: 0ed718e93da4bca43bb242e5a97c6ced3546aa8ec9f17d18ce00a444dca95d93
5
5
  SHA512:
6
- metadata.gz: ad3e2e137494e604fe6253a78bf960c6a933c3c6d863bb3c873eec700a91a25743a9e348b61f8bfdc4f446864318e11fd7a79bcd158b89f56ce285276f97cf11
7
- data.tar.gz: 0bba87c8470d46409e7483d52bd33ca013b17ee8090ee0c68e38827afbcd3664acd1ca14f98b547c213ffadf1d8ead1514b0ac2316bddf007c50afd603777ad5
6
+ metadata.gz: ee5a1dc4ddb014510defa98a6c36a3d0e3ef9913c5cce5195878c688d062f7b95e3b30b376558adbc300ce4586f894e2e2af75dac933bc621c5401e2f7cf1eff
7
+ data.tar.gz: 0cd9ec1e44e68aeae47dbc86f95e18f1402831579b94d942c6ed4e9b264eab2b1f698bbe776616f962b4f6f28b4fe0fedb1e8e6d37aeb4b5be376425cd7d795d
data/.env CHANGED
@@ -1,6 +1,6 @@
1
1
  ALPINE_RUBY_VERSION=3.2.2
2
2
  RAILS_VERSION=7.0.8
3
- VIEW_COMPONENT_VERSION=2.66.0
3
+ VIEW_COMPONENT_VERSION=2.74.0
4
4
  SOLR_PORT=8983
5
5
  SOLR_URL=http://solr:8983/solr/blacklight-core
6
6
  SOLR_VERSION=latest
@@ -109,14 +109,14 @@ jobs:
109
109
  run: bundle exec rake ci
110
110
  env:
111
111
  ENGINE_CART_RAILS_OPTIONS: '--skip-keeps --skip-test'
112
- test_vc3:
112
+ test_vc2:
113
113
  runs-on: ubuntu-latest
114
114
  strategy:
115
115
  matrix:
116
116
  ruby: ['3.2']
117
117
  env:
118
118
  RAILS_VERSION: 7.0.8
119
- VIEW_COMPONENT_VERSION: ${{ matrix.view_component_version }}
119
+ VIEW_COMPONENT_VERSION: "~> 2.74"
120
120
  steps:
121
121
  - uses: actions/checkout@v2
122
122
  - name: Set up Ruby
data/.rubocop.yml CHANGED
@@ -42,6 +42,7 @@ Metrics/ClassLength:
42
42
  - "lib/blacklight/search_builder.rb"
43
43
  - "lib/blacklight/search_state.rb"
44
44
  - "lib/blacklight/search_state/filter_field.rb"
45
+ - "app/presenters/blacklight/document_presenter.rb"
45
46
 
46
47
  Layout/LineLength:
47
48
  Max: 200
data/VERSION CHANGED
@@ -1 +1 @@
1
- 7.39.0
1
+ 7.40.0
@@ -11,18 +11,26 @@ module Blacklight
11
11
  # @param [SolrDocument] document
12
12
  # @param [ActionView::Base] view_context scope for linking and generating urls
13
13
  # @param [Blacklight::Configuration] configuration
14
- def initialize(document, view_context, configuration = view_context.blacklight_config)
14
+ def initialize(document, view_context, configuration = view_context.blacklight_config, view_config: nil, field_presenter_options: {})
15
15
  @document = document
16
16
  @view_context = view_context
17
17
  @configuration = configuration
18
+ @view_config = view_config
19
+ @field_presenter_options = field_presenter_options
18
20
  end
19
21
 
20
22
  # @return [Hash<String,Configuration::Field>] all the fields for this index view that should be rendered
21
- def fields_to_render
22
- return to_enum(:fields_to_render) unless block_given?
23
+ def fields_to_render(document_fields = fields, **kwargs)
24
+ unless block_given?
25
+ return to_enum(:fields_to_render, document_fields, **kwargs) unless method(:fields_to_render).arity.zero?
23
26
 
24
- fields.each do |name, field_config|
25
- field_presenter = field_presenter(field_config)
27
+ Deprecation.warn(self.class, 'In Blacklight 8, Blacklight::DocumentPresenter#fields_to_render accepts additional arguments')
28
+
29
+ return to_enum(:fields_to_render)
30
+ end
31
+
32
+ document_fields.each do |name, field_config|
33
+ field_presenter = field_presenter(field_config, kwargs)
26
34
 
27
35
  next unless field_presenter.render_field? && field_presenter.any?
28
36
 
@@ -30,10 +38,21 @@ module Blacklight
30
38
  end
31
39
  end
32
40
 
33
- def field_presenters
34
- return to_enum(:field_presenters) unless block_given?
41
+ def field_presenters(document_fields = fields, **kwargs)
42
+ unless block_given?
43
+ return to_enum(:field_presenters, document_fields, **kwargs) unless method(:field_presenters).arity.zero?
44
+
45
+ Deprecation.warn(self.class, 'In Blacklight 8, Blacklight::DocumentPresenter#field_presenters accepts additional arguments')
35
46
 
36
- fields_to_render.each { |_, _, config| yield config }
47
+ return to_enum(:field_presenters)
48
+ end
49
+
50
+ if method(:fields_to_render).arity.zero?
51
+ Deprecation.warn(self.class, 'In Blacklight 8, Blacklight::DocumentPresenter#fields_to_render accept additional arguments')
52
+ fields_to_render.each { |_, _, config| yield config }
53
+ else
54
+ fields_to_render(document_fields, **kwargs).each { |_, _, config| yield config }
55
+ end
37
56
  end
38
57
 
39
58
  ##
@@ -122,7 +141,7 @@ module Blacklight
122
141
  end
123
142
 
124
143
  def show_view_config
125
- configuration.view_config(:show)
144
+ configuration.view_config(:show, action_name: view_context.action_name)
126
145
  end
127
146
 
128
147
  def inspect
@@ -158,7 +177,7 @@ module Blacklight
158
177
  end
159
178
 
160
179
  def field_presenter_options
161
- {}
180
+ @field_presenter_options ||= {}
162
181
  end
163
182
  end
164
183
  end
@@ -30,7 +30,7 @@ module Blacklight
30
30
  deprecation_deprecate label: 'Use #heading'
31
31
 
32
32
  def view_config
33
- @view_config ||= configuration.view_config(view_context.document_index_view_type)
33
+ @view_config ||= configuration.view_config(view_context.document_index_view_type, action_name: view_context.action_name)
34
34
  end
35
35
 
36
36
  private
data/blacklight.gemspec CHANGED
@@ -32,7 +32,7 @@ Gem::Specification.new do |s|
32
32
  s.add_dependency "deprecation"
33
33
  s.add_dependency "i18n", '>= 1.7.0' # added named parameters
34
34
  s.add_dependency "ostruct", '>= 0.3.2'
35
- s.add_dependency "view_component", '>= 2.66', '< 4'
35
+ s.add_dependency "view_component", '>= 2.74', '< 4'
36
36
  s.add_dependency 'hashdiff'
37
37
  s.add_dependency "zeitwerk"
38
38
 
@@ -3,57 +3,20 @@
3
3
  module Blacklight
4
4
  class Component < ViewComponent::Base
5
5
  class << self
6
- # Workaround for https://github.com/ViewComponent/view_component/issues/1565
7
- def config
8
- @config ||= ViewComponent::Config.defaults.merge(ViewComponent::Base.config)
9
- end
6
+ alias upstream_sidecar_files sidecar_files
10
7
 
11
- # rubocop:disable Naming/MemoizedInstanceVariableName
12
- def compiler
13
- @__vc_compiler ||= EngineCompiler.new(self)
8
+ def reset_compiler!
9
+ @__vc_compiler = nil
14
10
  end
15
- # rubocop:enable Naming/MemoizedInstanceVariableName
16
-
17
- alias sidecar_files _sidecar_files unless ViewComponent::Base.respond_to? :sidecar_files
18
- end
19
-
20
- EXCLUDE_VARIABLES = [
21
- :@lookup_context, :@view_renderer, :@view_flow, :@view_context,
22
- :@tag_builder, :@current_template,
23
- :@__vc_set_slots, :@__vc_original_view_context,
24
- :@__vc_variant, :@__vc_content_evaluated,
25
- :@__vc_render_in_block, :@__vc_content, :@__vc_helpers
26
- ].freeze
27
-
28
- def inspect
29
- # Exclude variables added by render_in
30
- render_variables = instance_variables - EXCLUDE_VARIABLES
31
- fields = render_variables.map { |ivar| "#{ivar}:#{instance_variable_get(ivar).inspect}" }.join(', ')
32
- "#<#{self.class.name}:#{object_id} #{fields}>"
33
- end
34
-
35
- class EngineCompiler < ::ViewComponent::Compiler
36
- # ViewComponent::Compiler locates and caches templates from sidecar files to the component source file.
37
- # While this is sensible in a Rails application, it prevents component templates defined in an Engine
38
- # from being overridden by an installing application without subclassing the component, which may also
39
- # require modifying any partials rendering the component. This subclass of compiler overrides the template
40
- # location algorithm to take the sidecar file names from the Engine, but look to see if a file of the
41
- # same name existing in the installing application (ie, under Rails.root). If the latter exists, this
42
- # compiler will cache that template instead of the engine-defined file; if not, the compiler will fall
43
- # back to the engine-defined file.
44
- def templates
45
- @templates ||= begin
46
- extensions = ActionView::Template.template_handler_extensions
47
11
 
48
- component_class.sidecar_files(extensions).each_with_object([]) do |path, memo|
49
- pieces = File.basename(path).split(".")
50
- app_path = "#{Rails.root}/#{path.slice(path.index(component_class.view_component_path)..-1)}"
12
+ def sidecar_files(*args, **kwargs)
13
+ upstream_sidecar_files(*args, **kwargs).map do |path|
14
+ app_path = Rails.root.join(path.slice(path.index(view_component_path)..-1).to_s).to_s
51
15
 
52
- memo << {
53
- path: File.exist?(app_path) ? app_path : path,
54
- variant: pieces.second.split("+").second&.to_sym,
55
- handler: pieces.last
56
- }
16
+ if File.exist?(app_path)
17
+ app_path
18
+ else
19
+ path
57
20
  end
58
21
  end
59
22
  end
data/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "blacklight-frontend",
3
- "version": "7.39.0",
3
+ "version": "7.40.0",
4
4
  "description": "The frontend code and styles for Blacklight",
5
5
  "main": "app/assets/javascripts/blacklight",
6
6
  "scripts": {
@@ -1,43 +1,48 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- RSpec.describe Blacklight::Component do
4
- let(:component_class) { Blacklight::DocumentTitleComponent }
3
+ RSpec.describe Blacklight::Component, type: :component do
4
+ let(:component_class) { Blacklight::System::ModalComponent }
5
5
 
6
- context "subclassed" do
7
- it "returns our Compiler implementation" do
8
- expect(component_class.ancestors).to include described_class
9
- expect(component_class.compiler).to be_a Blacklight::Component::EngineCompiler
6
+ before do
7
+ component_class.reset_compiler!
8
+ ViewComponent::CompileCache.invalidate!
9
+
10
+ component_class.class_eval do
11
+ undef :call if method_defined?(:call)
10
12
  end
11
13
  end
12
14
 
13
- describe Blacklight::Component::EngineCompiler do
14
- subject(:compiler) { described_class.new(component_class) }
15
+ after do
16
+ component_class.reset_compiler!
17
+ ViewComponent::CompileCache.invalidate!
15
18
 
16
- let(:original_compiler) { ViewComponent::Compiler.new(component_class) }
17
- let(:original_path) { original_compiler.send(:templates).first[:path] }
18
- let(:resolved_path) { compiler.templates.first[:path] }
19
+ component_class.class_eval do
20
+ undef :call if method_defined?(:call)
21
+ end
22
+ end
19
23
 
20
- context "without overrides" do
21
- it "links to engine template" do
22
- expect(resolved_path).not_to include(".internal_test_app")
23
- expect(resolved_path).to eql(original_path)
24
- end
24
+ context "without overrides" do
25
+ it "renders the engine template" do
26
+ render_inline(component_class.new)
27
+ expect(page).to have_css('.modal-header')
25
28
  end
29
+ end
26
30
 
27
- context "with overrides" do
28
- let(:path_match) do
29
- Regexp.new(Regexp.escape(File.join(".internal_test_app", component_class.view_component_path)))
31
+ context "with overrides" do
32
+ around do |ex|
33
+ FileUtils.mkdir_p(Rails.root.join('app/components/blacklight/system'))
34
+ Rails.root.join("app/components/blacklight/system/modal_component.html.erb").open("w") do |f|
35
+ f.puts '<div class="custom-modal">Overridden</div>'
30
36
  end
31
37
 
32
- before do
33
- allow(File).to receive(:exist?).and_call_original
34
- allow(File).to receive(:exist?).with(path_match).and_return(true)
35
- end
38
+ ex.run
39
+ ensure
40
+ Rails.root.join('app/components/blacklight/system/modal_component.html.erb').unlink
41
+ end
36
42
 
37
- it "links to application template" do
38
- expect(resolved_path).to include(".internal_test_app")
39
- expect(resolved_path).not_to eql(original_path)
40
- end
43
+ it "renders to application template" do
44
+ render_inline(component_class.new)
45
+ expect(page).to have_css('.custom-modal')
41
46
  end
42
47
  end
43
48
  end
@@ -12,6 +12,7 @@ RSpec.describe Blacklight::DocumentPresenter do
12
12
 
13
13
  before do
14
14
  allow(request_context).to receive(:search_state).and_return(search_state)
15
+ allow(request_context).to receive(:action_name).and_return(:show)
15
16
  end
16
17
 
17
18
  describe '#fields_to_render' do
@@ -22,6 +22,7 @@ RSpec.describe Blacklight::IndexPresenter, api: true do
22
22
 
23
23
  before do
24
24
  allow(request_context).to receive(:search_state).and_return(search_state)
25
+ allow(request_context).to receive(:action_name).and_return(:index)
25
26
  end
26
27
 
27
28
  describe '#fields' do
@@ -22,6 +22,7 @@ RSpec.describe Blacklight::ShowPresenter, api: true do
22
22
 
23
23
  before do
24
24
  allow(request_context).to receive(:search_state).and_return(search_state)
25
+ allow(request_context).to receive(:action_name).and_return(:show)
25
26
  end
26
27
 
27
28
  describe "link_rel_alternates" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: blacklight
3
3
  version: !ruby/object:Gem::Version
4
- version: 7.39.0
4
+ version: 7.40.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonathan Rochkind
@@ -17,7 +17,7 @@ authors:
17
17
  autorequire:
18
18
  bindir: exe
19
19
  cert_chain: []
20
- date: 2024-09-26 00:00:00.000000000 Z
20
+ date: 2024-10-25 00:00:00.000000000 Z
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency
23
23
  name: rails
@@ -129,7 +129,7 @@ dependencies:
129
129
  requirements:
130
130
  - - ">="
131
131
  - !ruby/object:Gem::Version
132
- version: '2.66'
132
+ version: '2.74'
133
133
  - - "<"
134
134
  - !ruby/object:Gem::Version
135
135
  version: '4'
@@ -139,7 +139,7 @@ dependencies:
139
139
  requirements:
140
140
  - - ">="
141
141
  - !ruby/object:Gem::Version
142
- version: '2.66'
142
+ version: '2.74'
143
143
  - - "<"
144
144
  - !ruby/object:Gem::Version
145
145
  version: '4'