Module: Blacklight::RenderPartialsHelperBehavior

Included in:
CatalogHelperBehavior
Defined in:
app/helpers/blacklight/render_partials_helper_behavior.rb

Instance Method Summary collapse

Instance Method Details

#document_index_path_templatesArray<String>

A list of document partial templates to attempt to render

Returns:

  • (Array<String>)

See Also:



101
102
103
104
105
106
107
108
109
110
# File 'app/helpers/blacklight/render_partials_helper_behavior.rb', line 101

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

Parameters:

  • documents (Array<SolrDocument>)

    list of documents to render

  • locals (Hash) (defaults to: {})

    to pass to the render call

Returns:

  • (String)


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.

Parameters:

  • view (String)

    type

  • documents (Array<SolrDocument>)

    list of documents to render

  • locals (Hash) (defaults to: {})

    to pass to the render call

Returns:

  • (String)

See Also:



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'app/helpers/blacklight/render_partials_helper_behavior.rb', line 80

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.

Parameters:

  • doc (SolrDocument)
  • base_name (String)

    base name for the partial

  • locals (Hash) (defaults to: {})

    local variables to pass through to the partials

See Also:

  • #document_partial_path_templates


52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'app/helpers/blacklight/render_partials_helper_behavior.rb', line 52

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_document_partials(doc, partials = [], locals = {}) ⇒ String

Return the list of partials for a given solr document

Parameters:

  • doc (SolrDocument)

    solr document to render partials for

  • partials (Array<String>) (defaults to: [])

    list of partials to render

  • locals (Hash) (defaults to: {})

    local variables to pass to the render call

Returns:

  • (String)


20
21
22
23
24
# File 'app/helpers/blacklight/render_partials_helper_behavior.rb', line 20

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_xml_partials(doc, partials = [], locals = {}) ⇒ String

Return the list of xml for a given solr document. Doesn’t safely escape for HTML.

Parameters:

  • doc (SolrDocument)

    solr document to render partials for

  • partials (Array<String>) (defaults to: [])

    list of partials to render

  • locals (Hash) (defaults to: {})

    local variables to pass to the render call

Returns:

  • (String)


34
35
36
37
38
# File 'app/helpers/blacklight/render_partials_helper_behavior.rb', line 34

def render_xml_partials(doc, partials = [], locals = {})
  partials.map do |action_name|
    render_document_partial(doc, action_name, locals)
  end.join("\n")
end