Class: HasHelpers::Icon
- Inherits:
-
Object
- Object
- HasHelpers::Icon
- Defined in:
- lib/has_helpers/utils/icon.rb
Overview
typed: false frozen_string_literal: true
Instance Attribute Summary collapse
-
#attributes ⇒ Object
Returns an Array of attributes assigned to the current icon.
-
#name ⇒ Object
Returns the value of attribute name.
-
#orientation ⇒ Object
Returns the value of attribute orientation.
Attributes included from UIAttributes::HTMLAttributes
Instance Method Summary collapse
-
#initialize(icon_name, **options) ⇒ Icon
constructor
Handle options passed to new.
- #to_icon(**options) ⇒ Object
- #to_partial_path ⇒ Object
- #to_renderable ⇒ Object
-
#to_s ⇒ Object
(also: #skin)
Renders a string representation of the current Icon.
Methods included from UIAttributes::HTMLAttributes
Methods included from Attributes::GuardedAttributes
Methods included from Attributes::AttributeAssignment
Constructor Details
#initialize(icon_name, **options) ⇒ Icon
Handle options passed to new. Hash args are assigned to attributes like ActiveRecord does.
Examples
::HasHelpers::Icon.new("calendar") ::HasHelpers::Icon.new("plane", :orientation => :flip_horizontal) ::HasHelpers::Icon.new("plane", :orientation => "rotate-90")
16 17 18 19 |
# File 'lib/has_helpers/utils/icon.rb', line 16 def initialize(icon_name, **) self.name = icon_name assign_attributes(**) end |
Instance Attribute Details
#attributes ⇒ Object
Returns an Array of attributes assigned to the current icon. The result is mutable and may be used to append, remove or modify the current attributes.
Examples
icon = ::HasHelpers::Icon.new("calendar", :julian) icon.attributes # => [ :julian ]
icon.attributes << :reformed
icon.attributes # => [ :julian, :reformed ]
55 56 57 |
# File 'lib/has_helpers/utils/icon.rb', line 55 def attributes @attributes ||= Array(@attributes) end |
#name ⇒ Object
Returns the value of attribute name.
8 9 10 |
# File 'lib/has_helpers/utils/icon.rb', line 8 def name @name end |
#orientation ⇒ Object
Returns the value of attribute orientation.
8 9 10 |
# File 'lib/has_helpers/utils/icon.rb', line 8 def orientation @orientation end |
Instance Method Details
#to_icon(**options) ⇒ Object
21 22 23 24 |
# File 'lib/has_helpers/utils/icon.rb', line 21 def to_icon(**) assign_attributes(**) self end |
#to_partial_path ⇒ Object
63 64 65 |
# File 'lib/has_helpers/utils/icon.rb', line 63 def to_partial_path "has_helpers/icons/icon" end |
#to_renderable ⇒ Object
59 60 61 |
# File 'lib/has_helpers/utils/icon.rb', line 59 def to_renderable self end |
#to_s ⇒ Object Also known as: skin
Renders a string representation of the current Icon. This is currently set to render as Font Awesome class names but could be easily altered (perhaps using optional settings) if needed.
Examples
::HasHelpers::Icon.new("calendar").to_s #=> "fa fa-calendar" ::HasHelpers::Icon.new("calendar", :category_green).to_s #=> "fa fa-calendar category-green" ::HasHelpers::Icon.new("plane", :orientation => :flip_horizantal).to_s #=> "fa fa-plane fa-flip-horizontal" ::HasHelpers::Icon.new("plane", :category_green, :orientation => "rotate-90").to_s #=> "fa fa-plane fa-rotate-90 category-green" ::HasHelpers::Icon.new("plane", :attributes => [:category_green, :category_disabled], :orientation => "rotate-90").to_s #=> "fa fa-plane fa-rotate-90 category-green"
36 37 38 39 40 41 42 |
# File 'lib/has_helpers/utils/icon.rb', line 36 def to_s [ "fa fa-#{ name }", *("fa-#{orientation}" if orientation), *attributes ].join(" ").tr("_", "-") end |