-
Notifications
You must be signed in to change notification settings - Fork 254
Commit
…of partial we're rendering This allows downstream implementors to override the calculated #document_partial_name on a per-partial basis. E.g. if you had a heterogeneous index with some records with MODS and MARC data, you could choose the appropriate rendering format for those records independent of the regular format.
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -428,19 +428,25 @@ def document_index_path_templates | |
|
||
## | ||
# Return a normalized partial name for rendering a single document | ||
# | ||
# | ||
# @param [SolrDocument] | ||
# @param [Symbol] base name for the partial | ||
# @return [String] | ||
def document_partial_name(document) | ||
display_type = document[blacklight_config.view_config(:show).display_type_field] | ||
def document_partial_name(document, base_name = nil) | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
cbeer
Author
Member
|
||
view_config = blacklight_config.view_config(:show) | ||
|
||
display_type = if action_name and view_config.has_key? :"#{base_name}_display_type_field" | ||
document[view_config[:"#{base_name}_display_type_field"]] | ||
end | ||
|
||
display_type ||= document[view_config.display_type_field] | ||
|
||
return 'default' unless display_type | ||
display_type = display_type.join(" ") if display_type.respond_to?(:join) | ||
display_type ||= 'default' | ||
|
||
# .to_s is necessary otherwise the default return value is not always a string | ||
# using "_" as sep. to more closely follow the views file naming conventions | ||
# parameterize uses "-" as the default sep. which throws errors | ||
"#{display_type.gsub("-"," ")}".parameterize("_").to_s | ||
Array(display_type).join(" ").gsub("-","_").parameterize("_") | ||
end | ||
|
||
## | ||
|
@@ -466,7 +472,7 @@ def render_document_partials(doc, partials = [], locals ={}) | |
# @param [String] base name for the partial | ||
# @param [Hash] locales to pass through to the partials | ||
def render_document_partial(doc, base_name, locals = {}) | ||
format = document_partial_name(doc) | ||
format = document_partial_name(doc, base_name) | ||
|
||
document_partial_path_templates.each do |str| | ||
# XXX rather than handling this logic through exceptions, maybe there's a Rails internals method | ||
|
I frequently override this method in my own apps, so this is backward compat thing where I need to make sure to change the method signature in my override too.
(Even though the second arg is optional, if other code tries to call my custom override with two args, and my custom override only takes one, that'll be a runtime error).
Such is life, it happens. But make sure it's in the release notes, please?
Also, maybe (I'm not sure) consider making the second arg an options hash (
document_partial_name(doc, :base_name => whatever)
), so that the method signature will never need to be changed again, with a backwards compat issue. I believe this method should be considered part of the BL 'api' and it will be common for apps to override it locally to control partial templates used.