Class: Heroicons::Icon

Inherits:
Object
  • Object
show all
Defined in:
lib/heroicons/icon.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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 = options
  @path_options = path_options
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/heroicons/icon.rb', line 3

def name
  @name
end

#optionsObject (readonly)

Returns the value of attribute options.



3
4
5
# File 'lib/heroicons/icon.rb', line 3

def options
  @options
end

#path_optionsObject (readonly)

Returns the value of attribute path_options.



3
4
5
# File 'lib/heroicons/icon.rb', line 3

def path_options
  @path_options
end

#variantObject (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

#renderObject



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"

  path_options.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

  options.each do |key, value|
    svg[key.to_s.dasherize] = value
  end

  doc
end