Class: HeroiconsHelper::Icon
- Inherits:
-
Object
- Object
- HeroiconsHelper::Icon
- Defined in:
- lib/heroicons_helper/icon.rb
Overview
Icon to show heroicons by name and variant.
Constant Summary collapse
- VARIANT_OUTLINE =
"outline"
- VARIANT_SOLID =
"solid"
- VARIANT_MINI =
"mini"
- VARIANT_MICRO =
"micro"
- VALID_VARIANTS =
Set.new([VARIANT_OUTLINE, VARIANT_SOLID, VARIANT_MINI, VARIANT_MICRO]).freeze
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
-
#height ⇒ Object
readonly
Returns the value of attribute height.
-
#inner ⇒ Object
readonly
Returns the value of attribute inner.
-
#keywords ⇒ Object
readonly
Returns the value of attribute keywords.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#variant ⇒ Object
readonly
Returns the value of attribute variant.
-
#width ⇒ Object
readonly
Returns the value of attribute width.
Instance Method Summary collapse
-
#initialize(name, variant, size: nil, attributes: {}) ⇒ Icon
constructor
A new instance of Icon.
-
#to_svg ⇒ Object
Returns an string representing a <svg> tag.
Constructor Details
#initialize(name, variant, size: nil, attributes: {}) ⇒ Icon
Returns a new instance of Icon.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/heroicons_helper/icon.rb', line 17 def initialize(name, variant, size: nil, attributes: {}) @name = name.to_s @variant = variant.to_s heroicon = get_heroicon(@name, @variant) @inner = heroicon["inner"] @width = size || heroicon["width"] @height = size || heroicon["height"] @keywords = heroicon["keywords"] @attributes = attributes.merge(heroicon["attributes"]) @attributes.merge!({ "class" => classes, "viewBox" => viewbox, "version" => "1.1", }) .merge!(a11y) .compact! end |
Instance Attribute Details
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
9 10 11 |
# File 'lib/heroicons_helper/icon.rb', line 9 def attributes @attributes end |
#height ⇒ Object (readonly)
Returns the value of attribute height.
9 10 11 |
# File 'lib/heroicons_helper/icon.rb', line 9 def height @height end |
#inner ⇒ Object (readonly)
Returns the value of attribute inner.
9 10 11 |
# File 'lib/heroicons_helper/icon.rb', line 9 def inner @inner end |
#keywords ⇒ Object (readonly)
Returns the value of attribute keywords.
9 10 11 |
# File 'lib/heroicons_helper/icon.rb', line 9 def keywords @keywords end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
9 10 11 |
# File 'lib/heroicons_helper/icon.rb', line 9 def name @name end |
#variant ⇒ Object (readonly)
Returns the value of attribute variant.
9 10 11 |
# File 'lib/heroicons_helper/icon.rb', line 9 def variant @variant end |
#width ⇒ Object (readonly)
Returns the value of attribute width.
9 10 11 |
# File 'lib/heroicons_helper/icon.rb', line 9 def width @width end |
Instance Method Details
#to_svg ⇒ Object
Returns an string representing a <svg> tag
38 39 40 |
# File 'lib/heroicons_helper/icon.rb', line 38 def to_svg "<svg #{html_attributes}>#{@inner}</svg>" end |