Class: Primer::OcticonComponent
- Defined in:
- app/components/primer/octicon_component.rb
Overview
‘Octicon` renders an <%= link_to_octicons %> with <%= link_to_system_arguments_docs %>.
Constant Summary collapse
- SIZE_DEFAULT =
:small- SIZE_MAPPINGS =
{ SIZE_DEFAULT => 16, :medium => 32, :large => 64 }.freeze
- SIZE_OPTIONS =
SIZE_MAPPINGS.keys
Constants included from Status::Dsl
Constants included from ViewHelper
Constants included from TestSelectorHelper
TestSelectorHelper::TEST_SELECTOR_TAG
Constants included from FetchOrFallbackHelper
FetchOrFallbackHelper::InvalidValueError
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(icon_name = nil, icon: nil, size: SIZE_DEFAULT, **system_arguments) ⇒ OcticonComponent
constructor
A new instance of OcticonComponent.
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
Constructor Details
#initialize(icon_name = nil, icon: nil, size: SIZE_DEFAULT, **system_arguments) ⇒ OcticonComponent
Returns a new instance of OcticonComponent.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'app/components/primer/octicon_component.rb', line 31 def initialize(icon_name = nil, icon: nil, size: SIZE_DEFAULT, **system_arguments) icon_key = icon_name || icon cache_key = [icon_key, size, system_arguments.slice(:height, :width)].join("_") @system_arguments = system_arguments @system_arguments[:tag] = :svg @system_arguments[:aria] ||= {} if @system_arguments[:aria][:label] || @system_arguments[:"aria-label"] @system_arguments[:role] = "img" else @system_arguments[:aria][:hidden] = true end if (cache_icon = Primer::Octicon::Cache.read(cache_key)) @icon = cache_icon else # Filter out classify options to prevent them from becoming invalid html attributes. # Note height and width are both classify options and valid html attributes. = { height: SIZE_MAPPINGS[fetch_or_fallback(SIZE_OPTIONS, size, SIZE_DEFAULT)] }.merge(@system_arguments.slice(:height, :width)) @icon = Octicons::Octicon.new(icon_key, ) Primer::Octicon::Cache.set(cache_key, @icon) end @system_arguments[:classes] = class_names( @icon.[:class], @system_arguments[:classes] ) @system_arguments.merge!(@icon..except(:class, :'aria-hidden')) end |
Instance Method Details
#call ⇒ Object
65 66 67 |
# File 'app/components/primer/octicon_component.rb', line 65 def call render(Primer::BaseComponent.new(**@system_arguments)) { @icon.path.html_safe } # rubocop:disable Rails/OutputSafety end |