23 #include "nulllocalizer_p.h"
24 #include "rendercontext.h"
28 #include <QtCore/QStringList>
37 : q_ptr(context), m_autoescape(
true), m_mutating(
false),
39 m_localizer(
new NullLocalizer)
41 m_variantHashStack.append(variantHash);
49 QList<QVariantHash> m_variantHashStack;
52 QList<std::pair<QString, QString>> m_externalMedia;
56 std::shared_ptr<AbstractLocalizer> m_localizer;
77 d_ptr->m_autoescape = other.d_ptr->m_autoescape;
78 d_ptr->m_externalMedia = other.d_ptr->m_externalMedia;
79 d_ptr->m_mutating = other.d_ptr->m_mutating;
80 d_ptr->m_variantHashStack = other.d_ptr->m_variantHashStack;
81 d_ptr->m_urlType = other.d_ptr->m_urlType;
82 d_ptr->m_relativeMediaPath = other.d_ptr->m_relativeMediaPath;
88 bool Context::autoEscape()
const
91 return d->m_autoescape;
94 void Context::setAutoEscape(
bool autoescape)
97 d->m_autoescape = autoescape;
106 for (
const QVariantHash &h : d->m_variantHashStack) {
107 auto it = h.constFind(str);
108 if (it != h.constEnd()) {
112 if (ret.userType() == qMetaTypeId<QString>()) {
113 ret = QVariant::fromValue<Cutelee::SafeString>(
127 const QHash<QString, QVariant> hash;
128 d->m_variantHashStack.prepend(hash);
135 d->m_variantHashStack.removeFirst();
142 d->m_variantHashStack[0].insert(name, variant);
149 d->m_variantHashStack[0].insert(name, QVariant::fromValue(
object));
152 QHash<QString, QVariant> Context::stackHash(
int depth)
const
156 return d->m_variantHashStack.value(depth);
159 bool Context::isMutating()
const
162 return d->m_mutating;
165 void Context::setMutating(
bool mutating)
168 d->m_mutating = mutating;
171 void Context::addExternalMedia(
const QString &absolutePart,
175 d->m_externalMedia.append({absolutePart, relativePart});
181 return d->m_externalMedia;
184 void Context::clearExternalMedia()
187 d->m_externalMedia.clear();
205 d->m_relativeMediaPath = path;
211 return d->m_relativeMediaPath;
217 return d->m_renderContext;
224 d->m_localizer = std::shared_ptr<AbstractLocalizer>(
new NullLocalizer);
233 return d->m_localizer;
The Context class holds the context to render a Template with.
RenderContext * renderContext() const
QString relativeMediaPath() const
std::shared_ptr< AbstractLocalizer > localizer() const
void setUrlType(UrlType type)
void insert(const QString &name, QObject *object)
void setLocalizer(std::shared_ptr< AbstractLocalizer > localizer)
Context & operator=(const Context &other)
virtual QVariant lookup(const QString &str) const
void setRelativeMediaPath(const QString &relativePath)
QList< std::pair< QString, QString > > externalMedia() const
@ AbsoluteUrls
Absolute URLs should be put in the template.
Provides storage facility for state while rendering a template.
The Cutelee namespace holds all public Cutelee API.
Cutelee::SafeString getSafeString(const QVariant &input)
Utility functions used throughout Cutelee.