Class: Foundation::Rails::Helpers::Element

Inherits:
Object
  • Object
show all
Extended by:
ActionView::Context, ActionView::Helpers
Includes:
ActionView::Context, ActionView::Helpers
Defined in:
lib/foundation/rails/helpers/element.rb

Direct Known Subclasses

Alert, Label, Panel, Tooltip

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes: {}, content: nil) {|_self| ... } ⇒ Element

Returns a new instance of Element.

Yields:

  • (_self)

Yield Parameters:



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

#attributesObject

Returns the value of attribute attributes.



26
27
28
# File 'lib/foundation/rails/helpers/element.rb', line 26

def attributes
  @attributes
end

#contentObject

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_sObject



35
36
37
# File 'lib/foundation/rails/helpers/element.rb', line 35

def to_s
  (tag_type, content, attributes_merge(attributes, default_attributes))
end