class Foundation::Rails::Helpers::Element

Attributes

attributes[RW]
content[RW]

Public Class Methods

new(attributes: {}, content: nil) { |self| ... } click to toggle source
# File lib/foundation/rails/helpers/element.rb, line 28
def initialize(attributes: {}, content: nil)
  @attributes = attributes
  @content = content

  yield self if block_given?
end

Public Instance Methods

attributes_merge(attributes = {}, defaults = {}, **other) click to toggle source

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…

# 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() click to toggle source
# File lib/foundation/rails/helpers/element.rb, line 35
def to_s
  content_tag(tag_type, content, attributes_merge(attributes, default_attributes))
end

Private Instance Methods

default_attributes() click to toggle source
# File lib/foundation/rails/helpers/element.rb, line 43
def default_attributes; {}; end
tag_type() click to toggle source
# File lib/foundation/rails/helpers/element.rb, line 41
def tag_type; :div; end