Class: Heroicons::Icon

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

Constant Summary collapse

AVAILABLE_VARIANTS =
{
  16 => [:solid],
  20 => [:solid],
  24 => [:outline, :solid]
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Icon.



11
12
13
14
15
16
# File 'lib/heroicons/icon.rb', line 11

def initialize(name, variant:, size:, **options)
  @name = name
  @size = size.in?(AVAILABLE_VARIANTS.keys) ? size : 24
  @variant = variant.in?(AVAILABLE_VARIANTS[@size]) ? variant : :solid
  @options = options.with_indifferent_access
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

#sizeObject (readonly)

Returns the value of attribute size.



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

def size
  @size
end

#variantObject (readonly)

Returns the value of attribute variant.



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

def variant
  @variant
end

Instance Method Details

#renderObject



18
19
20
21
22
23
24
25
# File 'lib/heroicons/icon.rb', line 18

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