21 #include "templatetag.h"
23 #include "../lib/exception.h"
24 #include "cutelee_tags_p.h"
27 TemplateTagNodeFactory::TemplateTagNodeFactory() {}
32 #if QT_VERSION < QT_VERSION_CHECK(5, 14, 0)
33 auto expr = tagContent.split(QLatin1Char(
' '), QString::SkipEmptyParts);
35 auto expr = tagContent.split(QLatin1Char(
' '), Qt::SkipEmptyParts);
42 QStringLiteral(
"'templatetag' statement takes one argument"));
45 auto name = expr.first();
47 if (!TemplateTagNode::isKeyword(name)) {
49 QStringLiteral(
"Not a template tag"));
61 static QHash<QString, QString> getKeywordMap()
63 QHash<QString, QString> map;
64 map.insert(QStringLiteral(
"openblock"), QLatin1String(BLOCK_TAG_START));
65 map.insert(QStringLiteral(
"closeblock"), QLatin1String(BLOCK_TAG_END));
66 map.insert(QStringLiteral(
"openvariable"), QLatin1String(VARIABLE_TAG_START));
67 map.insert(QStringLiteral(
"closevariable"), QLatin1String(VARIABLE_TAG_END));
68 map.insert(QStringLiteral(
"openbrace"), QChar::fromLatin1(
'{'));
69 map.insert(QStringLiteral(
"closebrace"), QChar::fromLatin1(
'}'));
70 map.insert(QStringLiteral(
"opencomment"), QLatin1String(COMMENT_TAG_START));
71 map.insert(QStringLiteral(
"closecomment"), QLatin1String(COMMENT_TAG_END));
75 bool TemplateTagNode::isKeyword(
const QString &name)
77 static auto map = getKeywordMap();
78 return map.contains(name);
84 static auto map = getKeywordMap();
85 (*stream) << map.value(m_name);
The Context class holds the context to render a Template with.
An exception for use when implementing template tags.
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.
Node * getNode(const QString &tagContent, Parser *p) const override
void render(OutputStream *stream, Context *c) const override
TemplateTagNode(const QString &tagName, QObject *parent={})