Class: Primer::Alpha::OcticonSymbols
- Defined in:
- app/components/primer/alpha/octicon_symbols.rb
Overview
OcticonSymbols renders a symbol dictionary using a list of <%= link_to_octicons %>.
Constant Summary
Constants inherited from Component
Component::INVALID_ARIA_LABEL_TAGS
Constants included from Status::Dsl
Constants included from ViewHelper
Constants included from TestSelectorHelper
TestSelectorHelper::TEST_SELECTOR_TAG
Constants included from FetchOrFallbackHelper
FetchOrFallbackHelper::InvalidValueError
Constants included from Primer::AttributesHelper
Primer::AttributesHelper::PLURAL_ARIA_ATTRIBUTES, Primer::AttributesHelper::PLURAL_DATA_ATTRIBUTES
Instance Method Summary collapse
-
#initialize(icons: []) ⇒ OcticonSymbols
constructor
A new instance of OcticonSymbols.
- #render? ⇒ Boolean
- #symbol_tags ⇒ Object
Methods inherited from Component
Methods included from JoinStyleArgumentsHelper
Methods included from TestSelectorHelper
Methods included from FetchOrFallbackHelper
#fetch_or_fallback, #fetch_or_fallback_boolean, #silence_deprecations?
Methods included from ClassNameHelper
Methods included from Primer::AttributesHelper
#aria, #data, #extract_data, #merge_aria, #merge_data, #merge_prefixed_attribute_hashes
Methods included from ExperimentalSlotHelpers
Methods included from ExperimentalRenderHelpers
Constructor Details
#initialize(icons: []) ⇒ OcticonSymbols
Returns a new instance of OcticonSymbols.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'app/components/primer/alpha/octicon_symbols.rb', line 10 def initialize(icons: []) @icons = {} icons.each do |icon| symbol = icon[:symbol] size = Primer::Beta::Octicon::SIZE_MAPPINGS[ fetch_or_fallback(Primer::Beta::Octicon::SIZE_OPTIONS, icon[:size] || Primer::Beta::Octicon::SIZE_DEFAULT, Primer::Beta::Octicon::SIZE_DEFAULT) ] cache_key = Primer::Octicon::Cache.get_key(symbol: symbol, size: size) if (cache_icon = Primer::Octicon::Cache.read(cache_key)) icon_instance = cache_icon else icon_instance = Octicons::Octicon.new(symbol, height: size) Primer::Octicon::Cache.set(cache_key, icon_instance) end # Don't put the same icon twice @icons[[symbol, icon_instance.height]] = icon_instance if @icons[[symbol, icon_instance.height]].nil? end end |
Instance Method Details
#render? ⇒ Boolean
33 34 35 |
# File 'app/components/primer/alpha/octicon_symbols.rb', line 33 def render? @icons.any? end |
#symbol_tags ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'app/components/primer/alpha/octicon_symbols.rb', line 37 def safe_join( @icons.values.map do |icon| content_tag( :symbol, icon.path.html_safe, # rubocop:disable Rails/OutputSafety id: "octicon_#{icon.symbol}_#{icon.height}", viewBox: icon.[:viewBox], width: icon.width, height: icon.height ) end ) end |