Sha256: 04b1d39fe8b900364009b730f385b91d4300e6045b12aef7aa3fedf9a0ba262e

Contents?: true

Size: 962 Bytes

Versions: 6

Compression:

Stored size: 962 Bytes

Contents

module Temple
  module CoffeeScript
    class AttributeMerger < Filter
      include Temple::HTML::Dispatcher

      define_options :merge_attrs => {'id' => '_', 'class' => ' '}

      def on_html_attrs(*attrs)
        names = []
        result = {}

        attrs.each do |html, attr, name, value|
          raise(InvalidExpression, 'Attribute is not a html attr') if html != :html || attr != :attr
          name = name.to_s
          if delimiter = options[:merge_attrs][name]
            if current = result[name]
              current << [:static, delimiter] << value
            else
              result[name] = [:multi, value]
              names << name
            end
          else
            raise "Multiple #{name} attributes specified" if result[name]
            result[name] = value
            names << name
          end
        end

        [:html, :attrs, *names.map {|name| [:html, :attr, name, result[name]]}]
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
skim-0.11.0 lib/temple/coffee_script/filters/attribute_merger.rb
skim-0.10.0 lib/temple/coffee_script/filters/attribute_merger.rb
skim-0.9.3 lib/temple/coffee_script/filters/attribute_merger.rb
skim-0.9.2 lib/temple/coffee_script/filters/attribute_merger.rb
skim-0.9.1 lib/temple/coffee_script/filters/attribute_merger.rb
skim-0.9.0 lib/temple/coffee_script/filters/attribute_merger.rb