Class: Heroicon::Icon
- Inherits:
-
Object
- Object
- Heroicon::Icon
- Defined in:
- lib/heroicon/icon.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#path_options ⇒ Object
readonly
Returns the value of attribute path_options.
-
#variant ⇒ Object
readonly
Returns the value of attribute variant.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(name:, variant:, options:, path_options:) ⇒ Icon
constructor
A new instance of Icon.
- #render ⇒ Object
Constructor Details
#initialize(name:, variant:, options:, path_options:) ⇒ Icon
Returns a new instance of Icon.
7 8 9 10 11 12 |
# File 'lib/heroicon/icon.rb', line 7 def initialize(name:, variant:, options:, path_options:) @name = name @variant = safe_variant(variant) @options = @path_options = end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
5 6 7 |
# File 'lib/heroicon/icon.rb', line 5 def name @name end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
5 6 7 |
# File 'lib/heroicon/icon.rb', line 5 def @options end |
#path_options ⇒ Object (readonly)
Returns the value of attribute path_options.
5 6 7 |
# File 'lib/heroicon/icon.rb', line 5 def @path_options end |
#variant ⇒ Object (readonly)
Returns the value of attribute variant.
5 6 7 |
# File 'lib/heroicon/icon.rb', line 5 def variant @variant end |
Class Method Details
.render(**kwargs) ⇒ Object
117 118 119 |
# File 'lib/heroicon/icon.rb', line 117 def render(**kwargs) new(**kwargs).render end |
Instance Method Details
#render ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/heroicon/icon.rb', line 14 def render return warning unless file.present? doc = Nokogiri::HTML::DocumentFragment.parse(file) svg = doc.at_css "svg" .each do |key, value| attribute = key.to_s.dasherize svg.css("path[#{attribute}]").each do |item| item[attribute] = value.to_s end end prepend_default_class_name .each do |key, value| svg[key.to_s.dasherize] = value end doc end |