Sha256: e5fe5460fa7d320c61452dcbf537b0a08f4432a2e30a1981750633fcad61db6c

Contents?: true

Size: 1.62 KB

Versions: 12

Compression:

Stored size: 1.62 KB

Contents

# frozen_string_literal: true

# Methods added to this helper will be available to all templates in the hosting application
module Blacklight::BlacklightHelperBehavior
  include Blacklight::UrlHelperBehavior
  include Blacklight::LayoutHelperBehavior
  include Blacklight::IconHelperBehavior

  ##
  # Get the name of this application from an i18n string
  # key: blacklight.application_name
  # Try first in the current locale, then the default locale
  #
  # @return [String] the application name
  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

  ##
  # 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:
  # http://stackoverflow.com/questions/339130/how-do-i-render-a-partial-of-a-different-format-in-rails (zgchurch)
  #
  # @param [String] format suffix
  # @yield
  def with_format(format)
    old_formats = formats
    self.formats = [format]
    yield
    self.formats = old_formats
    nil
  end

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

  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
end

Version data entries

12 entries across 12 versions & 2 rubygems

Version Path
blacklight-8.6.1 app/helpers/blacklight/blacklight_helper_behavior.rb
blacklight-8.6.0 app/helpers/blacklight/blacklight_helper_behavior.rb
blacklight-8.5.1 app/helpers/blacklight/blacklight_helper_behavior.rb
blacklight-8.5.0 app/helpers/blacklight/blacklight_helper_behavior.rb
blacklight-8.4.0 app/helpers/blacklight/blacklight_helper_behavior.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/blacklight-8.3.0/app/helpers/blacklight/blacklight_helper_behavior.rb
blacklight-8.3.0 app/helpers/blacklight/blacklight_helper_behavior.rb
blacklight-8.2.2 app/helpers/blacklight/blacklight_helper_behavior.rb
blacklight-8.2.1 app/helpers/blacklight/blacklight_helper_behavior.rb
blacklight-8.2.0 app/helpers/blacklight/blacklight_helper_behavior.rb
blacklight-8.1.0 app/helpers/blacklight/blacklight_helper_behavior.rb
blacklight-8.0.1 app/helpers/blacklight/blacklight_helper_behavior.rb