21#include "templatetag.h"
23#include "../lib/exception.h"
24#include "cutelee_tags_p.h"
27TemplateTagNodeFactory::TemplateTagNodeFactory() {}
32 auto expr = tagContent.split(QLatin1Char(
' '), Qt::SkipEmptyParts);
38 QStringLiteral(
"'templatetag' statement takes one argument"));
41 auto name = expr.first();
43 if (!TemplateTagNode::isKeyword(name)) {
45 QStringLiteral(
"Not a template tag"));
57static QHash<QString, QString> getKeywordMap()
59 QHash<QString, QString> map;
60 map.insert(QStringLiteral(
"openblock"), QLatin1String(BLOCK_TAG_START));
61 map.insert(QStringLiteral(
"closeblock"), QLatin1String(BLOCK_TAG_END));
62 map.insert(QStringLiteral(
"openvariable"), QLatin1String(VARIABLE_TAG_START));
63 map.insert(QStringLiteral(
"closevariable"), QLatin1String(VARIABLE_TAG_END));
64 map.insert(QStringLiteral(
"openbrace"), QChar::fromLatin1(
'{'));
65 map.insert(QStringLiteral(
"closebrace"), QChar::fromLatin1(
'}'));
66 map.insert(QStringLiteral(
"opencomment"), QLatin1String(COMMENT_TAG_START));
67 map.insert(QStringLiteral(
"closecomment"), QLatin1String(COMMENT_TAG_END));
71bool TemplateTagNode::isKeyword(
const QString &name)
73 static auto map = getKeywordMap();
74 return map.contains(name);
80 static auto map = getKeywordMap();
81 (*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={})