Class: Slimi::Filters::DoInserter

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

Overview

Append missing ‘do` to embedded Ruby code.

Constant Summary collapse

VALID_RUBY_LINE_REGEXP =
/(\A(if|unless|else|elsif|when|begin|rescue|ensure|case)\b)|\bdo\s*(\|[^|]*\|\s*)?\Z/.freeze

Instance Method Summary collapse

Methods inherited from Base

#on_slimi_embedded, #on_slimi_position, #on_slimi_text

Instance Method Details

#on_slimi_control(code, expression) ⇒ Array

Parameters:

  • code (String)
  • expressio (Array)

Returns:

  • (Array)


12
13
14
15
# File 'lib/slimi/filters/do_inserter.rb', line 12

def on_slimi_control(code, expression)
  code += ' do' unless code.match?(VALID_RUBY_LINE_REGEXP) || empty_exp?(expression)
  [:slimi, :control, code, compile(expression)]
end

#on_slimi_output(escape, code, expression) ⇒ Array

Parameters:

  • escape (Boolean)
  • code (String)
  • expression (Array)

Returns:

  • (Array)


21
22
23
24
# File 'lib/slimi/filters/do_inserter.rb', line 21

def on_slimi_output(escape, code, expression)
  code += ' do' unless code.match?(VALID_RUBY_LINE_REGEXP) || empty_exp?(expression)
  [:slimi, :output, escape, code, compile(expression)]
end