Sha256: a9518ed238435fc9683dff31f6c9c287e0eef11c4747f161f586f2186c118734

Contents?: true

Size: 957 Bytes

Versions: 10

Compression:

Stored size: 957 Bytes

Contents

require 'active_support/concern'

module Fortitude
  class Widget
    module Convenience
      def content_and_attributes_from_tag_arguments(content_or_attributes = nil, attributes = nil)
        if (! attributes) && content_or_attributes.kind_of?(Hash)
          [ nil, (content_or_attributes || { }) ]
        else
          [ content_or_attributes, (attributes || { }) ]
        end
      end

      def add_css_classes(classes_to_add, a = nil, b = nil)
        classes_to_add = Array(classes_to_add)
        content, attributes = content_and_attributes_from_tag_arguments(a, b)

        attributes = if attributes.has_key?('class')
          attributes.merge('class' => (Array(attributes['class'] || [ ]) + classes_to_add))
        else
          attributes.merge(:class => (Array(attributes[:class] || [ ]) + classes_to_add))
        end

        [ content, attributes ]
      end

      alias_method :add_css_class, :add_css_classes
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
fortitude-0.9.6-java lib/fortitude/widget/convenience.rb
fortitude-0.9.6 lib/fortitude/widget/convenience.rb
fortitude-0.9.5-java lib/fortitude/widget/convenience.rb
fortitude-0.9.5 lib/fortitude/widget/convenience.rb
fortitude-0.9.4-java lib/fortitude/widget/convenience.rb
fortitude-0.9.4 lib/fortitude/widget/convenience.rb
fortitude-0.9.3-java lib/fortitude/widget/convenience.rb
fortitude-0.9.3 lib/fortitude/widget/convenience.rb
fortitude-0.9.2-java lib/fortitude/widget/convenience.rb
fortitude-0.9.2 lib/fortitude/widget/convenience.rb