Cutelee
6.1.0
|
The Context class holds the context to render a Template with. More...
#include <cutelee/context.h>
Public Types | |
enum | UrlType { AbsoluteUrls , RelativeUrls } |
Public Member Functions | |
Context () | |
Context (const Context &other) | |
Context (const QVariantHash &hash) | |
virtual | ~Context () |
QList< std::pair< QString, QString > > | externalMedia () const |
void | insert (const QString &name, const QVariant &variant) |
void | insert (const QString &name, QObject *object) |
std::shared_ptr< AbstractLocalizer > | localizer () const |
virtual QVariant | lookup (const QString &str) const |
Context & | operator= (const Context &other) |
void | pop () |
void | push () |
QString | relativeMediaPath () const |
RenderContext * | renderContext () const |
void | setLocalizer (std::shared_ptr< AbstractLocalizer > localizer) |
void | setRelativeMediaPath (const QString &relativePath) |
void | setUrlType (UrlType type) |
UrlType | urlType () const |
For application developers, using the Context class is a matter of inserting keys and values as appropriate for rendering a Template using the insert method.
Note that one Template may be rendered multiple times with different contexts. Note also that any QVariant may be inserted into a Context object. Most commonly, QObjects will be used here.
For template tag developers, some other Context API is relevant.
It is possible to push and pop layers of context while a template is being rendered. This is useful if your template tag makes additional variables temporarily available in a part of a template. Template tags should only modify layers of context that they push themselves, and should pop any layers created before finishing its rendering step.
See for example the {% with %}
tag. In a template such as
In this case, lowerName is available in the context only between the {% with %}
and {% endwith %}
tags. The implementation of the {% with %}
tag render method is:
Note that a Context may temporarily override a variable in a parent context. This is why it is important to push a new context when adding items to context and pop it when finished.
Context::Context | ( | ) |
Creates an empty context
Definition at line 60 of file context.cpp.
|
explicit |
Sets every key in the hash as a property name with the variant as the value.
Definition at line 62 of file context.cpp.
Context::Context | ( | const Context & | other | ) |
Copy Constructor
Definition at line 67 of file context.cpp.
|
virtual |
Destructor
Definition at line 86 of file context.cpp.
Returns the external media encountered in the Template while rendering.
Definition at line 178 of file context.cpp.
Insert the context object variant
identified by name
into the Context.
Definition at line 138 of file context.cpp.
void Context::insert | ( | const QString & | name, |
QObject * | object | ||
) |
Insert the context object object
identified by name
into the Context.
Definition at line 145 of file context.cpp.
Referenced by CycleNode::render(), FilterNode::render(), ForNode::render(), IfChangedNode::render(), RangeNode::render(), RegroupNode::render(), WithNode::render(), I18nVarNode::render(), I18ncVarNode::render(), I18ncpVarNode::render(), I18npVarNode::render(), L10nFileSizeVarNode::render(), L10nMoneyVarNode::render(), and BlockNode::render().
std::shared_ptr< AbstractLocalizer > Context::localizer | ( | ) | const |
Returns the localizer currently in use.
Definition at line 230 of file context.cpp.
Referenced by I18nNode::render(), I18nVarNode::render(), I18ncNode::render(), I18ncVarNode::render(), I18ncpNode::render(), I18ncpVarNode::render(), I18npNode::render(), I18npVarNode::render(), L10nFileSizeNode::render(), L10nFileSizeVarNode::render(), L10nMoneyNode::render(), L10nMoneyVarNode::render(), WithLocaleNode::render(), Cutelee::Variable::resolve(), and setLocalizer().
Returns the context object identified by the key str
Definition at line 100 of file context.cpp.
References Cutelee::getSafeString().
Referenced by ForNode::render(), IfChangedNode::render(), and Cutelee::Variable::resolve().
Assignmant operator
Definition at line 73 of file context.cpp.
void Context::pop | ( | ) |
Pops the context.
Definition at line 131 of file context.cpp.
Referenced by FilterNode::render(), ForNode::render(), IfChangedNode::render(), RangeNode::render(), RegroupNode::render(), WithNode::render(), WithLocaleNode::render(), and BlockNode::render().
void Context::push | ( | ) |
Pushes a new context.
Definition at line 123 of file context.cpp.
Referenced by FilterNode::render(), ForNode::render(), IfChangedNode::render(), RangeNode::render(), RegroupNode::render(), WithNode::render(), WithLocaleNode::render(), and BlockNode::render().
QString Context::relativeMediaPath | ( | ) | const |
The relative path to external media to be used in templates.
Definition at line 208 of file context.cpp.
Referenced by MediaFinderNode::render().
RenderContext * Context::renderContext | ( | ) | const |
Returns a modifiable RenderContext. This may be used to make Template rendering threadsafe so that render state does not need to be stored in the Node implementation itself.
Definition at line 214 of file context.cpp.
Referenced by BlockNode::getSuper(), Cutelee::Template::render(), CycleNode::render(), BlockNode::render(), ExtendsNode::render(), and ConstantIncludeNode::render().
void Context::setLocalizer | ( | std::shared_ptr< AbstractLocalizer > | localizer | ) |
Sets the localizer
to be used.
The Context takes ownerwhip of the localizer.
Definition at line 220 of file context.cpp.
References localizer().
void Context::setRelativeMediaPath | ( | const QString & | relativePath | ) |
Sets the relative path to external media to be used in templates to relativePath
Definition at line 202 of file context.cpp.
void Context::setUrlType | ( | Context::UrlType | type | ) |
Sets the type of external media URL to be used in the template to type
.
Definition at line 190 of file context.cpp.
Context::UrlType Context::urlType | ( | ) | const |
The type of URL used in the template.
Definition at line 196 of file context.cpp.
Referenced by MediaFinderNode::render().