Class: Heroicons::Icon
- Inherits:
-
Object
- Object
- Heroicons::Icon
- Defined in:
- lib/heroicons/icon.rb
Constant Summary collapse
- AVAILABLE_VARIANTS =
{ 16 => [:solid], 20 => [:solid], 24 => [:outline, :solid] }.freeze
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#size ⇒ Object
readonly
Returns the value of attribute size.
-
#variant ⇒ Object
readonly
Returns the value of attribute variant.
Instance Method Summary collapse
-
#initialize(name, variant:, size:, **options) ⇒ Icon
constructor
A new instance of Icon.
- #render ⇒ Object
Constructor Details
#initialize(name, variant:, size:, **options) ⇒ Icon
Returns a new instance of Icon.
11 12 13 14 15 16 |
# File 'lib/heroicons/icon.rb', line 11 def initialize(name, variant:, size:, **) @name = name @size = size.in?(AVAILABLE_VARIANTS.keys) ? size : 24 @variant = variant.in?(AVAILABLE_VARIANTS[@size]) ? variant : :solid @options = .with_indifferent_access end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
9 10 11 |
# File 'lib/heroicons/icon.rb', line 9 def name @name end |
#size ⇒ Object (readonly)
Returns the value of attribute size.
9 10 11 |
# File 'lib/heroicons/icon.rb', line 9 def size @size end |
#variant ⇒ Object (readonly)
Returns the value of attribute variant.
9 10 11 |
# File 'lib/heroicons/icon.rb', line 9 def variant @variant end |
Instance Method Details
#render ⇒ Object
18 19 20 21 22 23 24 25 |
# File 'lib/heroicons/icon.rb', line 18 def render return warning unless content.present? fragment = Nokogiri::HTML::DocumentFragment.parse(content) svg = fragment.at_css "svg" @options.each { |key, value| svg[key.to_s] = value } fragment end |