Class: RailsuiIcon::Icon

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

Constant Summary collapse

VALID_VARIANTS =
%i[solid outline mini micro].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, variant: RailsuiIcon.configuration.default_variant, options: {}, custom_path: nil) ⇒ Icon

Returns a new instance of Icon.



9
10
11
12
13
14
# File 'lib/railsui_icon/icon.rb', line 9

def initialize(name:, variant: RailsuiIcon.configuration.default_variant, options: {}, custom_path: nil)
  @name = name
  @variant = validate_variant(variant)
  @options = options
  @custom_path = custom_path
end

Instance Attribute Details

#custom_pathObject (readonly)

Returns the value of attribute custom_path.



7
8
9
# File 'lib/railsui_icon/icon.rb', line 7

def custom_path
  @custom_path
end

#nameObject (readonly)

Returns the value of attribute name.



7
8
9
# File 'lib/railsui_icon/icon.rb', line 7

def name
  @name
end

#optionsObject (readonly)

Returns the value of attribute options.



7
8
9
# File 'lib/railsui_icon/icon.rb', line 7

def options
  @options
end

#variantObject (readonly)

Returns the value of attribute variant.



7
8
9
# File 'lib/railsui_icon/icon.rb', line 7

def variant
  @variant
end

Class Method Details

.render(**kwargs) ⇒ Object



154
155
156
# File 'lib/railsui_icon/icon.rb', line 154

def render(**kwargs)
  new(**kwargs).render
end

Instance Method Details

#renderObject



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

def render
  if custom_path
    render_custom_path(custom_path)
  else
    render_standard_icon
  end
rescue StandardError => e
  Rails.logger.error "Failed to render icon: #{e.message}"
  warning
end