Skip to content

Commit

Permalink
Support custom tranformation of display_type_field into partial name
Browse files Browse the repository at this point in the history
This enables implementers to override the type_field_to_partial_name
in order to use a field value like 'PdfBook' to render a partial like
'pdf_book'.
  • Loading branch information
jcoyne committed Mar 17, 2014
1 parent 9fb98ba commit b9f72a0
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion app/helpers/blacklight/blacklight_helper_behavior.rb
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,21 @@ def document_partial_name(document, base_name = nil)

display_type ||= 'default'

# .to_s is necessary otherwise the default return value is not always a string
type_field_to_partial_name(document, display_type)
end

##
# Return a partial name for rendering a document
# this method can be overridden in order to transform the value
# (e.g. 'PdfBook' => 'pdf_book')
#
# @param [SolrDocument] document
# @param [String, Array] display_type a value suggestive of a partial
# @return [String] the name of the partial to render
# @example
# type_field_to_partial_name(['a book-article'])
# => 'a_book_article'
def type_field_to_partial_name(document, display_type)
# using "_" as sep. to more closely follow the views file naming conventions
# parameterize uses "-" as the default sep. which throws errors
Array(display_type).join(" ").gsub("-","_").parameterize("_")
Expand Down

0 comments on commit b9f72a0

Please sign in to comment.