Module: Blacklight::RenderPartialsHelper
- Included in:
- BlacklightHelperBehavior
- Defined in:
- app/helpers/blacklight/render_partials_helper.rb
Instance Method Summary collapse
-
#document_index_path_templates ⇒ Array<String>
A list of document partial templates to attempt to render.
-
#document_partial_name(document, base_name = nil) ⇒ String
protected
Return a normalized partial name for rendering a single document.
-
#document_partial_path_templates ⇒ Object
protected
A list of document partial templates to try to render for a document.
-
#render_document_index(documents = nil, locals = {}) ⇒ String
Render the document index view.
-
#render_document_index_with_view(view, documents, locals = {}) ⇒ String
Render the document index for the given view type with the list of documents.
-
#render_document_partial(doc, base_name, locals = {}) ⇒ Object
Given a doc and a base name for a partial, this method will attempt to render an appropriate partial based on the document format and view type.
-
#render_document_partials(doc, partials = [], locals = {}) ⇒ String
Return the list of partials for a given solr document.
-
#render_grouped_document_index ⇒ Object
Render the document index for a grouped response.
- #type_field_to_partial_name(document, display_type) ⇒ Object protected
Instance Method Details
#document_index_path_templates ⇒ Array<String>
A list of document partial templates to attempt to render
88 89 90 91 92 93 94 95 96 97 |
# File 'app/helpers/blacklight/render_partials_helper.rb', line 88 def document_index_path_templates # first, the legacy template names for backwards compatbility # followed by the new, inheritable style # finally, a controller-specific path for non-catalog subclasses @document_index_path_templates ||= [ "document_%{index_view_type}", "catalog/document_%{index_view_type}", "catalog/document_list" ] end |
#document_partial_name(document, base_name = nil) ⇒ String (protected)
Return a normalized partial name for rendering a single document
134 135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'app/helpers/blacklight/render_partials_helper.rb', line 134 def document_partial_name(document, base_name = nil) view_config = blacklight_config.view_config(:show) display_type = if base_name and view_config.key? :"#{base_name}_display_type_field" document[view_config[:"#{base_name}_display_type_field"]] end display_type ||= document[view_config.display_type_field] display_type ||= 'default' type_field_to_partial_name(document, display_type) end |
#document_partial_path_templates ⇒ Object (protected)
A list of document partial templates to try to render for a document
The partial names will be interpolated with the following variables:
- action_name: (e.g. index, show)
- index_view_type: (the current view type, e.g. list, gallery)
- format: the document's format (e.g. book)
157 158 159 160 161 162 163 164 165 166 167 168 169 170 |
# File 'app/helpers/blacklight/render_partials_helper.rb', line 157 def document_partial_path_templates # first, the legacy template names for backwards compatbility # followed by the new, inheritable style # finally, a controller-specific path for non-catalog subclasses @partial_path_templates ||= [ "%{action_name}_%{index_view_type}_%{format}", "%{action_name}_%{index_view_type}_default", "%{action_name}_%{format}", "%{action_name}_default", "catalog/%{action_name}_%{format}", "catalog/_%{action_name}_partials/%{format}", "catalog/_%{action_name}_partials/default" ] end |
#render_document_index(documents = nil, locals = {}) ⇒ String
Render the document index view
9 10 11 12 |
# File 'app/helpers/blacklight/render_partials_helper.rb', line 9 def render_document_index documents = nil, locals = {} documents ||= @document_list render_document_index_with_view(document_index_view_type, documents, locals) end |
#render_document_index_with_view(view, documents, locals = {}) ⇒ String
Render the document index for the given view type with the list of documents.
This method will interpolate the list of templates with the current view, and gracefully handles missing templates.
71 72 73 74 75 76 77 78 79 80 81 |
# File 'app/helpers/blacklight/render_partials_helper.rb', line 71 def render_document_index_with_view view, documents, locals = {} template = cached_view ['index', view].join('_') do find_document_index_template_with_view(view, locals) end if template template.render(self, locals.merge(documents: documents)) else '' end end |
#render_document_partial(doc, base_name, locals = {}) ⇒ Object
Given a doc and a base name for a partial, this method will attempt to render an appropriate partial based on the document format and view type.
If a partial that matches the document format is not found, render a default partial for the base name.
44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'app/helpers/blacklight/render_partials_helper.rb', line 44 def render_document_partial(doc, base_name, locals = {}) format = document_partial_name(doc, base_name) view_type = document_index_view_type template = cached_view ['show', view_type, base_name, format].join('_') do find_document_show_template_with_view(view_type, base_name, format, locals) end if template template.render(self, locals.merge(document: doc)) else '' end end |
#render_document_partials(doc, partials = [], locals = {}) ⇒ String
Return the list of partials for a given solr document
26 27 28 29 30 |
# File 'app/helpers/blacklight/render_partials_helper.rb', line 26 def render_document_partials(doc, partials = [], locals = {}) safe_join(partials.map do |action_name| render_document_partial(doc, action_name, locals) end, "\n") end |
#render_grouped_document_index ⇒ Object
Render the document index for a grouped response
16 17 18 |
# File 'app/helpers/blacklight/render_partials_helper.rb', line 16 def render_grouped_document_index render 'catalog/group_default' end |
#type_field_to_partial_name(document, display_type) ⇒ Object (protected)
113 114 115 116 117 118 |
# File 'app/helpers/blacklight/render_partials_helper.rb', line 113 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 underscore = '_'.freeze Array(display_type).join(' '.freeze).tr('-'.freeze, underscore).parameterize(separator: underscore) end |