Sablon.Processor.Document.OperationConstruction (sablon v0.4.4)

Copy Markdown View Source

Walks the merge fields of a document part and turns them into statements.

Fields are consumed one at a time; block statements consume everything up to their end field, which is how nesting falls out naturally. Adjacent blocks of an if/elsIf/else chain share their delimiting fields: the else field ends one block and starts the next.

Summary

Functions

Consumes the next field and builds its statement.

Consumes fields until end_expression is reached and returns the enclosed block.

Like consume_block/2 but splits the region at every field matching one of sub_expr_patterns, returning one block per clause.

Creates a construction state for fields.

Builds every statement the fields describe.

Types

t()

@type t() :: %Sablon.Processor.Document.OperationConstruction{
  current: term() | nil,
  default_handler: module() | nil,
  fields: [term()],
  handlers: [module()]
}

Functions

consume(state, allow_insertion)

@spec consume(t(), boolean()) :: {struct() | nil, t()}

Consumes the next field and builds its statement.

allow_insertion is false while collecting the body of a block: the fields inside it are re-parsed for every copy, so building insertion statements for the original nodes would render them twice.

consume_block(state, end_expression)

@spec consume_block(t(), binary()) :: {Sablon.Processor.Document.Block.t(), t()}

Consumes fields until end_expression is reached and returns the enclosed block.

consume_multi_block(state, end_expression, sub_expr_patterns)

@spec consume_multi_block(t(), binary(), [Regex.t()]) ::
  {[Sablon.Processor.Document.Block.t()], t()}

Like consume_block/2 but splits the region at every field matching one of sub_expr_patterns, returning one block per clause.

new(fields, handlers, default_handler \\ nil)

@spec new([term()], [module()], module() | nil) :: t()

Creates a construction state for fields.

operations(state)

@spec operations(t()) :: [struct()]

Builds every statement the fields describe.