Class: SlimLint::Filters::ControlProcessor

Inherits:
Slim::Filter
  • Object
show all
Defined in:
lib/slim_lint/filters/control_processor.rb

Overview

A dumbed-down version of Slim::Controls which doesn’t introduce temporary variables and other cruft (which in the context of extracting Ruby code, results in a lot of weird cops reported by RuboCop).

Constant Summary collapse

BLOCK_RE =
/\A(if|unless)\b|\bdo\s*(\|[^\|]*\|)?\s*$/

Instance Method Summary collapse

Instance Method Details

#on_slim_control(code, content) ⇒ Object

Handle control expression ‘[:slim, :control, code, content]`

Parameters:

  • code (String)
  • content (Array)


14
15
16
17
18
# File 'lib/slim_lint/filters/control_processor.rb', line 14

def on_slim_control(code, content)
  [:multi,
    [:code, code],
    compile(content)]
end

#on_slim_output(_escape, code, content) ⇒ Array

Handle output expression ‘[:slim, :output, escape, code, content]`

Parameters:

  • _escape (Boolean)
  • code (String)
  • content (Array)

Returns:

  • (Array)

    Array



26
27
28
29
30
31
32
33
34
# File 'lib/slim_lint/filters/control_processor.rb', line 26

def on_slim_output(_escape, code, content)
  if code[BLOCK_RE]
    [:multi,
      [:code, code, compile(content)],
      [:code, 'end']]
  else
    [:multi, [:dynamic, code], compile(content)]
  end
end

#on_slim_text(_type, content) ⇒ Array

Handle text expression ‘[:slim, :text, type, content]`

Parameters:

  • _type (Symbol)
  • content (Array)

Returns:

  • (Array)


41
42
43
44
45
# File 'lib/slim_lint/filters/control_processor.rb', line 41

def on_slim_text(_type, content)
  # Ensures :newline expressions from static output are still represented in
  # the final expression
  compile(content)
end