24#include "blockcontext.h"
27#include "nodebuiltins_p.h"
29#include "rendercontext.h"
35ExtendsNodeFactory::ExtendsNodeFactory(
QObject *parent)
47 QStringLiteral(
"Error: Include tag takes only one argument"));
57 TagSyntaxError, QStringLiteral(
"Extends tag is not in a template."));
59 const auto nodeList = p->
parse(t);
60 n->setNodeList(nodeList);
65 QStringLiteral(
"Extends tag may only appear once in a template."));
72 :
Node(parent), m_filterExpression(fe)
76ExtendsNode::~ExtendsNode() {}
85 for (; it != end; ++it) {
86 map.
insert((*it)->name(), *it);
92void ExtendsNode::setNodeList(
const NodeList &list)
96 const auto blockList = m_list.
findChildren<BlockNode *>();
97 m_blocks = createNodeMap(blockList);
102 const auto parentVar = m_filterExpression.resolve(c);
103 if (parentVar.userType() == qMetaTypeId<Cutelee::Template>()) {
104 return parentVar.value<Template>();
111 const auto t = ti->engine()->loadByName(parentName);
114 throw Cutelee::Exception(
116 QStringLiteral(
"Template not found %1").arg(parentName));
119 throw Cutelee::Exception(t->error(), t->errorString());
126 const auto parentTemplate = getParent(c);
128 if (!parentTemplate) {
130 QStringLiteral(
"Cannot load template."));
135 blockContext.addBlocks(m_blocks);
138 const auto nodeList = parentTemplate->nodeList();
140 const auto parentBlocks
141 = createNodeMap(parentTemplate->findChildren<
BlockNode *>());
143 for (
auto n : nodeList) {
148 blockContext.addBlocks(parentBlocks);
155 parentTemplate->nodeList().render(stream, c);
157 auto nodes = parentTemplate->findChildren<
BlockNode *>();
158 blockContext.remove(nodes);
162void ExtendsNode::appendNode(
Node *node)
Base class for all NodeFactories.
Q_INVOKABLE QStringList smartSplit(const QString &str) const
The Context class holds the context to render a Template with.
RenderContext * renderContext() const
An exception for use when implementing template tags.
A FilterExpression object represents a filter expression in a template.
A list of Nodes with some convenience API for rendering them.
QList< T > findChildren()
void append(Cutelee::Node *node)
Base class for all nodes.
TemplateImpl * containerTemplate() const
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={})
QVariant & data(const Node *const scopeNode)
The Template class is a tree of nodes which may be rendered.
Node * getNode(const QString &tagContent, Parser *p) const override
void render(OutputStream *stream, Context *c) const override
The Cutelee namespace holds all public Cutelee API.
Cutelee::SafeString getSafeString(const QVariant &input)
iterator insert(const Key &key, const T &value)
const_iterator constBegin() const const
const_iterator constEnd() const const
QObject * parent() const const
T qobject_cast(QObject *object)
void setParent(QObject *parent)
void setValue(const T &value)
Utility functions used throughout Cutelee.