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 Note: we do string comparison of the classes, because hot reloading in the development environment may cause each to have

separate versions of the class loaded (see document.class.object_id and Bookmark#document_type.object_id)

Parameters:

Returns:

  • (Boolean)


45
46
47
# File 'app/helpers/blacklight/document_helper_behavior.rb', line 45

def bookmarked? document
  current_bookmarks.any? { |x| x.document_id == document.id && x.document_type.to_s == document.class.to_s }
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



51
52
53
# File 'app/helpers/blacklight/document_helper_behavior.rb', line 51

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



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

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