Module: Blacklight::DocumentHelperBehavior

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

Overview

Helper methods for catalog-like controllers that work with documents

Instance Method Summary collapse

Instance Method Details

#bookmarked?(document) ⇒ Boolean

Check if the document is in the user’s bookmarks

Parameters:

Returns:

  • (Boolean)


43
44
45
# File 'app/helpers/blacklight/document_helper_behavior.rb', line 43

def bookmarked? document
  current_bookmarks.any? { |x| x.document_id == document.id && x.document_type == document.class }
end

#document_class_prefixString

Return a prefix for the document classes infered from the document

Returns:

  • (String)

See Also:



23
24
25
# File 'app/helpers/blacklight/document_helper_behavior.rb', line 23

def document_class_prefix
  'blacklight-'
end

#document_presenter(document) ⇒ Object

Returns a document presenter for the given document



49
50
51
# File 'app/helpers/blacklight/document_helper_behavior.rb', line 49

def document_presenter(document)
  document_presenter_class(document).new(document, self)
end

#document_presenter_class(_document = nil) ⇒ Object

Override this method if you want to use a differnet presenter for your documents

Parameters:

  • _document (Blacklight::Document) (defaults to: nil)

    optional, here for extension + backwards compatibility only



56
57
58
59
60
61
62
63
# File 'app/helpers/blacklight/document_helper_behavior.rb', line 56

def document_presenter_class(_document = nil)
  case action_name
  when 'show', 'citation'
    blacklight_config.view_config(:show, action_name: action_name).document_presenter_class
  else
    blacklight_config.view_config(document_index_view_type, action_name: action_name).document_presenter_class
  end
end

#render_document_class(document = @document) ⇒ String

Get the classes to add to a document’s div

Parameters:

Returns:

  • (String)


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

def render_document_class(document = @document)
  types = document_presenter(document).display_type
  return if types.blank?

  Array(types).compact.map do |t|
    "#{document_class_prefix}#{t.try(:parameterize) || t}"
  end.join(' ')
end