Class: Slimi::Filters::EndInserter

Inherits:
Base
  • Object
show all
Defined in:
lib/slimi/filters/end_inserter.rb

Overview

Append missing ‘end` line to embedded Ruby code in control block.

Defined Under Namespace

Classes: Expression

Instance Method Summary collapse

Methods inherited from Base

#on_slimi_control, #on_slimi_embedded, #on_slimi_output, #on_slimi_position, #on_slimi_text

Instance Method Details

#on_multi(*expressions) ⇒ Object

Parameters:

  • expressions (Array<Array>)


8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/slimi/filters/end_inserter.rb', line 8

def on_multi(*expressions)
  result = [:multi]
  prev_indent = false
  expressions.each do |source|
    expression = Expression.new(source)
    if expression.control?
      raise ::Temple::FilterError, 'Explicit end statements are forbidden.' if expression.end?

      result << code_end if prev_indent && !expression.else?

      prev_indent = expression.if?
    elsif !expression.newline? && prev_indent
      result << code_end
      prev_indent = false
    end

    result << compile(source)
  end

  result << code_end if prev_indent
  result
end