Sha256: 0207b6d809d815d38c258ec000e399305dde007b2dafe60520f771834c7daf74

Contents?: true

Size: 833 Bytes

Versions: 2

Compression:

Stored size: 833 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)
    return render(icon_name.new) if icon_name.is_a?(Class)
    return render(icon_name) if icon_name.is_a?(ViewComponent::Base)

    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

2 entries across 2 versions & 1 rubygems

Version Path
blacklight-7.40.0 app/helpers/blacklight/icon_helper_behavior.rb
blacklight-7.39.0 app/helpers/blacklight/icon_helper_behavior.rb