23 #include "../lib/exception.h" 26 WithNodeFactory::WithNodeFactory() {}
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) {
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));
NodeList parse(Node *parent, const QStringList &stopAt={})
The Context class holds the context to render a Template with.
const_reference at(qsizetype i) const const
qsizetype size() const const
Node * getNode(const QString &tagContent, Parser *p) const override
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.
A list of Nodes with some convenience API for rendering them.
A FilterExpression object represents a filter expression in a template.
Q_INVOKABLE QStringList smartSplit(const QString &str) const
void render(OutputStream *stream, Context *c) const override
void insert(const QString &name, QObject *object)
void render(OutputStream *stream, Context *c) const
An exception for use when implementing template tags.