23 #include "../lib/exception.h"
26 WithNodeFactory::WithNodeFactory() {}
30 const QStringList expr =
smartSplit(tagContent);
31 std::vector<std::pair<QString, FilterExpression> > namedExpressions;
33 if (expr.size() != 4 || expr.at(2) != QStringLiteral(
"as")) {
34 bool newSyntax =
false;
35 for (
int i = 1; i < expr.size(); ++i) {
36 const auto parts = expr.at(i).split(QLatin1Char(
'='));
37 if (parts.size() == 2) {
38 namedExpressions.push_back({ parts.at(0),
FilterExpression(parts.at(1), p) });
48 TagSyntaxError, QStringLiteral(
"%1 expected format is 'name=value' or 'value as name'")
55 auto n =
new WithNode(namedExpressions, p);
56 auto nodeList = p->
parse(n, QStringLiteral(
"endwith"));
57 n->setNodeList(nodeList);
63 WithNode::WithNode(
const std::vector<std::pair<QString, FilterExpression> > &namedExpressions,
66 , m_namedExpressions(namedExpressions)
71 void WithNode::setNodeList(
const NodeList &nodeList) { m_list = nodeList; }
76 for (
const auto &pair : m_namedExpressions) {
77 c->
insert(pair.first, pair.second.resolve(c));
Q_INVOKABLE QStringList smartSplit(const QString &str) const
The Context class holds the context to render a Template with.
void insert(const QString &name, QObject *object)
An exception for use when implementing template tags.
A FilterExpression object represents a filter expression in a template.
A list of Nodes with some convenience API for rendering them.
void render(OutputStream *stream, Context *c) const
Base class for all nodes.
The OutputStream class is used to render templates to a QTextStream.
The Parser class processes a string template into a tree of nodes.
NodeList parse(Node *parent, const QStringList &stopAt={})
Node * getNode(const QString &tagContent, Parser *p) const override
void render(OutputStream *stream, Context *c) const override