Module: Blacklight::RenderPartialsHelperBehavior

Extended by:
Deprecation
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:



110
111
112
113
114
115
116
117
118
119
# File 'app/helpers/blacklight/render_partials_helper_behavior.rb', line 110

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

Return a normalized partial name for rendering a single document

Parameters:

  • document (SolrDocument)
  • base_name (Symbol) (defaults to: nil)

    base name for the partial

Returns:

  • (String)


128
129
130
131
132
# File 'app/helpers/blacklight/render_partials_helper_behavior.rb', line 128

def document_partial_name(document, base_name = nil)
  display_type = document_presenter(document).display_type(base_name, default: 'default')

  type_field_to_partial_name(document, display_type)
end

#render_document_index(documents = nil, locals = {}) ⇒ String

Render the document index view

Parameters:

  • documents (Array<SolrDocument>) (defaults to: nil)

    list of documents to render

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

    to pass to the render call

Returns:

  • (String)


11
12
13
14
15
16
17
# File 'app/helpers/blacklight/render_partials_helper_behavior.rb', line 11

def render_document_index documents = nil, locals = {}
  unless documents
    Deprecation.warn(self, "Calling render_document_index without documents is deprecated and will be removed in version 8")
    documents = @response.documents
  end
  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:



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'app/helpers/blacklight/render_partials_helper_behavior.rb', line 89

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


62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'app/helpers/blacklight/render_partials_helper_behavior.rb', line 62

def render_document_partial(doc, base_name, locals = {})
  format = Deprecation.silence(Blacklight::RenderPartialsHelperBehavior) { 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

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)


32
33
34
35
36
# File 'app/helpers/blacklight/render_partials_helper_behavior.rb', line 32

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_indexObject

Render the document index for a grouped response



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

def render_grouped_document_index
  render 'catalog/group'
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)


44
45
46
47
48
# File 'app/helpers/blacklight/render_partials_helper_behavior.rb', line 44

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