Class: Temple::Filters::DynamicMerger
- Inherits:
-
Temple::Filter
- Object
- Temple::Filter
- Temple::Filters::DynamicMerger
- Defined in:
- lib/temple/filters/dynamic_merger.rb
Overview
Compile [:multi, [:static, ‘foo’], [:dynamic, ‘bar’]] to [:dynamic, ‘“foo#bar”’]
Constant Summary
Constants included from Utils
Utils::ESCAPE_HTML, Utils::ESCAPE_HTML_PATTERN
Instance Attribute Summary
Attributes included from Mixins::Options
Instance Method Summary collapse
Methods included from Mixins::Options
Methods included from Mixins::ControlFlowDispatcher
#on_block, #on_case, #on_cond, #on_if
Methods included from Mixins::EscapeDispatcher
Methods included from Mixins::CoreDispatcher
Methods included from Mixins::CompiledDispatcher
Methods included from Utils
#empty_exp?, #escape_html, #escape_html_safe, #indent_dynamic, #unique_name
Instance Method Details
#on_multi(*exps) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/temple/filters/dynamic_merger.rb', line 6 def on_multi(*exps) exps = exps.dup result = [:multi] buffer = [] until exps.empty? type, arg = exps.first if type == :dynamic && arg.count("\n") == 0 buffer << exps.shift elsif type == :static && exps.size > (count = arg.count("\n")) && exps[1, count].all? { |e| e == [:newline] } (1 + count).times { buffer << exps.shift } elsif type == :newline && exps.size > (count = count_newline(exps)) && exps[count].first == :static && count == exps[count].last.count("\n") (count + 1).times { buffer << exps.shift } else result.concat(merge_dynamic(buffer)) buffer = [] result << compile(exps.shift) end end result.concat(merge_dynamic(buffer)) result.size == 2 ? result[1] : result end |