Module: Blacklight::IconHelperBehavior

Included in:
BlacklightHelperBehavior
Defined in:
app/helpers/blacklight/icon_helper_behavior.rb

Overview

Module to help generate icon helpers for SVG images

Instance Method Summary collapse

Instance Method Details

#blacklight_icon(icon_name, **kwargs) ⇒ String

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.

Parameters:

  • icon_name (String, Symbol)

Returns:

  • (String)


12
13
14
15
16
17
18
19
20
# File 'app/helpers/blacklight/icon_helper_behavior.rb', line 12

def blacklight_icon(icon_name, **kwargs)
  render "Blacklight::Icons::#{icon_name.to_s.camelize}Component".constantize.new(**kwargs)
rescue NameError
  Blacklight.deprecation.warn(
    "Falling back on the LegacyIconComponent with \"#{icon_name}\" is deprecated. Instead create the component `Blacklight::Icons::#{icon_name.to_s.camelize}Component` for this icon."
  )

  render Blacklight::Icons::LegacyIconComponent.new(name: icon_name, **kwargs)
end