Sha256: 2877dce3aa928ac61508107e1462de8f8103bb80b2fd2f1e9bd1c751ebbf9bc7

Contents?: true

Size: 1.27 KB

Versions: 2

Compression:

Stored size: 1.27 KB

Contents

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 = {}, **other)
          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

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
foundation-rails-helpers-0.0.4 lib/foundation/rails/helpers/element.rb
foundation-rails-helpers-0.0.3 lib/foundation/rails/helpers/element.rb