Module: Blacklight::BlacklightHelperBehavior
- Includes:
- IconHelperBehavior, LayoutHelperBehavior, UrlHelperBehavior
- Included in:
- BlacklightHelper
- Defined in:
- app/helpers/blacklight/blacklight_helper_behavior.rb
Overview
Methods added to this helper will be available to all templates in the hosting application
Layout helpers collapse
-
#application_name ⇒ String
Get the name of this application from an i18n string key: blacklight.application_name Try first in the current locale, then the default locale.
-
#document_index_view_type(query_params = params) ⇒ Symbol
Get the current “view type” (and ensure it is a valid type).
-
#extra_body_classes ⇒ Array<String>
List of classes to be applied to the <body> element.
-
#opensearch_description_tag(title, href) ⇒ String
Open Search discovery tag for HTML <head> links.
-
#render_body_class ⇒ String
Render classes for the <body> element.
-
#render_link_rel_alternates(document = @document, options = {}) ⇒ String
Create <link rel=“alternate”> links from a documents dynamically provided export formats.
-
#render_page_title ⇒ String
Get the page's HTML title.
Search result helpers collapse
-
#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_grouped_response?(response = @response) ⇒ Boolean
Should we render a grouped response (because the response contains a grouped response instead of the normal response).
- #search_bar_presenter_class ⇒ Class
-
#with_format(format) { ... } ⇒ Object
Render a partial of an arbitrary format inside a template of a different format.
Methods included from IconHelperBehavior
Methods included from LayoutHelperBehavior
#container_classes, #html_tag_attributes, #main_content_classes, #show_content_classes, #show_sidebar_classes, #sidebar_classes
Methods included from UrlHelperBehavior
#controller_tracking_method, #link_back_to_catalog, #link_to_document, #link_to_previous_search, #session_tracking_params, #session_tracking_path
Instance Method Details
#application_name ⇒ String
Get the name of this application from an i18n string key: blacklight.application_name Try first in the current locale, then the default locale
17 18 19 20 21 22 23 24 |
# File 'app/helpers/blacklight/blacklight_helper_behavior.rb', line 17 def application_name # It's important that we don't use ActionView::Helpers::CacheHelper#cache here # because it returns nil. Rails.cache.fetch 'blacklight/application_name' do t('blacklight.application_name', default: t('blacklight.application_name', locale: I18n.default_locale)) end end |
#document_index_view_type(query_params = params) ⇒ Symbol
Get the current “view type” (and ensure it is a valid type)
72 73 74 75 76 77 78 79 80 |
# File 'app/helpers/blacklight/blacklight_helper_behavior.rb', line 72 def document_index_view_type query_params = params view_param = query_params[:view] view_param ||= session[:preferred_view] if view_param && document_index_views.key?(view_param.to_sym) view_param.to_sym else default_document_index_view_type end end |
#document_presenter(document) ⇒ Object
Returns a document presenter for the given document
113 114 115 |
# File 'app/helpers/blacklight/blacklight_helper_behavior.rb', line 113 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
120 121 122 123 124 125 126 127 |
# File 'app/helpers/blacklight/blacklight_helper_behavior.rb', line 120 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 |
#extra_body_classes ⇒ Array<String>
List of classes to be applied to the <body> element
63 64 65 |
# File 'app/helpers/blacklight/blacklight_helper_behavior.rb', line 63 def extra_body_classes @extra_body_classes ||= ["blacklight-#{controller.controller_name}", "blacklight-#{[controller.controller_name, controller.action_name].join('-')}"] end |
#opensearch_description_tag(title, href) ⇒ String
Open Search discovery tag for HTML <head> links
138 139 140 |
# File 'app/helpers/blacklight/blacklight_helper_behavior.rb', line 138 def opensearch_description_tag title, href tag :link, href: href, title: title, type: "application/opensearchdescription+xml", rel: "search" end |
#render_body_class ⇒ String
Render classes for the <body> element
55 56 57 |
# File 'app/helpers/blacklight/blacklight_helper_behavior.rb', line 55 def render_body_class extra_body_classes.join " " end |
#render_grouped_response?(response = @response) ⇒ Boolean
Should we render a grouped response (because the response contains a grouped response instead of the normal response)
Default to false if there's no response object available (sometimes the case
for tests, but might happen in other circumstances too..)
107 108 109 |
# File 'app/helpers/blacklight/blacklight_helper_behavior.rb', line 107 def render_grouped_response? response = @response response&.grouped? end |
#render_link_rel_alternates(document = @document, options = {}) ⇒ String
Create <link rel=“alternate”> links from a documents dynamically provided export formats.
Returns empty string if no links available.
46 47 48 49 50 |
# File 'app/helpers/blacklight/blacklight_helper_behavior.rb', line 46 def render_link_rel_alternates(document = @document, = {}) return if document.nil? document_presenter(document).link_rel_alternates() end |
#render_page_title ⇒ String
Get the page's HTML title
30 31 32 |
# File 'app/helpers/blacklight/blacklight_helper_behavior.rb', line 30 def render_page_title (content_for(:page_title) if content_for?(:page_title)) || @page_title || application_name end |
#search_bar_presenter_class ⇒ Class
130 131 132 |
# File 'app/helpers/blacklight/blacklight_helper_behavior.rb', line 130 def blacklight_config.view_config(action_name: :index). end |
#with_format(format) { ... } ⇒ Object
Render a partial of an arbitrary format inside a template of a different format. (e.g. render an HTML partial from an XML template) code taken from: stackoverflow.com/questions/339130/how-do-i-render-a-partial-of-a-different-format-in-rails (zgchurch)
92 93 94 95 96 97 98 |
# File 'app/helpers/blacklight/blacklight_helper_behavior.rb', line 92 def with_format(format) old_formats = formats self.formats = [format] yield self.formats = old_formats nil end |