Sha256: 35789702a79f577c28a969c138a2ad1aea8b42de06b6b08eea89e1cc88738586

Contents?: true

Size: 1.26 KB

Versions: 1

Compression:

Stored size: 1.26 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 = {})
          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

1 entries across 1 versions & 1 rubygems

Version Path
foundation-rails-helpers-0.0.2 lib/foundation/rails/helpers/element.rb