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

Class Method Summary collapse

Instance Method Summary collapse

Methods included from IconHelperBehavior

#blacklight_icon

Methods included from LayoutHelperBehavior

#container_classes, #extra_body_classes, #html_tag_attributes, #main_content_classes, #opensearch_description_tag, #render_body_class, #render_link_rel_alternates, #render_nav_actions, #render_page_title, #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

Class Method Details

.blacklight_gem_pathObject



41
42
43
# File 'app/helpers/blacklight/blacklight_helper_behavior.rb', line 41

def self.blacklight_gem_path
  @blacklight_gem_path ||= Gem.loaded_specs["blacklight"].full_gem_path
end

Instance Method Details

#application_nameString

Get the name of this application from an i18n string key: blacklight.application_name Try first in the current locale, then the default locale

Returns:

  • (String)

    the application name



15
16
17
18
19
20
21
22
# File 'app/helpers/blacklight/blacklight_helper_behavior.rb', line 15

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

#partial_from_blacklight?(partial) ⇒ Boolean

Returns:

  • (Boolean)


45
46
47
48
49
# File 'app/helpers/blacklight/blacklight_helper_behavior.rb', line 45

def partial_from_blacklight?(partial)
  path = lookup_context.find_all(partial, lookup_context.prefixes + [""], true).first&.identifier

  path.nil? ? false : path.starts_with?(Blacklight::BlacklightHelperBehavior.blacklight_gem_path)
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)

Parameters:

  • format (String)

    suffix

Yields:



33
34
35
36
37
38
39
# File 'app/helpers/blacklight/blacklight_helper_behavior.rb', line 33

def with_format(format)
  old_formats = formats
  self.formats = [format]
  yield
  self.formats = old_formats
  nil
end