Class: Temple::Filters::ControlFlow
Overview
Control flow filter which processes [:if, condition, yes-exp, no-exp] and [:block, code, content] expressions. This is useful for ruby code generation with lots of conditionals.
Constant Summary
Constants included
from Utils
Utils::ESCAPE_HTML, Utils::ESCAPE_HTML_PATTERN
Instance Attribute Summary
#options
Instance Method Summary
collapse
included, #initialize
#on_escape
#on_capture, #on_multi
#call, #compile
Methods included from Utils
#empty_exp?, #escape_html, #escape_html_safe, #indent_dynamic, #unique_name
Instance Method Details
#on_block(code, exp) ⇒ Object
35
36
37
38
39
40
|
# File 'lib/temple/filters/control_flow.rb', line 35
def on_block(code, exp)
[:multi,
[:code, code],
compile(exp),
[:code, 'end']]
end
|
#on_case(arg, *cases) ⇒ Object
21
22
23
24
25
26
27
28
29
|
# File 'lib/temple/filters/control_flow.rb', line 21
def on_case(arg, *cases)
result = [:multi, [:code, arg ? "case (#{arg})" : 'case']]
cases.map do |c|
condition, exp = c
result << [:code, condition == :else ? 'else' : "when #{condition}"] << compile(exp)
end
result << [:code, 'end']
result
end
|
#on_cond(*cases) ⇒ Object
31
32
33
|
# File 'lib/temple/filters/control_flow.rb', line 31
def on_cond(*cases)
on_case(nil, *cases)
end
|
#on_if(condition, yes, no = nil) ⇒ Object
10
11
12
13
14
15
16
17
18
19
|
# File 'lib/temple/filters/control_flow.rb', line 10
def on_if(condition, yes, no = nil)
result = [:multi, [:code, "if #{condition}"], compile(yes)]
while no && no.first == :if
result << [:code, "elsif #{no[1]}"] << compile(no[2])
no = no[3]
end
result << [:code, 'else'] << compile(no) if no
result << [:code, 'end']
result
end
|