Class: Anyicon::Icon
Overview
The Icon class is responsible for managing the rendering of icons from various collections available on GitHub. It handles downloading and caching of icons to ensure they are available for use in a Ruby on Rails application.
Example usage:
icon = Anyicon::Icon.new(icon: 'fontawesome_regular:address-book')
icon.render
The class supports additional properties that can be passed in to customize the SVG elements.
Class Method Summary collapse
-
.render(**kwargs) ⇒ String
Renders the SVG content for the specified icons.
Instance Method Summary collapse
-
#initialize(icon:, **props) ⇒ Icon
constructor
Initializes a new Icon instance.
-
#render ⇒ String
Renders the SVG content for the specified icons.
Methods inherited from Common
Constructor Details
#initialize(icon:, **props) ⇒ Icon
Initializes a new Icon instance.
24 25 26 27 28 |
# File 'lib/anyicon/icon.rb', line 24 def initialize(icon:, **props) super() @icons = icon.split(',').map { |i| i.split(':') } @props = props end |
Class Method Details
.render(**kwargs) ⇒ String
Renders the SVG content for the specified icons.
118 119 120 |
# File 'lib/anyicon/icon.rb', line 118 def render(**kwargs) new(**kwargs).render end |
Instance Method Details
#render ⇒ String
Renders the SVG content for the specified icons.
33 34 35 36 37 38 39 40 |
# File 'lib/anyicon/icon.rb', line 33 def render result = ''.html_safe @icons.each do |icon| ensure_icon_exists(icon) result.concat(svg_content(icon).html_safe) end result end |