Module: TablerIconsRuby

Extended by:
TablerIconsRuby
Included in:
TablerIconsRuby
Defined in:
lib/tabler_icons_ruby.rb,
lib/tabler_icons_ruby/version.rb

Defined Under Namespace

Modules: Helper Classes: Error

Constant Summary collapse

VERSION =
"3.11.0"

Class Method Summary collapse

Class Method Details

.render(icon_name, size: nil, color: nil, class: nil, stroke_width: nil, **options) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/tabler_icons_ruby.rb', line 11

def self.render(icon_name, size: nil, color: nil, class: nil, stroke_width: nil, **options)
  icon_name = icon_name.to_s.tr('_', '-')
  root = nokogiri_doc(icon_name).root

  if size
    root.set_attribute('width', size)
    root.set_attribute('height', size)
  end

  if html_class = binding.local_variable_get(:class)
    new_classes = html_class.is_a?(String) ? html_class.split(" ") : Array(html_class)
    classes = (root.classes + new_classes).join(' ')
    root.set_attribute('class', classes)
  end

  root.set_attribute('color', color) if color
  root.set_attribute('stroke-width', stroke_width) if stroke_width

  options.each do |attribute_name, attribute_value|
    root.set_attribute(attribute_name, attribute_value)
  end

  html = root.to_html
  html = html.html_safe if html.respond_to?(:html_safe)
  html
end