Sha256: 49d44a0fc1caab5accba88875fc08f194fbdefdc5897f9b95f6e227aaf577266

Contents?: true

Size: 704 Bytes

Versions: 12

Compression:

Stored size: 704 Bytes

Contents

# frozen_string_literal: true

##
# Module to help generate icon helpers for SVG images
module Blacklight::IconHelperBehavior
  ##
  # Returns the raw SVG (String) for a Blacklight Icon located in
  # app/assets/images/blacklight/*.svg. Caches them so we don't have to look up
  # the svg everytime.
  # @param [String, Symbol] icon_name
  # @return [String]
  def blacklight_icon(icon_name, **kwargs)
    render "Blacklight::Icons::#{icon_name.to_s.camelize}Component".constantize.new(**kwargs)
  rescue NameError
    Rails.cache.fetch([:blacklight_icons, icon_name, kwargs]) do
      icon = Blacklight::Icon.new(icon_name, **kwargs)
      tag.span(icon.svg.html_safe, **icon.options)
    end
  end
end

Version data entries

12 entries across 12 versions & 2 rubygems

Version Path
blacklight-7.38.0 app/helpers/blacklight/icon_helper_behavior.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/blacklight-7.37.0/app/helpers/blacklight/icon_helper_behavior.rb
blacklight-7.37.0 app/helpers/blacklight/icon_helper_behavior.rb
blacklight-7.36.2 app/helpers/blacklight/icon_helper_behavior.rb
blacklight-7.36.1 app/helpers/blacklight/icon_helper_behavior.rb
blacklight-7.36.0 app/helpers/blacklight/icon_helper_behavior.rb
blacklight-7.35.0 app/helpers/blacklight/icon_helper_behavior.rb
blacklight-7.34.0 app/helpers/blacklight/icon_helper_behavior.rb
blacklight-7.33.1 app/helpers/blacklight/icon_helper_behavior.rb
blacklight-7.33.0 app/helpers/blacklight/icon_helper_behavior.rb
blacklight-7.32.0 app/helpers/blacklight/icon_helper_behavior.rb
blacklight-7.31.0 app/helpers/blacklight/icon_helper_behavior.rb