Class: Heroicons::Icon
- Inherits:
-
Object
- Object
- Heroicons::Icon
- Defined in:
- lib/heroicons/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.
5 6 7 8 9 10 |
# File 'lib/heroicons/icon.rb', line 5 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.
3 4 5 |
# File 'lib/heroicons/icon.rb', line 3 def name @name end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
3 4 5 |
# File 'lib/heroicons/icon.rb', line 3 def @options end |
#path_options ⇒ Object (readonly)
Returns the value of attribute path_options.
3 4 5 |
# File 'lib/heroicons/icon.rb', line 3 def @path_options end |
#variant ⇒ Object (readonly)
Returns the value of attribute variant.
3 4 5 |
# File 'lib/heroicons/icon.rb', line 3 def variant @variant end |
Class Method Details
.render(**kwargs) ⇒ Object
115 116 117 |
# File 'lib/heroicons/icon.rb', line 115 def render(**kwargs) new(**kwargs).render end |
Instance Method Details
#render ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/heroicons/icon.rb', line 12 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 |