Class: Foundation::Rails::Helpers::Element
- Inherits:
-
Object
- Object
- Foundation::Rails::Helpers::Element
- Extended by:
- ActionView::Context, ActionView::Helpers
- Includes:
- ActionView::Context, ActionView::Helpers
- Defined in:
- lib/foundation/rails/helpers/element.rb
Instance Attribute Summary collapse
-
#attributes ⇒ Object
Returns the value of attribute attributes.
-
#content ⇒ Object
Returns the value of attribute content.
Instance Method Summary collapse
-
#attributes_merge(attributes = {}, defaults = {}, **other) ⇒ Object
If there is conflict while attempting to merge the attributes w/ the defaults and the key is the class then we’ll combine the classes passed in w/ the defaults…otherwise we’ll take the left side of the merge…
-
#initialize(attributes: {}, content: nil) {|_self| ... } ⇒ Element
constructor
A new instance of Element.
- #to_s ⇒ Object
Constructor Details
#initialize(attributes: {}, content: nil) {|_self| ... } ⇒ Element
Returns a new instance of Element.
28 29 30 31 32 33 |
# File 'lib/foundation/rails/helpers/element.rb', line 28 def initialize(attributes: {}, content: nil) @attributes = attributes @content = content yield self if block_given? end |
Instance Attribute Details
#attributes ⇒ Object
Returns the value of attribute attributes.
26 27 28 |
# File 'lib/foundation/rails/helpers/element.rb', line 26 def attributes @attributes end |
#content ⇒ Object
Returns the value of attribute content.
26 27 28 |
# File 'lib/foundation/rails/helpers/element.rb', line 26 def content @content end |
Instance Method Details
#attributes_merge(attributes = {}, defaults = {}, **other) ⇒ Object
If there is conflict while attempting to merge the attributes w/ the defaults and the key is the class then we’ll combine the classes passed in w/ the defaults…otherwise we’ll take the left side of the merge… this ensures that dropdown buttons always get the basic classes they need to display properly…
19 20 21 22 23 24 |
# File 'lib/foundation/rails/helpers/element.rb', line 19 def attributes_merge(attributes = {}, defaults = {}, **other) mergeable = %i[class] attributes.merge(defaults) do |key, left, right| key.in?(mergeable) ? [left, right].join(' ') : left end end |
#to_s ⇒ Object
35 36 37 |
# File 'lib/foundation/rails/helpers/element.rb', line 35 def to_s content_tag(tag_type, content, attributes_merge(attributes, default_attributes)) end |