# Transformers
# Overview
Transformers allow to simplify certain repetitive patterns in the ZML.
Transformers are invoked automatically for all ZML, including named parameters in ZSS.
The available transformers are described in this chapter.
# Children
# Purpose
The Children transformer allows to provide children tags as unnamed children, without explicitly specifying the
children
or child
named parameter.
# Transformation
# Simplified ZML
# Explicit ZML
# Conditions
Applied to class tags that satisfy all of the following criteria:
- Has unnamed children tags.
- Has a named parameter by the name of
children
orchild
.
# Additional Logic
- If the parent widget has both a
child
parameter and achildren
parameter, then:- If there are two or more unnamed children - then the
children
parameter will be used. - Otherwise - the
child
parameter is used.
- If there are two or more unnamed children - then the
- Otherwise, if only the
child
parameter is available, and two or more unnamed children are provided - then an error is logged and the transformation aborts.
# Text
# Purpose
The Text transformer allows to:
- Provide text directly inside the
<Text>
tag without explicitly specifying the positional parameter. - Provide interpolated text instead of a Dart expression.
# Transformation
# Simplified ZML
# Explicit ZML
# Conditions
Applied to Text tags that satisfy all of the following criteria:
- Has text.
- Has no unnamed children tags.
- Does not have the first positional parameter explicitly specified:
- In a
<:0->
positional parameter tag. - Or in a
z-bind:0
attribute.
- In a
# Additional Logic
First, all XML comments are removed. Everything between <!--
and -->
is removed, according to standard XML rules.
EVEN INSIDE MUSTACHE
Comments are removed before the text is parsed and processed, so they get removed even if according to Dart rules they would not.
# Example
# Builder
# Text Processing
Then, the text is processed in multiple steps, in the following order:
First, the text is broken into parts, where each part is either a mustache section, or text.
For example, the content Hello {{ name }}!
will be broken into three parts:
Hello
{{ name }}
!
Then, ezFlap iterates over the parts.
The mustached parts are converted to a Dart interpolation string, e.g. ${ name }
.
Non-mustached parts are processed in multiple steps, in the following order:
<
is changed to<
.>
is changed to>
.&
is changed to&
.- Newlines are replaced with spaces (each newline is replaced with a single space).
\r\n
is also replaced with a single space.
- Multiple consecutive spaces are replaced with a single space.
- If the text part is the first one (i.e. the text before the first mustache) - it is trimmed on the left.
- If the text part is the last one - it is trimmed on the right.
<br/>
is changed to a newline.- For each newline followed by a space the space is removed.
- E.g. so that
a<br/> b
will givea\nb
and nota\n b
.
- E.g. so that
- For each
that has preceding and/or following spaces - the spaces are removed.
is changed to a space.
# TextSpan
# Purpose
The TextSpan transformer does for <TextSpan>
the same thing it does for <Text>
.
The interpolated text is passed to its text
named parameter.
# Transformation
# Simplified ZML
# Explicit ZML
# Conditions
Applied to TextSpan tags that satisfy all of the following criteria:
- Has text.
- Has no unnamed children tags.
- Does not have the
text
named parameter explicitly specified:- In a
<text->
named parameter tag. - In a
z-bind:text
attribute. - In a
text
interpolated string attribute.
- In a
# Additional Logic
Applies the same logic as the Text transformer.
← Life-Cycle Props →