Class: Sablon::Processor::Document::FieldHandler
- Inherits:
-
Object
- Object
- Sablon::Processor::Document::FieldHandler
- Defined in:
- lib/sablon/processor/document/field_handlers.rb
Overview
This class is used to setup field handlers to process different merge field expressions based on the expression text. The #handles? and #build_statement methods form the standard FieldHandler API and can be implemented however they are needed to be as long as the call signature stays the same.
Direct Known Subclasses
CommentHandler, ConditionalHandler, EachLoopHandler, ImageHandler, InsertionHandler
Instance Method Summary collapse
-
#build_statement(constructor, field, options = {}) ⇒ Object
Uses the provided arguments to construct a Statement object.
-
#handles?(field) ⇒ Boolean
Returns a non-nil value if the field expression matches the pattern.
-
#initialize(pattern) ⇒ FieldHandler
constructor
Used when registering processors.
Constructor Details
#initialize(pattern) ⇒ FieldHandler
Used when registering processors. The pattern tells the handler what expression text to search for.
12 13 14 |
# File 'lib/sablon/processor/document/field_handlers.rb', line 12 def initialize(pattern) @pattern = pattern end |
Instance Method Details
#build_statement(constructor, field, options = {}) ⇒ Object
Uses the provided arguments to construct a Statement object. The constructor is an instance of the OperationConstruction class, the field is the current merge field being evaluated and the options hash defines any other parameters passed in during OperationConstruction#consume. Currently the only option passed is ‘:allow_insertion`.
27 |
# File 'lib/sablon/processor/document/field_handlers.rb', line 27 def build_statement(constructor, field, = {}); end |
#handles?(field) ⇒ Boolean
Returns a non-nil value if the field expression matches the pattern
17 18 19 |
# File 'lib/sablon/processor/document/field_handlers.rb', line 17 def handles?(field) field.expression.match(@pattern) end |