Cutelee
6.1.0
|
Base class for all NodeFactories. More...
#include <cutelee/node.h>
Public Member Functions | |
AbstractNodeFactory (QObject *parent={}) | |
~AbstractNodeFactory () override | |
virtual Node * | getNode (const QString &tagContent, Parser *p) const =0 |
Protected Member Functions | |
QList< FilterExpression > | getFilterExpressionList (const QStringList &list, Parser *p) const |
Q_INVOKABLE QStringList | smartSplit (const QString &str) const |
This class can be used to make custom tags available to templates. The getNode method should be implemented to return a Node to be rendered.
A node is represented in template markup as content surrounded by percent signed tokens.
It is the responsibility of an AbstractNodeFactory implementation to process the contents of a tag and return a Node implementation from its getNode method.
The getNode method would for example be called with the tagContent "some_tag arg1 arg2
". That content could then be split up, the arguments processed and a Node created
The getNode implementation might also advance the parser. For example if we had a {% times %}
tag which rendered content the amount of times it was given in its argument, it could be used like this:
The argument to {% times %}
might not be a simple number, but could be a FilterExpression such as "someobject.some_property|getDigit:1
".
The implementation could look like
Note that it is necessary to invoke the parser to create the child nodes only after creating the Node to return. That node must be passed to the Parser to perform as the parent QObject to the child nodes.
|
explicit |
|
override |
|
protected |
Returns a list of FilterExpression objects created with Parser p
as described by the content of list
.
This is used for convenience when handling the arguments to a tag.
Definition at line 192 of file node.cpp.
Referenced by CycleNodeFactory::getNode(), FirstOfNodeFactory::getNode(), IfChangedNodeFactory::getNode(), and MediaFinderNodeFactory::getNode().
|
pure virtual |
This method should be reimplemented to return a Node which can be rendered.
The tagContent
is the content of the tag including the tag name and arguments. For example, if the template content is {% my_tag arg1 arg2 %}
, the tagContent will be "my_tag arg1 arg2".
The Parser p
is available and can be advanced if appropriate. For example, if the tag has an end tag, the parser can be advanced to the end tag.
Implemented in ScriptableNodeFactory, IncludeNodeFactory, ExtendsNodeFactory, BlockNodeFactory, WithLocaleNodeFactory, L10nMoneyVarNodeFactory, L10nMoneyNodeFactory, L10nFileSizeVarNodeFactory, L10nFileSizeNodeFactory, I18npVarNodeFactory, I18npNodeFactory, I18ncpVarNodeFactory, I18ncpNodeFactory, I18ncVarNodeFactory, I18ncNodeFactory, I18nVarNodeFactory, I18nNodeFactory, WithNodeFactory, WidthRatioNodeFactory, TemplateTagNodeFactory, SpacelessNodeFactory, RegroupNodeFactory, RangeNodeFactory, NowNodeFactory, MediaFinderNodeFactory, LoadNodeFactory, IfNotEqualNodeFactory, IfEqualNodeFactory, IfChangedNodeFactory, IfNodeFactory, ForNodeFactory, FirstOfNodeFactory, FilterNodeFactory, DebugNodeFactory, CycleNodeFactory, CommentNodeFactory, and AutoescapeNodeFactory.
|
protected |
Splits str
into a list, taking quote marks into account.
This is typically used in the implementation of getNode with the tagContent.
If str
is 'one "two three" four 'five " six' seven', the returned list will contain the following strings:
Definition at line 202 of file node.cpp.
Referenced by CycleNodeFactory::getNode(), FirstOfNodeFactory::getNode(), ForNodeFactory::getNode(), IfNodeFactory::getNode(), MediaFinderNodeFactory::getNode(), RangeNodeFactory::getNode(), WidthRatioNodeFactory::getNode(), WithNodeFactory::getNode(), I18nNodeFactory::getNode(), I18nVarNodeFactory::getNode(), I18ncNodeFactory::getNode(), I18ncVarNodeFactory::getNode(), I18ncpNodeFactory::getNode(), I18ncpVarNodeFactory::getNode(), I18npNodeFactory::getNode(), I18npVarNodeFactory::getNode(), L10nFileSizeNodeFactory::getNode(), L10nFileSizeVarNodeFactory::getNode(), L10nMoneyNodeFactory::getNode(), L10nMoneyVarNodeFactory::getNode(), WithLocaleNodeFactory::getNode(), ExtendsNodeFactory::getNode(), and IncludeNodeFactory::getNode().