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
-
#bookmarked?(document) ⇒ Boolean
Check if the document is in the user’s bookmarks.
-
#document_class_prefix ⇒ String
Return a prefix for the document classes infered from the document.
-
#document_presenter(document) ⇒ Object
Returns a document presenter for the given document.
-
#document_presenter_class(_document = nil) ⇒ Object
Override this method if you want to use a differnet presenter for your documents.
-
#render_document_class(document = @document) ⇒ String
Get the classes to add to a document’s div.
- #render_document_sidebar_partial(document) ⇒ String deprecated Deprecated.
Instance Method Details
#bookmarked?(document) ⇒ Boolean
Check if the document is in the user’s bookmarks
69 70 71 |
# File 'app/helpers/blacklight/document_helper_behavior.rb', line 69 def bookmarked? document current_bookmarks.any? { |x| x.document_id == document.id && x.document_type == document.class } end |
#document_class_prefix ⇒ String
Return a prefix for the document classes infered from the document
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
75 76 77 |
# File 'app/helpers/blacklight/document_helper_behavior.rb', line 75 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
82 83 84 85 86 87 88 89 |
# File 'app/helpers/blacklight/document_helper_behavior.rb', line 82 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
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 |
#render_document_sidebar_partial(document) ⇒ String
Render the sidebar partial for a document This is used as an integration point by downstream apps to add to the default sidebar. See: github.com/geoblacklight/geoblacklight/blob/7d3c31c7af3362879b97e2c1351a2496c728c59c/app/helpers/blacklight_helper.rb#L7
36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'app/helpers/blacklight/document_helper_behavior.rb', line 36 def (document) unless @render_document_sidebar_partials_deprecation_warning_shown partials = lookup_context.find_all('show_sidebar', lookup_context.prefixes, true, [], {}) unless partials.first.identifier.starts_with? Blacklight.root Blacklight.deprecation.warn('The partial catalog/_show_sidebar.html.erb will not be rendered by #render_document_sidebar_partial in Blacklight 9.0.' \ 'Configure blacklight_config.show.sidebar_component instead (default Blacklight::Search::SidebarComponent).') @render_document_sidebar_partials_deprecation_warning_shown = true end end render 'show_sidebar', document: document end |