23#include "../lib/exception.h"
27IfEqualNodeFactory::IfEqualNodeFactory() {}
34 if (expr.size() != 3) {
35 throw Cutelee::Exception(
37 QStringLiteral(
"%1 tag takes two arguments.").arg(expr.first()));
40 FilterExpression val1(expr.at(1), p);
41 FilterExpression val2(expr.at(2), p);
43 auto n =
new IfEqualNode(val1, val2, negate, p);
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);
64IfNotEqualNodeFactory::IfNotEqualNodeFactory() {}
68 return do_getNode(tagContent, p,
true);
81void IfEqualNode::setTrueList(
const NodeList &trueList)
83 m_trueList = trueList;
86void IfEqualNode::setFalseList(
const NodeList &falseList)
88 m_falseList = falseList;
93 auto var1 = m_var1.resolve(c);
94 auto var2 = m_var2.resolve(c);
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.
A FilterExpression object represents a filter expression in a template.
A list of Nodes with some convenience API for rendering them.
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.