Class: LiquidLint::Filters::ControlProcessor
- Inherits:
-
Liquid::Filter
- Object
- Liquid::Filter
- LiquidLint::Filters::ControlProcessor
- Defined in:
- lib/liquid_lint/filters/control_processor.rb
Overview
A dumbed-down version of Liquid::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
-
#on_liquid_control(code, content) ⇒ Object
Handle control expression ‘[:liquid, :control, code, content]`.
-
#on_liquid_output(_escape, code, content) ⇒ Array
Handle output expression ‘[:liquid, :output, escape, code, content]`.
-
#on_liquid_text(_type, content) ⇒ Array
Handle text expression ‘[:liquid, :text, type, content]`.
Instance Method Details
#on_liquid_control(code, content) ⇒ Object
Handle control expression ‘[:liquid, :control, code, content]`
14 15 16 17 18 |
# File 'lib/liquid_lint/filters/control_processor.rb', line 14 def on_liquid_control(code, content) [:multi, [:code, code], compile(content)] end |
#on_liquid_output(_escape, code, content) ⇒ Array
Handle output expression ‘[:liquid, :output, escape, code, content]`
26 27 28 29 30 31 32 33 34 |
# File 'lib/liquid_lint/filters/control_processor.rb', line 26 def on_liquid_output(_escape, code, content) if code[BLOCK_RE] [:multi, [:code, code, compile(content)], [:code, 'end']] else [:multi, [:dynamic, code], compile(content)] end end |
#on_liquid_text(_type, content) ⇒ Array
Handle text expression ‘[:liquid, :text, type, content]`
41 42 43 44 45 |
# File 'lib/liquid_lint/filters/control_processor.rb', line 41 def on_liquid_text(_type, content) # Ensures :newline expressions from static output are still represented in # the final expression compile(content) end |