Class: Sablon::Processor::Document::ConditionalHandler
- Inherits:
-
FieldHandler
- Object
- FieldHandler
- Sablon::Processor::Document::ConditionalHandler
- Defined in:
- lib/sablon/processor/document/field_handlers.rb
Overview
Handles conditional blocks in the template
Instance Method Summary collapse
- #build_statement(constructor, field, _options = {}) ⇒ Object
-
#initialize ⇒ ConditionalHandler
constructor
A new instance of ConditionalHandler.
Methods inherited from FieldHandler
Constructor Details
#initialize ⇒ ConditionalHandler
Returns a new instance of ConditionalHandler.
59 60 61 |
# File 'lib/sablon/processor/document/field_handlers.rb', line 59 def initialize super(/([^ ]+):if(?:\(([^)]+)\))?/) end |
Instance Method Details
#build_statement(constructor, field, _options = {}) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/sablon/processor/document/field_handlers.rb', line 63 def build_statement(constructor, field, = {}) expr_name = field.expression.match(@pattern).to_a[1] args = [ # end expression (first arg) "#{expr_name}:endIf", # sub block patterns to check for /(#{expr_name}):els[iI]f(?:\(([^)]+)\))?/, /(#{expr_name}):else/ ] blocks = process_blocks(constructor.consume_multi_block(*args)) Statement::Condition.new(blocks) end |