Sha256: a70dafe9b2ce53dc3dafb411e19b54d106a210a5a66f57ecd8b8c6e23eebeb5e

Contents?: true

Size: 969 Bytes

Versions: 7

Compression:

Stored size: 969 Bytes

Contents

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

      default_options[:attr_delimiter] = {'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[:attr_delimiter][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

7 entries across 7 versions & 1 rubygems

Version Path
skim-0.8.6 lib/temple/coffee_script/filters/attribute_merger.rb
skim-0.8.5 lib/temple/coffee_script/filters/attribute_merger.rb
skim-0.8.4 lib/temple/coffee_script/filters/attribute_merger.rb
skim-0.8.3 lib/temple/coffee_script/filters/attribute_merger.rb
skim-0.8.2 lib/temple/coffee_script/filters/attribute_merger.rb
skim-0.8.1 lib/temple/coffee_script/filters/attribute_merger.rb
skim-0.8.0 lib/temple/coffee_script/filters/attribute_merger.rb