Module: Blacklight::RenderPartialsHelperBehavior
- Included in:
- CatalogHelperBehavior
- Defined in:
- app/helpers/blacklight/render_partials_helper_behavior.rb
Instance Method Summary collapse
-
#document_index_path_templates ⇒ Array<String>
A list of document partial templates to attempt to render.
-
#render_document_index(documents, 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_xml_partials(doc, partials = [], locals = {}) ⇒ String
Return the list of xml for a given solr document.
Instance Method Details
#document_index_path_templates ⇒ Array<String>
A list of document partial templates to attempt to render
87 88 89 90 91 92 93 94 95 96 |
# File 'app/helpers/blacklight/render_partials_helper_behavior.rb', line 87 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 |
#render_document_index(documents, locals = {}) ⇒ String
Render the document index view
10 11 12 |
# File 'app/helpers/blacklight/render_partials_helper_behavior.rb', line 10 def render_document_index documents, locals = {} 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.
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'app/helpers/blacklight/render_partials_helper_behavior.rb', line 66 def render_document_index_with_view view, documents, locals = {} view_config = blacklight_config&.view_config(view) return render partial: view_config.template, locals: locals.merge(documents: documents, view_config: view_config) if view_config&.template 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, view_config: view_config)) 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.
38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'app/helpers/blacklight/render_partials_helper_behavior.rb', line 38 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 logger.warn("No template was found for base_name: '#{base_name}', view_type: '#{view_type}' in render_document_partial") '' end end |
#render_xml_partials(doc, partials = [], locals = {}) ⇒ String
Return the list of xml for a given solr document. Doesn’t safely escape for HTML.
20 21 22 23 24 |
# File 'app/helpers/blacklight/render_partials_helper_behavior.rb', line 20 def render_xml_partials(doc, partials = [], locals = {}) partials.map do |action_name| render_document_partial(doc, action_name, locals) end.join("\n") end |