module Foundation module Rails module Helpers class Element include ActionView::Helpers include ActionView::Context extend ActionView::Helpers extend ActionView::Context ## # 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... # def attributes_merge(attributes = {}, defaults = {}) mergeable = %i[class] attributes.merge(defaults) do |key, left, right| key.in?(mergeable) ? [left, right].join(' ') : left end end attr_accessor :attributes, :content def initialize(attributes: {}, content: nil) @attributes = attributes @content = content yield self if block_given? end def to_s content_tag(tag_type, content, attributes_merge(attributes, default_attributes)) end private def tag_type; :div; end def default_attributes; {}; end end end end end