Class: Faml::Html

Inherits:
Temple::HTML::Fast
  • Object
show all
Defined in:
lib/faml/html.rb

Instance Method Summary collapse

Instance Method Details

#on_haml_attr(name, value) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/faml/html.rb', line 24

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

#on_haml_attrs(code) ⇒ Object



20
21
22
# File 'lib/faml/html.rb', line 20

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

#on_haml_doctype(type) ⇒ Object



49
50
51
52
53
# File 'lib/faml/html.rb', line 49

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

#on_haml_preserve(sym) ⇒ Object



55
56
57
# File 'lib/faml/html.rb', line 55

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

#on_haml_tag(name, self_closing, attrs, content = nil) ⇒ Object



10
11
12
13
14
15
16
17
18
# File 'lib/faml/html.rb', line 10

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}>"] unless closed
  result
end