blacklight 6.2.0 → 6.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (113) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +3 -0
  3. data/.solr_wrapper +5 -0
  4. data/.travis.yml +3 -5
  5. data/Gemfile +3 -3
  6. data/VERSION +1 -1
  7. data/app/assets/javascripts/blacklight/core.js +19 -5
  8. data/app/helpers/blacklight/blacklight_helper_behavior.rb +48 -20
  9. data/app/helpers/blacklight/configuration_helper_behavior.rb +1 -1
  10. data/app/helpers/blacklight/url_helper_behavior.rb +2 -1
  11. data/app/presenters/blacklight/document_presenter.rb +58 -150
  12. data/app/presenters/blacklight/field_presenter.rb +31 -0
  13. data/app/presenters/blacklight/index_presenter.rb +69 -0
  14. data/app/presenters/blacklight/link_alternate_presenter.rb +29 -0
  15. data/app/presenters/blacklight/rendering/abstract_step.rb +24 -0
  16. data/app/presenters/blacklight/rendering/helper_method.rb +23 -0
  17. data/app/presenters/blacklight/rendering/join.rb +16 -0
  18. data/app/presenters/blacklight/rendering/link_to_facet.rb +35 -0
  19. data/app/presenters/blacklight/rendering/microdata.rb +17 -0
  20. data/app/presenters/blacklight/rendering/pipeline.rb +32 -0
  21. data/app/presenters/blacklight/rendering/terminator.rb +9 -0
  22. data/app/presenters/blacklight/show_presenter.rb +93 -0
  23. data/app/services/blacklight/field_retriever.rb +58 -0
  24. data/app/views/catalog/_document_default.atom.builder +2 -3
  25. data/app/views/catalog/_document_default.rss.builder +2 -2
  26. data/app/views/kaminari/blacklight/_next_page.html.erb +9 -3
  27. data/app/views/kaminari/blacklight/_prev_page.html.erb +10 -3
  28. data/lib/blacklight/configuration.rb +15 -3
  29. data/lib/blacklight/configuration/null_field.rb +13 -0
  30. data/lib/blacklight/configuration/view_config.rb +6 -0
  31. data/lib/generators/blacklight/templates/catalog_controller.rb +1 -1
  32. data/lib/generators/blacklight/templates/config/blacklight.yml +1 -1
  33. data/lib/generators/blacklight/templates/config/jetty.yml +1 -1
  34. data/spec/controllers/alternate_controller_spec.rb +2 -2
  35. data/spec/controllers/application_controller_spec.rb +1 -1
  36. data/spec/controllers/blacklight/facet_spec.rb +3 -3
  37. data/spec/controllers/blacklight/search_fields_spec.rb +7 -7
  38. data/spec/controllers/blacklight/search_helper_spec.rb +44 -44
  39. data/spec/controllers/blacklight/suggest_search_spec.rb +1 -1
  40. data/spec/controllers/bookmarks_controller_spec.rb +6 -6
  41. data/spec/controllers/catalog_controller_spec.rb +125 -125
  42. data/spec/controllers/saved_searches_controller_spec.rb +4 -9
  43. data/spec/controllers/search_history_controller_spec.rb +3 -6
  44. data/spec/controllers/suggest_controller_spec.rb +2 -2
  45. data/spec/features/alternate_controller_spec.rb +3 -3
  46. data/spec/features/bookmarks_spec.rb +6 -6
  47. data/spec/features/did_you_mean_spec.rb +10 -10
  48. data/spec/features/facets_spec.rb +4 -4
  49. data/spec/features/record_view_spec.rb +4 -4
  50. data/spec/features/saved_searches_spec.rb +4 -4
  51. data/spec/features/search_context_spec.rb +4 -4
  52. data/spec/features/search_filters_spec.rb +10 -10
  53. data/spec/features/search_formats_spec.rb +2 -2
  54. data/spec/features/search_history_spec.rb +5 -5
  55. data/spec/features/search_pagination_spec.rb +4 -4
  56. data/spec/features/search_results_spec.rb +7 -7
  57. data/spec/features/search_sort_spec.rb +2 -2
  58. data/spec/features/search_spec.rb +6 -6
  59. data/spec/helpers/blacklight_helper_spec.rb +105 -65
  60. data/spec/helpers/catalog_helper_spec.rb +36 -36
  61. data/spec/helpers/configuration_helper_spec.rb +28 -28
  62. data/spec/helpers/facets_helper_spec.rb +39 -39
  63. data/spec/helpers/hash_as_hidden_fields_spec.rb +1 -1
  64. data/spec/helpers/render_constraints_helper_spec.rb +1 -1
  65. data/spec/helpers/search_history_constraints_helper_spec.rb +7 -7
  66. data/spec/helpers/url_helper_spec.rb +20 -17
  67. data/spec/lib/blacklight/search_state_spec.rb +2 -2
  68. data/spec/lib/blacklight/utils_spec.rb +15 -15
  69. data/spec/lib/blacklight_spec.rb +1 -1
  70. data/spec/lib/tasks/blacklight_task_spec.rb +1 -1
  71. data/spec/models/blacklight/configurable_spec.rb +3 -3
  72. data/spec/models/blacklight/configuration_spec.rb +52 -52
  73. data/spec/models/blacklight/document_spec.rb +10 -10
  74. data/spec/models/blacklight/facet_paginator_spec.rb +5 -5
  75. data/spec/models/blacklight/search_builder_spec.rb +34 -34
  76. data/spec/models/blacklight/user_spec.rb +4 -4
  77. data/spec/models/bookmark_spec.rb +5 -5
  78. data/spec/models/record_mailer_spec.rb +11 -11
  79. data/spec/models/search_spec.rb +1 -1
  80. data/spec/models/solr_document_spec.rb +4 -4
  81. data/spec/presenters/document_presenter_spec.rb +94 -50
  82. data/spec/presenters/index_presenter_spec.rb +147 -0
  83. data/spec/presenters/pipeline_spec.rb +28 -0
  84. data/spec/presenters/show_presenter_spec.rb +287 -0
  85. data/spec/routing/catalog_routing_spec.rb +11 -11
  86. data/spec/spec_helper.rb +10 -1
  87. data/spec/support/backport_test.rb +38 -0
  88. data/spec/test_app_templates/Gemfile.extra +2 -10
  89. data/spec/views/_user_util_links.html.erb_spec.rb +1 -1
  90. data/spec/views/catalog/_constraints.html.erb_spec.rb +3 -3
  91. data/spec/views/catalog/_constraints_element.html.erb_spec.rb +5 -5
  92. data/spec/views/catalog/_document.html.erb_spec.rb +2 -2
  93. data/spec/views/catalog/_document_list.html.erb_spec.rb +1 -1
  94. data/spec/views/catalog/_facet_layout.html.erb_spec.rb +4 -4
  95. data/spec/views/catalog/_facets.html.erb_spec.rb +4 -4
  96. data/spec/views/catalog/_index_default.erb_spec.rb +5 -4
  97. data/spec/views/catalog/_index_header_default.html.erb_spec.rb +4 -3
  98. data/spec/views/catalog/_paginate_compact.html.erb_spec.rb +3 -3
  99. data/spec/views/catalog/_search_header.erb_spec.rb +1 -1
  100. data/spec/views/catalog/_show_default.erb_spec.rb +6 -5
  101. data/spec/views/catalog/_show_sidebar.erb_spec.rb +2 -1
  102. data/spec/views/catalog/_show_tools.html.erb_spec.rb +8 -8
  103. data/spec/views/catalog/_sort_and_per_page.html.erb_spec.rb +2 -2
  104. data/spec/views/catalog/_thumbnail_default.erb_spec.rb +3 -2
  105. data/spec/views/catalog/_view_type_group.html.erb_spec.rb +3 -3
  106. data/spec/views/catalog/facet.html.erb_spec.rb +3 -3
  107. data/spec/views/catalog/index.atom.builder_spec.rb +15 -14
  108. data/spec/views/catalog/index.html.erb_spec.rb +3 -3
  109. data/spec/views/catalog/opensearch.xml.builder_spec.rb +1 -1
  110. data/spec/views/catalog/show.html.erb_spec.rb +5 -4
  111. data/tasks/blacklight.rake +1 -1
  112. metadata +25 -4
  113. data/config/jetty.yml +0 -13
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 56c35c6ca23b02b1ca6e11d7ba4eca20e6e98765
4
- data.tar.gz: e84c2c02337bd0ff644922c8007b8aa700b1a0bc
3
+ metadata.gz: 38e64adb886cc4afffadc21d807dd85b7f919bef
4
+ data.tar.gz: 6d422b5862b493b3f5b4db3d163c3dbed749bae3
5
5
  SHA512:
6
- metadata.gz: 9e78806fd48f0861fba67936341782d9411b45719688c9fc1fe08cd4e3cc1a8e5675ab3496c185ae16ad2b0a8019a9d2b0b535d36f6284e5a2d2c21623424064
7
- data.tar.gz: 2e72ce5c749e044c9c60383341ef872ba427feeb4da4172adbf3bd257e41ea5cd7eb6d653d0a6fc0ee57cdee2fb70d5e0e2d55df2ae85b3045584a27eea819f1
6
+ metadata.gz: 0b9ff4de640f01ff5ee90d2a10b6b8d2d36b7c746890ab7f19403c85a6cc92a1afe058d5ea79a616aaefe4c8f4f777210c5452e112b26c066e2743cfb99f154c
7
+ data.tar.gz: 6ff37f57181bd54aa43531ef7beae404c787b2c94bab6a2fbe3d0652420ab3f3c1f03b1efb3e7a934ae09ba1c82c7bb381b87d992796742e899b81fc203cccb1
@@ -14,3 +14,6 @@ Metrics/LineLength:
14
14
 
15
15
  Style/StringLiterals:
16
16
  Enabled: false
17
+
18
+ Style/IndentationConsistency:
19
+ Enabled: false
@@ -0,0 +1,5 @@
1
+ # Place any default configuration for solr_wrapper here
2
+ # port: 8983
3
+ collection:
4
+ dir: solr/conf/
5
+ name: blacklight-core
@@ -9,12 +9,10 @@ rvm:
9
9
 
10
10
  matrix:
11
11
  include:
12
- - rvm: 2.1.9
12
+ - rvm: 2.3.1
13
13
  env: "RAILS_VERSION=4.2.6"
14
14
  - rvm: 2.2.5
15
- env: "RAILS_VERSION=4.2.6"
16
- - rvm: 2.3.1
17
- env: "RAILS_VERSION=5.0.0.rc1"
15
+ env: "RAILS_VERSION=5.0.0"
18
16
  - rvm: jruby-9.0.5.0
19
17
  env: "RAILS_VERSION=4.2.6 JRUBY_OPTS=\"-J-Xms512m -J-Xmx1024m\""
20
18
  allow_failures:
@@ -25,7 +23,7 @@ before_install:
25
23
  - gem install bundler
26
24
 
27
25
  env:
28
- - "RAILS_VERSION=4.2.6"
26
+ - "RAILS_VERSION=5.0.0"
29
27
 
30
28
  notifications:
31
29
  irc: "irc.freenode.org#blacklight"
data/Gemfile CHANGED
@@ -34,11 +34,11 @@ else
34
34
  end
35
35
  end
36
36
 
37
- if ENV['RAILS_VERSION'].nil? || ENV['RAILS_VERSION'] =~ /^4\.2/
37
+ if ENV['RAILS_VERSION'].nil? || ENV['RAILS_VERSION'] =~ /^5\.0/ || ENV['RAILS_VERSION'] == 'edge'
38
+ gem 'rspec-rails', '>= 3.5.0.beta4', '~> 3.5'
39
+ elsif ENV['RAILS_VERSION'] =~ /^4\.2/
38
40
  gem 'responders', "~> 2.0"
39
41
  gem 'sass-rails', ">= 5.0"
40
- elsif ENV['RAILS_VERSION'] =~ /^5\.0/ || ENV['RAILS_VERSION'] == 'edge'
41
- # nop
42
42
  else
43
43
  gem 'bootstrap-sass', '< 3.3.5' # 3.3.5 requires sass 3.3, incompatible with sass-rails 4.x
44
44
  gem 'sass-rails', "< 5.0"
data/VERSION CHANGED
@@ -1 +1 @@
1
- 6.2.0
1
+ 6.3.0
@@ -9,17 +9,31 @@ Blacklight = function() {
9
9
  for(var i = 0; i < buffer.length; i++) {
10
10
  buffer[i].call();
11
11
  }
12
+ },
13
+
14
+ listeners: function () {
15
+ var listeners = [];
16
+ if (Turbolinks && Turbolinks.supported) {
17
+ // Turbolinks 5
18
+ if (Turbolinks.BrowserAdapter) {
19
+ listeners.push('turbolinks:load');
20
+ } else {
21
+ // Turbolinks < 5
22
+ listeners.push('page:load', 'ready');
23
+ }
24
+ } else {
25
+ listeners.push('ready');
26
+ }
27
+
28
+ return listeners.join(' ');
12
29
  }
13
- }
30
+ };
14
31
  }();
15
32
 
16
33
  // turbolinks triggers page:load events on page transition
17
34
  // If app isn't using turbolinks, this event will never be triggered, no prob.
18
- $(document).on('page:load', function() {
35
+ $(document).on(Blacklight.listeners(), function() {
19
36
  Blacklight.activate();
20
37
  });
21
38
 
22
- $(document).ready(function() {
23
- Blacklight.activate();
24
- });
25
39
 
@@ -7,6 +7,8 @@ module Blacklight::BlacklightHelperBehavior
7
7
  include RenderConstraintsHelper
8
8
  include RenderPartialsHelper
9
9
  include FacetsHelper
10
+ extend Deprecation
11
+ self.deprecation_horizon = 'Blacklight version 7.0.0'
10
12
 
11
13
  ##
12
14
  # Get the name of this application, from either:
@@ -77,7 +79,7 @@ module Blacklight::BlacklightHelperBehavior
77
79
  # Determine whether to render a given field in the index view.
78
80
  #
79
81
  # @param [SolrDocument] document
80
- # @param [Blacklight::Solr::Configuration::Field] field_config
82
+ # @param [Blacklight::Configuration::Field] field_config
81
83
  # @return [Boolean]
82
84
  def should_render_index_field? document, field_config
83
85
  should_render_field?(field_config, document) && document_has_value?(document, field_config)
@@ -87,7 +89,7 @@ module Blacklight::BlacklightHelperBehavior
87
89
  # Determine whether to render a given field in the show view
88
90
  #
89
91
  # @param [SolrDocument] document
90
- # @param [Blacklight::Solr::Configuration::Field] field_config
92
+ # @param [Blacklight::Configuration::Field] field_config
91
93
  # @return [Boolean]
92
94
  def should_render_show_field? document, field_config
93
95
  should_render_field?(field_config, document) && document_has_value?(document, field_config)
@@ -97,7 +99,7 @@ module Blacklight::BlacklightHelperBehavior
97
99
  # Check if a document has (or, might have, in the case of accessor methods) a value for
98
100
  # the given solr field
99
101
  # @param [SolrDocument] document
100
- # @param [Blacklight::Solr::Configuration::Field] field_config
102
+ # @param [Blacklight::Configuration::Field] field_config
101
103
  # @return [Boolean]
102
104
  def document_has_value? document, field_config
103
105
  document.has?(field_config.field) ||
@@ -158,12 +160,17 @@ module Blacklight::BlacklightHelperBehavior
158
160
  # @param [String] field
159
161
  # @param [Hash] opts
160
162
  # @options opts [String] :value
163
+ # TODO: deprecate and use render_field_value
161
164
  def render_index_field_value *args
165
+ render_field_value(*args)
166
+ end
167
+
168
+ def render_field_value(*args)
162
169
  options = args.extract_options!
163
170
  document = args.shift || options[:document]
164
171
 
165
172
  field = args.shift || options[:field]
166
- presenter(document).render_index_field_value field, options.except(:document, :field)
173
+ presenter(document).field_value field, options.except(:document, :field)
167
174
  end
168
175
 
169
176
  ##
@@ -211,12 +218,9 @@ module Blacklight::BlacklightHelperBehavior
211
218
  # @param [String] field
212
219
  # @param [Hash] opts
213
220
  # @options opts [String] :value
221
+ # TODO: deprecate and use render_field_value
214
222
  def render_document_show_field_value *args
215
- options = args.extract_options!
216
- document = args.shift || options[:document]
217
-
218
- field = args.shift || options[:field]
219
- presenter(document).render_document_show_field_value field, options.except(:document, :field)
223
+ render_field_value(*args)
220
224
  end
221
225
 
222
226
  ##
@@ -227,7 +231,7 @@ module Blacklight::BlacklightHelperBehavior
227
231
  # @return [String]
228
232
  def document_heading document=nil
229
233
  document ||= @document
230
- presenter(document).document_heading
234
+ presenter(document).heading
231
235
  end
232
236
 
233
237
  ##
@@ -240,7 +244,7 @@ module Blacklight::BlacklightHelperBehavior
240
244
  def document_show_html_title document=nil
241
245
  document ||= @document
242
246
 
243
- presenter(document).document_show_html_title
247
+ presenter(document).html_title
244
248
  end
245
249
 
246
250
  ##
@@ -258,7 +262,7 @@ module Blacklight::BlacklightHelperBehavior
258
262
  tag = options.fetch(:tag, :h4)
259
263
  document ||= @document
260
264
 
261
- content_tag(tag, presenter(document).document_heading, itemprop: "name")
265
+ content_tag(tag, presenter(document).heading, itemprop: "name")
262
266
  end
263
267
 
264
268
  ##
@@ -270,15 +274,14 @@ module Blacklight::BlacklightHelperBehavior
270
274
  # Rendering:
271
275
  # - helper_method
272
276
  # - link_to_search
273
- # TODO : maybe this should be merged with render_field_value, and the ugly signature
274
- # simplified by pushing some of this logic into the "model"
275
277
  # @param [SolrDocument] document
276
278
  # @param [String] field name
277
- # @param [Blacklight::Solr::Configuration::Field] solr field configuration
279
+ # @param [Blacklight::Configuration::Field] solr field configuration
278
280
  # @param [Hash] options additional options to pass to the rendering helpers
279
- def get_field_values document, field, field_config, options = {}
280
- presenter(document).get_field_values field, field_config, options
281
+ def get_field_values document, _field, field_config, options = {}
282
+ presenter(document).field_values field_config, options
281
283
  end
284
+ deprecation_deprecate :get_field_values
282
285
 
283
286
  ##
284
287
  # Get the current "view type" (and ensure it is a valid type)
@@ -321,15 +324,40 @@ module Blacklight::BlacklightHelperBehavior
321
324
 
322
325
  ##
323
326
  # Returns a document presenter for the given document
327
+ # TODO: Move this to the controller. It can just pass a presenter or set of presenters.
324
328
  def presenter(document)
325
- presenter_class.new(document, self)
329
+ case action_name
330
+ when 'show', 'citation'
331
+ show_presenter(document)
332
+ when 'index'
333
+ index_presenter(document)
334
+ else
335
+ raise "Unable to determine presenter type for #{action_name} on #{controller_name}"
336
+ end
337
+ end
338
+
339
+ def show_presenter(document)
340
+ show_presenter_class(document).new(document, self)
341
+ end
342
+
343
+ def index_presenter(document)
344
+ index_presenter_class(document).new(document, self)
326
345
  end
327
346
 
328
- ##
329
- # Override this method if you want to use a different presenter class
330
347
  def presenter_class
331
348
  blacklight_config.document_presenter_class
332
349
  end
350
+ deprecation_deprecate presenter_class: "replaced by show_presenter_class and index_presenter_class"
351
+
352
+ ##
353
+ # Override this method if you want to use a different presenter class
354
+ def show_presenter_class(_document)
355
+ blacklight_config.show.document_presenter_class
356
+ end
357
+
358
+ def index_presenter_class(_document)
359
+ blacklight_config.index.document_presenter_class
360
+ end
333
361
 
334
362
  ##
335
363
  # Open Search discovery tag for HTML <head> links
@@ -5,7 +5,7 @@ module Blacklight::ConfigurationHelperBehavior
5
5
  # Index fields to display for a type of document
6
6
  #
7
7
  # @param [SolrDocument] document
8
- # @return [Array<Blacklight::Solr::Configuration::Field>]
8
+ # @return [Array<Blacklight::Configuration::Field>]
9
9
  def index_fields document=nil
10
10
  blacklight_config.index_fields
11
11
  end
@@ -16,6 +16,7 @@ module Blacklight::UrlHelperBehavior
16
16
  # Use the catalog_path RESTful route to create a link to the show page for a specific item.
17
17
  # catalog_path accepts a hash. The solr query params are stored in the session,
18
18
  # so we only need the +counter+ param here. We also need to know if we are viewing to document as part of search results.
19
+ # TODO: move this to the IndexPresenter
19
20
  def link_to_document(doc, field_or_opts = nil, opts={:counter => nil})
20
21
  if field_or_opts.is_a? Hash
21
22
  opts = field_or_opts
@@ -24,7 +25,7 @@ module Blacklight::UrlHelperBehavior
24
25
  end
25
26
 
26
27
  field ||= document_show_link_field(doc)
27
- label = presenter(doc).render_document_index_label field, opts
28
+ label = index_presenter(doc).label field, opts
28
29
  link_to label, url_for_document(doc), document_link_params(doc, opts)
29
30
  end
30
31
 
@@ -1,9 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
  module Blacklight
3
+ # @deprecated
3
4
  class DocumentPresenter
4
- include ActionView::Helpers::OutputSafetyHelper
5
- include ActionView::Helpers::TagHelper
6
5
  extend Deprecation
6
+ self.deprecation_horizon = 'Blacklight version 7.0.0'
7
7
 
8
8
  # @param [SolrDocument] document
9
9
  # @param [ActionController::Base] controller scope for linking and generating urls
@@ -20,39 +20,25 @@ module Blacklight
20
20
  #
21
21
  # @param [SolrDocument] document
22
22
  # @return [String]
23
+ # @deprecated use ShowPresenter#heading instead
23
24
  def document_heading
24
- fields = Array(@configuration.view_config(:show).title_field)
25
- f = fields.find { |field| @document.has? field }
26
-
27
- if f.nil?
28
- render_field_value(@document.id)
29
- else
30
- render_field_value(@document[f])
31
- end
25
+ show_presenter.heading
32
26
  end
27
+ deprecation_deprecate document_heading: "use ShowPresenter#heading instead"
33
28
 
34
29
  ##
35
30
  # Create <link rel="alternate"> links from a documents dynamically
36
31
  # provided export formats. Returns empty string if no links available.
37
32
  #
38
- # @params [SolrDocument] document
39
33
  # @params [Hash] options
40
34
  # @option options [Boolean] :unique ensures only one link is output for every
41
35
  # content type, e.g. as required by atom
42
36
  # @option options [Array<String>] :exclude array of format shortnames to not include in the output
37
+ # @deprecated moved to ShowPresenter#link_rel_alternates
43
38
  def link_rel_alternates(options = {})
44
- options = { unique: false, exclude: [] }.merge(options)
45
-
46
- seen = Set.new
47
-
48
- safe_join(@document.export_formats.map do |format, spec|
49
- next if options[:exclude].include?(format) || (options[:unique] && seen.include?(spec[:content_type]))
50
-
51
- seen.add(spec[:content_type])
52
-
53
- tag(:link, rel: "alternate", title: format, type: spec[:content_type], href: @controller.polymorphic_url(@document, format: format))
54
- end.compact, "\n")
39
+ show_presenter.link_rel_alternates(options)
55
40
  end
41
+ deprecation_deprecate link_rel_alternates: "use ShowPresenter#link_rel_alternates instead"
56
42
 
57
43
  ##
58
44
  # Get the document's "title" to display in the <title> element.
@@ -60,80 +46,36 @@ module Blacklight
60
46
  #
61
47
  # @see #document_heading
62
48
  # @return [String]
49
+ # @deprecated use ShowPresenter#html_title instead
63
50
  def document_show_html_title
64
- if @configuration.view_config(:show).html_title_field
65
- fields = Array(@configuration.view_config(:show).html_title_field)
66
- f = fields.find { |field| @document.has? field }
67
-
68
- if f.nil?
69
- render_field_value(@document.id)
70
- else
71
- render_field_value(@document[f])
72
- end
73
- else
74
- document_heading
75
- end
76
- end
77
-
78
- ##
79
- # Render a value (or array of values) from a field
80
- #
81
- # @param [String] value or list of values to display
82
- # @param [Blacklight::Solr::Configuration::Field] solr field configuration
83
- # @return [String]
84
- def render_field_value value=nil, field_config=nil
85
- safe_values = recode_values(Array(value))
86
-
87
- if field_config and field_config.itemprop
88
- safe_values = safe_values.map { |x| content_tag :span, x, :itemprop => field_config.itemprop }
89
- end
90
-
91
- render_values(safe_values, field_config)
92
- end
93
-
94
- ##
95
- # Render a fields values as a string
96
- # @param [Array] values to display
97
- # @param [Blacklight::Solr::Configuration::Field] solr field configuration
98
- # @return [String]
99
- def render_values(values, field_config = nil)
100
- options = {}
101
- options = field_config.separator_options if field_config && field_config.separator_options
102
-
103
- values.map { |x| html_escape(x) }.to_sentence(options).html_safe
51
+ show_presenter.html_title
104
52
  end
53
+ deprecation_deprecate document_show_html_title: "use ShowPresenter#html_title instead"
105
54
 
106
55
  ##
107
56
  # Render the document index heading
108
57
  #
109
58
  # @param [Symbol, Proc, String] field Render the given field or evaluate the proc or render the given string
110
59
  # @param [Hash] opts
111
- def render_document_index_label(field, opts = {})
112
- label = case field
113
- when Symbol
114
- @document[field]
115
- when Proc
116
- field.call(@document, opts)
117
- when String
118
- field
119
- end
120
- render_field_value label || @document.id
60
+ # @deprecated use IndexPresenter#label instead
61
+ def render_document_index_label(*args)
62
+ index_presenter.label(*args)
121
63
  end
64
+ deprecation_deprecate render_document_index_label: "use IndexPresenter#label instead"
122
65
 
123
66
  ##
124
67
  # Render the index field label for a document
125
68
  #
126
- # Allow an extention point where information in the document
127
- # may drive the value of the field
128
- # @param [String] field
129
- # @param [Hash] opts
130
- # @options opts [String] :value
131
- def render_index_field_value field, options = {}
132
- field_config = @configuration.index_fields[field]
133
- value = options[:value] || get_field_values(field, field_config, options)
134
-
135
- render_field_value value, field_config
69
+ # Allow an extention point where information in the document
70
+ # may drive the value of the field
71
+ # @param [String] field
72
+ # @param [Hash] opts
73
+ # @options opts [String] :value
74
+ # @deprecated use IndexPresenter#field_value instead
75
+ def render_index_field_value *args
76
+ index_presenter.field_value(*args)
136
77
  end
78
+ deprecation_deprecate render_index_field_value: "use IndexPresenter#field_value instead"
137
79
 
138
80
  ##
139
81
  # Render the show field value for a document
@@ -143,12 +85,11 @@ module Blacklight
143
85
  # @param [String] field
144
86
  # @param [Hash] options
145
87
  # @options opts [String] :value
146
- def render_document_show_field_value field, options={}
147
- field_config = @configuration.show_fields[field]
148
- value = options[:value] || get_field_values(field, field_config, options)
149
-
150
- render_field_value value, field_config
88
+ # @deprecated use ShowPresenter#field_value
89
+ def render_document_show_field_value *args
90
+ show_presenter.field_value(*args)
151
91
  end
92
+ deprecation_deprecate render_document_show_field_value: "use ShowPresenter#field_value instead"
152
93
 
153
94
  ##
154
95
  # Get the value for a document's field, and prepare to render it.
@@ -159,78 +100,45 @@ module Blacklight
159
100
  # Rendering:
160
101
  # - helper_method
161
102
  # - link_to_search
162
- # TODO : maybe this should be merged with render_field_value, and the ugly signature
163
- # simplified by pushing some of this logic into the "model"
164
- # @param [SolrDocument] document
165
103
  # @param [String] field name
166
- # @param [Blacklight::Solr::Configuration::Field] solr field configuration
104
+ # @param [Blacklight::Configuration::Field] solr field configuration
167
105
  # @param [Hash] options additional options to pass to the rendering helpers
168
- def get_field_values field, field_config, options = {}
169
- # retrieving values
170
- value = case
171
- when (field_config and field_config.highlight)
172
- # retrieve the document value from the highlighting response
173
- @document.highlight_field(field_config.field).map(&:html_safe) if @document.has_highlight_field? field_config.field
174
- when (field_config and field_config.accessor)
175
- # implicit method call
176
- if field_config.accessor === true
177
- @document.send(field)
178
- # arity-1 method call (include the field name in the call)
179
- elsif !field_config.accessor.is_a?(Array) && @document.method(field_config.accessor).arity != 0
180
- @document.send(field_config.accessor, field)
181
- # chained method calls
182
- else
183
- Array(field_config.accessor).inject(@document) do |result, method|
184
- result.send(method)
185
- end
186
- end
187
- when field_config
188
- # regular document field
189
- if field_config.default and field_config.default.is_a? Proc
190
- @document.fetch(field_config.field, &field_config.default)
191
- else
192
- @document.fetch(field_config.field, field_config.default)
193
- end
194
- when field
195
- @document[field]
196
- end
197
-
198
- # rendering values
199
- case
200
- when (field_config and field_config.helper_method)
201
- @controller.send(field_config.helper_method, options.merge(document: @document, field: field, config: field_config, value: value))
202
- when (field_config and field_config.link_to_search)
203
- link_field = if field_config.link_to_search === true
204
- field_config.key
205
- else
206
- field_config.link_to_search
207
- end
106
+ # @deprecated
107
+ def get_field_values _field, field_config, options = {}
108
+ field_values(field_config, options)
109
+ end
110
+ deprecation_deprecate get_field_values: 'Use field_values instead'
208
111
 
209
- Array(value).map do |v|
210
- @controller.link_to render_field_value(v, field_config), @controller.search_action_path(@controller.search_state.reset.add_facet_params(link_field, v))
211
- end if field
212
- else
213
- value
214
- end
112
+ ##
113
+ # Get the value for a document's field, and prepare to render it.
114
+ # - highlight_field
115
+ # - accessor
116
+ # - solr field
117
+ #
118
+ # Rendering:
119
+ # - helper_method
120
+ # - link_to_search
121
+ # @param [Blacklight::Configuration::Field] solr field configuration
122
+ # @param [Hash] options additional options to pass to the rendering helpers
123
+ def field_values(field_config, options={})
124
+ FieldPresenter.new(@controller, @document, field_config, options).render
215
125
  end
126
+ deprecation_deprecate field_values: 'Use ShowPresenter or IndexPresenter field_values instead'
216
127
 
217
- def html_escape(*args)
218
- ERB::Util.html_escape(*args)
128
+ # @deprecated
129
+ def render_field_value(values, field_config = Configuration::NullField.new)
130
+ FieldPresenter.new(@controller, @document, field_config, value: values).render
219
131
  end
132
+ deprecation_deprecate render_field_value: 'Use FieldPresenter instead'
220
133
 
221
134
  private
222
135
 
223
- # @param [Array<String,Fixnum>] values
224
- # @return [Array] an array with all strings converted to UTF-8
225
- def recode_values(values)
226
- values.collect do |value|
227
- if value.respond_to?(:encoding) && value.encoding != Encoding::UTF_8
228
- Rails.logger.warn "Found a non utf-8 value in Blacklight::DocumentPresenter. \"#{value}\" Encoding is #{value.encoding}"
229
- value.dup.force_encoding('UTF-8')
230
- else
231
- value
232
- end
233
- end
136
+ def index_presenter
137
+ @controller.index_presenter(@document)
138
+ end
139
+
140
+ def show_presenter
141
+ @controller.show_presenter(@document)
234
142
  end
235
143
  end
236
144
  end