23 #include "../lib/exception.h"
27 IfEqualNodeFactory::IfEqualNodeFactory() {}
34 if (expr.size() != 3) {
37 QStringLiteral(
"%1 tag takes two arguments.").arg(expr.first()));
45 const QString endTag(QStringLiteral(
"end") + expr.first());
46 auto trueList = p->
parse(n, {QStringLiteral(
"else"), endTag});
47 n->setTrueList(trueList);
50 falseList = p->
parse(n, endTag);
51 n->setFalseList(falseList);
61 return do_getNode(tagContent, p,
false);
64 IfNotEqualNodeFactory::IfNotEqualNodeFactory() {}
68 return do_getNode(tagContent, p,
true);
81 void IfEqualNode::setTrueList(
const NodeList &trueList)
83 m_trueList = trueList;
86 void IfEqualNode::setFalseList(
const NodeList &falseList)
88 m_falseList = falseList;
96 auto equal =
equals(var1, var2);
98 if (((m_negate && !equal) || (!m_negate && equal)))
99 m_trueList.
render(stream, c);
101 m_falseList.
render(stream, c);
Q_INVOKABLE QStringList smartSplit(const QString &str) const
The Context class holds the context to render a Template with.
An exception for use when implementing template tags.
A FilterExpression object represents a filter expression in a template.
QVariant resolve(OutputStream *stream, Context *c) const
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
Node * getNode(const QString &tagContent, Parser *p) const override
bool equals(const QVariant &lhs, const QVariant &rhs)
QString content
The content of this Token.
Utility functions used throughout Cutelee.