Class: Heroicons::Icon

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

Constant Summary collapse

VARIANTS =
%i[solid outline].freeze
SIZES =
[20, 24].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, variant:, size:, **options) ⇒ Icon



8
9
10
11
12
13
# File 'lib/heroicons/icon.rb', line 8

def initialize(name, variant:, size:, **options)
  @name = name
  @variant = variant.in?(VARIANTS) ? variant : :solid
  @size = size.in?(SIZES) ? size : 24
  @options = options.with_indifferent_access
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



6
7
8
# File 'lib/heroicons/icon.rb', line 6

def name
  @name
end

#sizeObject (readonly)

Returns the value of attribute size.



6
7
8
# File 'lib/heroicons/icon.rb', line 6

def size
  @size
end

#variantObject (readonly)

Returns the value of attribute variant.



6
7
8
# File 'lib/heroicons/icon.rb', line 6

def variant
  @variant
end

Instance Method Details

#renderObject



15
16
17
18
19
20
21
22
# File 'lib/heroicons/icon.rb', line 15

def render
  return warning unless content.present?

  fragment = Nokogiri::HTML::DocumentFragment.parse(content)
  svg = fragment.at_css "svg"
  @options.each { |key, value| svg[key.to_s] = value }
  fragment
end