app/presenters/blacklight/document_presenter.rb in blacklight-5.19.2 vs app/presenters/blacklight/document_presenter.rb in blacklight-6.0.0.pre1
- old
+ new
@@ -85,14 +85,33 @@
if field_config and field_config.itemprop
safe_values = safe_values.map { |x| content_tag :span, x, :itemprop => field_config.itemprop }
end
- safe_join(safe_values, (field_config.separator if field_config) || field_value_separator)
+ render_values(safe_values, field_config)
end
##
+ # Render a fields values as a string
+ # @param [Array] values to display
+ # @param [Blacklight::Solr::Configuration::Field] solr field configuration
+ # @return [String]
+ def render_values(values, field_config = nil)
+ options = {}
+ options = field_config.separator_options if field_config && field_config.separator_options
+
+ if field_config && field_config.separator
+ Deprecation.warn(self.class, 'The field configuration #separator is deprecated. Use #separator_options instead')
+ options[:words_connector] ||= field_config.separator
+ options[:two_words_connector] ||= field_config.separator
+ options[:last_word_connector] ||= field_config.separator
+ end
+
+ values.to_sentence(options)
+ end
+
+ ##
# Render the document index heading
#
# @param [Hash] opts (Deprecated)
# @option opts [Symbol] :label Render the given field from the document
# @option opts [Proc] :label Evaluate the given proc
@@ -165,11 +184,11 @@
when (field_config and field_config.highlight)
# retrieve the document value from the highlighting response
@document.highlight_field(field_config.field).map(&:html_safe) if @document.has_highlight_field? field_config.field
when (field_config and field_config.accessor)
# implicit method call
- if field_config.accessor == true
+ if field_config.accessor === true
@document.send(field)
# arity-1 method call (include the field name in the call)
elsif !field_config.accessor.is_a?(Array) && @document.method(field_config.accessor).arity != 0
@document.send(field_config.accessor, field)
# chained method calls
@@ -190,13 +209,13 @@
end
# rendering values
case
when (field_config and field_config.helper_method)
- @controller.send(field_config.helper_method, options.merge(document: @document, field: field, config: field_config, value: value))
+ @controller.send(field_config.helper_method, options.merge(:document => @document, :field => field, :value => value))
when (field_config and field_config.link_to_search)
- link_field = if field_config.link_to_search == true
+ link_field = if field_config.link_to_search === true
field_config.key
else
field_config.link_to_search
end
@@ -205,16 +224,7 @@
end if field
else
value
end
end
-
- ##
- # Default separator to use in #render_field_value
- #
- # @return [String]
- def field_value_separator
- ', '
- end
-
end
end