Sha256: 490aeb4c99049f6ee3a26c5771154accfc7e98520db415416bb38aa282619fc4

Contents?: true

Size: 1.26 KB

Versions: 3

Compression:

Stored size: 1.26 KB

Contents

# encoding: utf-8

# Option default_attributes
#
# A hash of default attributes for tags (`{tag => {attribute => default_value}}`).
# Attributes of each tag will reverse merged with his default attributes, so you
# don't have to write over and over that script tag has attribute `type` with value
# `text/javascript`. For example, `%script` compiles to `<script type="text/javascript"></script>`.
# Defaults to `{script: {type: "text/javascript"}, form: {method: "POST"}}`

module Haml
  class Engine
    alias_method :__initialize__, :initialize
    def initialize(template, options = Hash.new)
      __initialize__(template, options)
      @options[:default_attributes] = Hash.new
      # symbolize keys
      @options[:default_attributes] = @options[:default_attributes].inject(Hash.new) do |options, pair|
        options.merge(pair.first.to_sym => pair.last)
      end
    end
  end

  module Precompiler
    alias_method :__prerender_tag__, :prerender_tag
    def prerender_tag(name, self_close, attributes)
      # merge given attributes with default attributes from options
      if default_attributes = @options[:default_attributes][name.to_sym]
        attributes = default_attributes.merge(attributes)
      end
      __prerender_tag__(name, self_close, attributes)
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
rango-0.2.3 lib/rango/templates/exts/haml.rb
rango-0.2.1 lib/rango/templates/exts/haml.rb
rango-0.2.1.pre lib/rango/templates/exts/haml.rb