blacklight 7.3.0 → 7.4.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 (41) hide show
  1. checksums.yaml +4 -4
  2. data/VERSION +1 -1
  3. data/app/helpers/blacklight/blacklight_helper_behavior.rb +2 -1
  4. data/app/helpers/blacklight/catalog_helper_behavior.rb +2 -3
  5. data/app/helpers/blacklight/configuration_helper_behavior.rb +3 -2
  6. data/app/helpers/blacklight/layout_helper_behavior.rb +7 -0
  7. data/app/helpers/blacklight/render_partials_helper_behavior.rb +1 -9
  8. data/app/helpers/blacklight/url_helper_behavior.rb +2 -2
  9. data/app/presenters/blacklight/document_presenter.rb +74 -4
  10. data/app/presenters/blacklight/field_presenter.rb +22 -11
  11. data/app/presenters/blacklight/index_presenter.rb +9 -50
  12. data/app/presenters/blacklight/show_presenter.rb +6 -53
  13. data/app/presenters/blacklight/thumbnail_presenter.rb +14 -4
  14. data/app/services/blacklight/field_retriever.rb +7 -1
  15. data/app/views/catalog/_document.atom.builder +1 -1
  16. data/app/views/catalog/_document.rss.builder +2 -2
  17. data/app/views/catalog/_facet_layout.html.erb +3 -3
  18. data/app/views/catalog/_opensearch_response_metadata.html.erb +3 -3
  19. data/app/views/catalog/_search_results.html.erb +1 -1
  20. data/app/views/catalog/index.json.jbuilder +2 -3
  21. data/app/views/catalog/show.json.jbuilder +3 -3
  22. data/app/views/layouts/blacklight/base.html.erb +2 -2
  23. data/config/i18n-tasks.yml +1 -1
  24. data/config/locales/blacklight.ar.yml +250 -0
  25. data/config/locales/blacklight.hu.yml +8 -0
  26. data/config/locales/blacklight.nl.yml +8 -0
  27. data/config/locales/blacklight.sq.yml +9 -0
  28. data/config/locales/blacklight.zh.yml +8 -0
  29. data/lib/blacklight/configuration.rb +16 -4
  30. data/spec/features/search_spec.rb +5 -0
  31. data/spec/helpers/blacklight/configuration_helper_behavior_spec.rb +4 -0
  32. data/spec/helpers/blacklight/layout_helper_behavior_spec.rb +10 -0
  33. data/spec/helpers/blacklight/url_helper_behavior_spec.rb +5 -5
  34. data/spec/helpers/catalog_helper_spec.rb +9 -0
  35. data/spec/models/blacklight/configuration_spec.rb +32 -10
  36. data/spec/presenters/blacklight/document_presenter_spec.rb +9 -14
  37. data/spec/presenters/blacklight/show_presenter_spec.rb +23 -6
  38. data/spec/presenters/thumbnail_presenter_spec.rb +1 -2
  39. data/spec/views/catalog/_facet_layout.html.erb_spec.rb +3 -2
  40. data/spec/views/catalog/index.html.erb_spec.rb +1 -1
  41. metadata +3 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 958a6b0c5bfc8cfdd7fa31fe600d5bc77219f389b850453ade7a7a7aef6f8229
4
- data.tar.gz: f6a49835143c4126550be6f937e7328e002e2c63f20dcb36adfa77150d6e60a0
3
+ metadata.gz: 05d5576219e73622cf05af970590c5492d1e7f18a2b1a3654fb26de71d424b64
4
+ data.tar.gz: 94a2e2b0b64d07b4fe0083df1e7658130c6d9dfba7c3acae4ee5b930a1ceb74c
5
5
  SHA512:
6
- metadata.gz: fce42f491e0dd73fc1f0f71d051d0afc8c324ac07b4fbaf9f0d728e0bdb0bde657000ef044e48b28fad008015b29c4dc0e73c47671677ae37cf2e38a06137741
7
- data.tar.gz: eb4d53904c2d1a309aef41fbcb166c18fabde6d0a8eaf8851df1032c783ea4b34af8115ffb91464f9aaed907078f42cacb644d12770f14fc301e9c008c3e4648
6
+ metadata.gz: 9d8fbf65bfad8b2d4dfac62bb3048dfdebca06f4752b6b66bfbfce218afa1b5deef6b7865896056760c1f7265e7d5968ffa3d52511ce49d54004a118191261b9
7
+ data.tar.gz: f1921d4f36915aa5761788ae8a80ddb1836777c2a6db8613d01987930af30ac8d2a273ccea62ecdbcb502c3716747a4ea551a64cc02b3cda7e1ade71067ddbb2
data/VERSION CHANGED
@@ -1 +1 @@
1
- 7.3.0
1
+ 7.4.0
@@ -50,8 +50,9 @@ module Blacklight::BlacklightHelperBehavior
50
50
  # Render OpenSearch headers for this search
51
51
  # @return [String]
52
52
  def render_opensearch_response_metadata
53
- render partial: 'catalog/opensearch_response_metadata'
53
+ render partial: 'catalog/opensearch_response_metadata', locals: { response: @response }
54
54
  end
55
+ deprecation_deprecate render_opensearch_response_metadata: 'Use `render "catalog/opensearch_response_metadata"\' instead'
55
56
 
56
57
  ##
57
58
  # Render classes for the <body> element
@@ -45,7 +45,7 @@ module Blacklight::CatalogHelperBehavior
45
45
  entry_name = if entry_name
46
46
  entry_name.pluralize(collection.size, I18n.locale)
47
47
  else
48
- collection.entry_name(count: collection.size).downcase
48
+ collection.entry_name(count: collection.size).to_s.downcase
49
49
  end
50
50
 
51
51
  entry_name = entry_name.pluralize unless collection.total_count == 1
@@ -134,8 +134,7 @@ module Blacklight::CatalogHelperBehavior
134
134
  #
135
135
  # @return [String]
136
136
  def render_document_class(document = @document)
137
- types = document[blacklight_config.view_config(document_index_view_type).display_type_field]
138
-
137
+ types = presenter(document).display_type
139
138
  return if types.blank?
140
139
 
141
140
  Array(types).compact.map do |t|
@@ -55,7 +55,7 @@ module Blacklight::ConfigurationHelperBehavior
55
55
  ##
56
56
  # Look up the label for the index field
57
57
  def index_field_label document, field
58
- field_config = blacklight_config.index_fields_for(document)[field]
58
+ field_config = blacklight_config.index_fields_for(index_presenter(document).display_type)[field]
59
59
  field_config ||= Blacklight::Configuration::NullField.new(key: field)
60
60
 
61
61
  field_config.display_label('index')
@@ -64,7 +64,7 @@ module Blacklight::ConfigurationHelperBehavior
64
64
  ##
65
65
  # Look up the label for the show field
66
66
  def document_show_field_label document, field
67
- field_config = blacklight_config.show_fields_for(document)[field]
67
+ field_config = blacklight_config.show_fields_for(show_presenter(document).display_type)[field]
68
68
  field_config ||= Blacklight::Configuration::NullField.new(key: field)
69
69
 
70
70
  field_config.display_label('show')
@@ -166,6 +166,7 @@ module Blacklight::ConfigurationHelperBehavior
166
166
 
167
167
  field
168
168
  end
169
+ deprecation_deprecate document_show_link_field: 'Deprecated without replacement'
169
170
 
170
171
  ##
171
172
  # Default sort field
@@ -11,6 +11,13 @@ module Blacklight
11
11
  "#{main_content_classes} show-document"
12
12
  end
13
13
 
14
+ ##
15
+ # Attributes to add to the <html> tag (e.g. lang and dir)
16
+ # @return [Hash]
17
+ def html_tag_attributes
18
+ { lang: I18n.locale }
19
+ end
20
+
14
21
  ##
15
22
  # Classes added to a document's sidebar div
16
23
  # @return [String]
@@ -115,15 +115,7 @@ module Blacklight::RenderPartialsHelperBehavior
115
115
  # @param [Symbol] base_name base name for the partial
116
116
  # @return [String]
117
117
  def document_partial_name(document, base_name = nil)
118
- view_config = blacklight_config.view_config(:show)
119
-
120
- display_type = if base_name && view_config.key?(:"#{base_name}_display_type_field")
121
- document[view_config[:"#{base_name}_display_type_field"]]
122
- end
123
-
124
- display_type ||= document[view_config.display_type_field]
125
-
126
- display_type ||= 'default'
118
+ display_type = show_presenter(document).display_type(base_name, default: 'default')
127
119
 
128
120
  type_field_to_partial_name(document, display_type)
129
121
  end
@@ -21,10 +21,10 @@ module Blacklight::UrlHelperBehavior
21
21
  def link_to_document(doc, field_or_opts = nil, opts = { counter: nil })
22
22
  label = case field_or_opts
23
23
  when NilClass
24
- index_presenter(doc).label document_show_link_field(doc), opts
24
+ index_presenter(doc).heading
25
25
  when Hash
26
26
  opts = field_or_opts
27
- index_presenter(doc).label document_show_link_field(doc), opts
27
+ index_presenter(doc).heading
28
28
  when Proc, Symbol
29
29
  Deprecation.warn(self, "passing a #{field_or_opts.class} to link_to_document is deprecated and will be removed in Blacklight 8")
30
30
  Deprecation.silence(Blacklight::IndexPresenter) do
@@ -5,6 +5,18 @@ module Blacklight
5
5
  class DocumentPresenter
6
6
  attr_reader :document, :configuration, :view_context
7
7
 
8
+ class_attribute :thumbnail_presenter
9
+ self.thumbnail_presenter = ThumbnailPresenter
10
+
11
+ # @param [SolrDocument] document
12
+ # @param [ActionView::Base] view_context scope for linking and generating urls
13
+ # @param [Blacklight::Configuration] configuration
14
+ def initialize(document, view_context, configuration = view_context.blacklight_config)
15
+ @document = document
16
+ @view_context = view_context
17
+ @configuration = configuration
18
+ end
19
+
8
20
  # @return [Hash<String,Configuration::Field>] all the fields for this index view that should be rendered
9
21
  def fields_to_render
10
22
  fields.select do |_name, field_config|
@@ -14,6 +26,46 @@ module Blacklight
14
26
  end
15
27
  end
16
28
 
29
+ ##
30
+ # Get the value of the document's "title" field, or a placeholder
31
+ # value (if empty)
32
+ #
33
+ # @return [String]
34
+ def heading
35
+ return field_values(view_config.title_field) if view_config.title_field.is_a? Blacklight::Configuration::Field
36
+
37
+ fields = Array.wrap(view_config.title_field) + [configuration.document_model.unique_key]
38
+ f = fields.lazy.map { |field| field_config(field) }.detect { |field_config| retrieve_values(field_config).any? }
39
+ field_values(f, except_operations: [Rendering::HelperMethod])
40
+ end
41
+
42
+ def display_type(base_name = nil, default: nil)
43
+ fields = []
44
+ fields += Array.wrap(view_config[:"#{base_name}_display_type_field"]) if base_name && view_config.key?(:"#{base_name}_display_type_field")
45
+ fields += Array.wrap(view_config.display_type_field)
46
+
47
+ display_type = fields.lazy.map { |field| retrieve_values(field_config(field)) }.detect(&:any?)
48
+ display_type ||= Array(default) if default
49
+
50
+ display_type
51
+ end
52
+
53
+ ##
54
+ # Render the field label for a document
55
+ #
56
+ # Allow an extention point where information in the document
57
+ # may drive the value of the field
58
+ # @param [Configuration::Field] field
59
+ # @param [Hash] options
60
+ # @option options [String] :value
61
+ def field_value field, options = {}
62
+ field_values(field, options)
63
+ end
64
+
65
+ def thumbnail
66
+ @thumbnail ||= thumbnail_presenter.new(document, view_context, view_config)
67
+ end
68
+
17
69
  private
18
70
 
19
71
  ##
@@ -29,10 +81,28 @@ module Blacklight
29
81
  # the given solr field
30
82
  # @param [Blacklight::Configuration::Field] field_config
31
83
  # @return [Boolean]
32
- def has_value? field_config
33
- document.has?(field_config.field) ||
34
- (document.has_highlight_field? field_config.field if field_config.highlight) ||
35
- field_config.accessor
84
+ def has_value?(field_config)
85
+ retrieve_values(field_config).present?
86
+ end
87
+
88
+ ##
89
+ # Get the value for a document's field, and prepare to render it.
90
+ # - highlight_field
91
+ # - accessor
92
+ # - solr field
93
+ #
94
+ # Rendering:
95
+ # - helper_method
96
+ # - link_to_facet
97
+ # @param [Blacklight::Configuration::Field] field_config solr field configuration
98
+ # @param [Hash] options additional options to pass to the rendering helpers
99
+ def field_values(field_config, options = {})
100
+ options[:values] ||= retrieve_values(field_config) unless options.key? :value
101
+ FieldPresenter.new(view_context, document, field_config, options).render
102
+ end
103
+
104
+ def retrieve_values(field_config)
105
+ FieldRetriever.new(document, field_config).fetch
36
106
  end
37
107
  end
38
108
  end
@@ -7,29 +7,40 @@ module Blacklight
7
7
  # @param document [SolrDocument] the document
8
8
  # @param field_config [Blacklight::Configuration::Field] the field's configuration
9
9
  # @param options [Hash]
10
- # @option options [Object] :value when this is provided, we don't want the pipeline to deal with helper methods.
11
- # this happens when drawing the label for the document
12
- def initialize(controller, document, field_config, options)
10
+ # @option options [Object] :values
11
+ # @option options [Array] :except_operations
12
+ # @option options [Object] :value
13
+ # @option options [Array] :steps
14
+ def initialize(controller, document, field_config, options = {})
13
15
  @controller = controller
14
16
  @document = document
15
17
  @field_config = field_config
16
18
  @options = options
19
+
20
+ @values = if options.key?(:value)
21
+ Array.wrap(options[:value])
22
+ else
23
+ options[:values]
24
+ end
25
+
26
+ @except_operations = options[:except_operations] || []
27
+ # Implicitly prevent helper methods from drawing when drawing the label for the document
28
+ @except_operations += [Rendering::HelperMethod] if options.key? :value
17
29
  end
18
30
 
19
- attr_reader :controller, :document, :field_config, :options
31
+ attr_reader :controller, :document, :field_config, :values, :except_operations, :options
20
32
 
21
33
  def render
22
- return Rendering::Pipeline.render(retrieve_values, field_config, document, controller, options) unless options[:value]
23
-
24
- values = Array.wrap(options[:value])
25
- # Prevents helper methods from drawing.
26
- steps = Rendering::Pipeline.operations - [Rendering::HelperMethod]
27
- Rendering::Pipeline.new(values, field_config, document, controller, steps, options).render
34
+ Rendering::Pipeline.new(values || retrieve_values, field_config, document, controller, pipeline_steps, options).render
28
35
  end
29
36
 
30
37
  private
31
38
 
32
- def retrieve_values
39
+ def pipeline_steps
40
+ (options[:steps] || Rendering::Pipeline.operations) - except_operations
41
+ end
42
+
43
+ def retrieve_values(field_config)
33
44
  FieldRetriever.new(document, field_config).fetch
34
45
  end
35
46
  end
@@ -1,34 +1,18 @@
1
1
  # frozen_string_literal: true
2
2
  module Blacklight
3
3
  class IndexPresenter < DocumentPresenter
4
- class_attribute :thumbnail_presenter
5
- self.thumbnail_presenter = ThumbnailPresenter
6
-
7
- attr_reader :view_config
8
-
9
- # @param [SolrDocument] document
10
- # @param [ActionView::Base] view_context scope for linking and generating urls
11
- # @param [Blacklight::Configuration] configuration
12
- def initialize(document, view_context, configuration = view_context.blacklight_config)
13
- @document = document
14
- @view_context = view_context
15
- @configuration = configuration
16
- @view_config = configuration.view_config(view_context.document_index_view_type)
17
- end
18
-
19
4
  ##
20
5
  # Render the document index heading. This is used when making a link to a
21
6
  # document, where we don't want any HTML markup added from the pipeline.
22
7
  #
23
8
  # @param [Symbol, Proc, String] field_or_string_or_proc Render the given field or evaluate the proc or render the given string
24
9
  # @param [Hash] opts
25
- # TODO: the default field should be `document_show_link_field(doc)'
26
10
  def label(field_or_string_or_proc, opts = {})
27
11
  config = Configuration::NullField.new
28
12
  value = case field_or_string_or_proc
29
13
  when Symbol
30
14
  config = field_config(field_or_string_or_proc)
31
- document[field_or_string_or_proc]
15
+ retrieve_values(config)
32
16
  when Proc
33
17
  Deprecation.warn(self, "calling IndexPresenter.label with a Proc is deprecated. " \
34
18
  "First argument must be a symbol. This will be removed in Blacklight 8")
@@ -39,46 +23,21 @@ module Blacklight
39
23
  field_or_string_or_proc
40
24
  end
41
25
 
42
- value ||= document.id
43
- field_values(config, value: value)
26
+ value = document.id if value.blank?
27
+ field_values(config, values: Array.wrap(value), except_operations: [Rendering::HelperMethod])
44
28
  end
45
29
 
46
- ##
47
- # Render the index field label for a document
48
- #
49
- # Allow an extention point where information in the document
50
- # may drive the value of the field
51
- # @param [Configuration::Field] field
52
- # @param [Hash] options
53
- # @option options [String] :value
54
- def field_value field, options = {}
55
- field_values(field, options)
56
- end
57
-
58
- def thumbnail
59
- @thumbnail ||= thumbnail_presenter.new(document, view_context, view_config)
60
- end
30
+ deprecation_deprecate label: 'Use #heading'
61
31
 
62
32
  private
63
33
 
64
- # @return [Hash<String,Configuration::Field>] all the fields for this index view
65
- def fields
66
- configuration.index_fields_for(document)
34
+ def view_config
35
+ @view_config ||= configuration.view_config(view_context.document_index_view_type)
67
36
  end
68
37
 
69
- ##
70
- # Get the value for a document's field, and prepare to render it.
71
- # - highlight_field
72
- # - accessor
73
- # - solr field
74
- #
75
- # Rendering:
76
- # - helper_method
77
- # - link_to_facet
78
- # @param [Blacklight::Configuration::Field] field_config solr field configuration
79
- # @param [Hash] options additional options to pass to the rendering helpers
80
- def field_values(field_config, options = {})
81
- FieldPresenter.new(view_context, document, field_config, options).render
38
+ # @return [Hash<String,Configuration::Field>] all the fields for this index view
39
+ def fields
40
+ configuration.index_fields_for(display_type)
82
41
  end
83
42
 
84
43
  def field_config(field)
@@ -1,15 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
  module Blacklight
3
3
  class ShowPresenter < DocumentPresenter
4
- # @param [SolrDocument] document
5
- # @param [ActionView::Base] view_context scope for linking and generating urls
6
- # @param [Blacklight::Configuration] configuration
7
- def initialize(document, view_context, configuration = view_context.blacklight_config)
8
- @document = document
9
- @view_context = view_context
10
- @configuration = configuration
11
- end
12
-
13
4
  ##
14
5
  # Create <link rel="alternate"> links from a documents dynamically
15
6
  # provided export formats. Returns empty string if no links available.
@@ -29,60 +20,22 @@ module Blacklight
29
20
  # @see #document_heading
30
21
  # @return [String]
31
22
  def html_title
23
+ return field_values(view_config.html_title_field) if view_config.html_title_field.is_a? Blacklight::Configuration::Field
24
+
32
25
  if view_config.html_title_field
33
- fields = Array.wrap(view_config.html_title_field)
34
- f = fields.detect { |field| document.has? field }
35
- f ||= 'id'
36
- field_values(field_config(f))
26
+ fields = Array.wrap(view_config.html_title_field) + [configuration.document_model.unique_key]
27
+ f = fields.lazy.map { |field| field_config(field) }.detect { |field_config| retrieve_values(field_config).any? }
28
+ field_values(f)
37
29
  else
38
30
  heading
39
31
  end
40
32
  end
41
33
 
42
- ##
43
- # Get the value of the document's "title" field, or a placeholder
44
- # value (if empty)
45
- #
46
- # @return [String]
47
- def heading
48
- fields = Array.wrap(view_config.title_field)
49
- f = fields.detect { |field| document.has? field }
50
- f ||= configuration.document_model.unique_key
51
- field_values(field_config(f), value: document[f])
52
- end
53
-
54
- ##
55
- # Render the show field value for a document
56
- #
57
- # Allow an extention point where information in the document
58
- # may drive the value of the field
59
- # @param [Configuration::Field] field
60
- # @param [Hash] options
61
- # @option options [String] :value
62
- def field_value field, options = {}
63
- field_values(field, options)
64
- end
65
-
66
34
  private
67
35
 
68
36
  # @return [Hash<String,Configuration::Field>]
69
37
  def fields
70
- configuration.show_fields_for(document)
71
- end
72
-
73
- ##
74
- # Get the value for a document's field, and prepare to render it.
75
- # - highlight_field
76
- # - accessor
77
- # - solr field
78
- #
79
- # Rendering:
80
- # - helper_method
81
- # - link_to_facet
82
- # @param [Blacklight::Configuration::Field] field_config solr field configuration
83
- # @param [Hash] options additional options to pass to the rendering helpers
84
- def field_values(field_config, options = {})
85
- FieldPresenter.new(view_context, document, field_config, options).render
38
+ configuration.show_fields_for(display_type)
86
39
  end
87
40
 
88
41
  def view_config
@@ -20,7 +20,7 @@ module Blacklight
20
20
  # @return [Boolean]
21
21
  def exists?
22
22
  thumbnail_method.present? ||
23
- (thumbnail_field && thumbnail_value_from_document(document).present?) ||
23
+ (thumbnail_field && thumbnail_value_from_document.present?) ||
24
24
  default_thumbnail.present?
25
25
  end
26
26
 
@@ -47,7 +47,7 @@ module Blacklight
47
47
  value = if thumbnail_method
48
48
  view_context.send(thumbnail_method, document, image_options)
49
49
  elsif thumbnail_field
50
- image_url = thumbnail_value_from_document(document)
50
+ image_url = thumbnail_value_from_document
51
51
  view_context.image_tag image_url, image_options if image_url.present?
52
52
  end
53
53
 
@@ -67,8 +67,18 @@ module Blacklight
67
67
  end
68
68
  end
69
69
 
70
- def thumbnail_value_from_document(document)
71
- Array(thumbnail_field).lazy.map { |field| document.first(field) }.reject(&:blank?).first
70
+ def thumbnail_value_from_document
71
+ Array(thumbnail_field).lazy.map { |field| retrieve_values(field_config(field)).first }.reject(&:blank?).first
72
+ end
73
+
74
+ def retrieve_values(field_config)
75
+ FieldRetriever.new(document, field_config).fetch
76
+ end
77
+
78
+ def field_config(field)
79
+ return field if field.is_a? Blacklight::Configuration::Field
80
+
81
+ Configuration::NullField.new(field)
72
82
  end
73
83
  end
74
84
  end