Sha256: cffe2f7610975faf7bb8a773826148f33df4c5a914a7896bad4ed375d70724c8

Contents?: true

Size: 1.67 KB

Versions: 13

Compression:

Stored size: 1.67 KB

Contents

require 'faml/attribute_builder'

module Faml
  class Html < Temple::HTML::Fast
    def on_haml_tag(name, self_closing, attrs, content = nil)
      name = name.to_s
      closed = self_closing && (!content || empty_exp?(content))
      result = [:multi, [:static, "<#{name}"], compile(attrs)]
      result << [:static, (closed && @format != :html ? ' /' : '') + '>']
      result << compile(content) if content
      result << [:static, "</#{name}>"] if !closed
      result
    end

    def on_haml_attrs(code)
      [:dynamic, "::Faml::AttributeBuilder.build(#{options[:attr_quote].inspect}, #{code})"]
    end

    def on_haml_attr(name, value)
      if empty_exp?(value)
        if @format == :html
          [:static, " #{name}"]
        else
          [:static, " #{name}=#{options[:attr_quote]}#{name}#{options[:attr_quote]}"]
        end
      elsif value[0] == :dvalue
        sym = unique_name
        [:multi,
          [:code, "#{sym} = (#{value[1]})"],
          [:case, sym,
            ['true', [:static, " #{name}"]],
            ['false, nil', [:multi]],
            [:else, [:multi,
              [:static, " #{name}=#{options[:attr_quote]}"],
              [:escape, true, [:dynamic, sym]],
              [:static, options[:attr_quote]],
            ]],
          ],
        ]
      else
        [:multi,
          [:static, " #{name}=#{options[:attr_quote]}"],
          compile(value),
          [:static, options[:attr_quote]]]
      end
    end

    def on_haml_doctype(type)
      compile([:html, :doctype, type])
    rescue Temple::FilterError
      [:multi]
    end

    def on_haml_preserve(sym)
      [:dynamic, "::Faml::Compiler.find_and_preserve(#{sym}.to_s)"]
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
faml-0.2.12 lib/faml/html.rb
faml-0.2.11 lib/faml/html.rb
faml-0.2.10 lib/faml/html.rb
faml-0.2.9 lib/faml/html.rb
faml-0.2.8 lib/faml/html.rb
faml-0.2.7 lib/faml/html.rb
faml-0.2.6 lib/faml/html.rb
faml-0.2.5 lib/faml/html.rb
faml-0.2.4 lib/faml/html.rb
faml-0.2.3 lib/faml/html.rb
faml-0.2.2 lib/faml/html.rb
faml-0.2.1 lib/faml/html.rb
faml-0.2.0 lib/faml/html.rb