Class: Heroicon::Icon

Inherits:
Object
  • Object
show all
Defined in:
lib/heroicon/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.



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

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/heroicon/icon.rb', line 5

def name
  @name
end

#optionsObject (readonly)

Returns the value of attribute options.



5
6
7
# File 'lib/heroicon/icon.rb', line 5

def options
  @options
end

#path_optionsObject (readonly)

Returns the value of attribute path_options.



5
6
7
# File 'lib/heroicon/icon.rb', line 5

def path_options
  @path_options
end

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

#renderObject



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"

  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