Cutelee
6.1.0
with_locale.cpp
1
/*
2
This file is part of the Cutelee template system.
3
4
Copyright (c) 2010 Stephen Kelly <steveire@gmail.com>
5
6
This library is free software; you can redistribute it and/or
7
modify it under the terms of the GNU Lesser General Public
8
License as published by the Free Software Foundation; either version
9
2.1 of the Licence, or (at your option) any later version.
10
11
This library is distributed in the hope that it will be useful,
12
but WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
Lesser General Public License for more details.
15
16
You should have received a copy of the GNU Lesser General Public
17
License along with this library. If not, see <http://www.gnu.org/licenses/>.
18
19
*/
20
21
#include "with_locale.h"
22
23
#include "../lib/exception.h"
24
#include "parser.h"
25
#include <
util.h
>
26
27
#include <QDebug>
28
#include <abstractlocalizer.h>
29
30
WithLocaleNodeFactory::WithLocaleNodeFactory() {}
31
32
Node
*
WithLocaleNodeFactory::getNode
(
const
QString
&tagContent,
Parser
*p)
const
33
{
34
auto
expr =
smartSplit
(tagContent);
35
36
if
(expr.size() != 2) {
37
throw
Cutelee::Exception
(
38
TagSyntaxError,
39
QStringLiteral(
40
"%1 expected format is for example 'with_locale \"de_DE\"'"
)
41
.arg(expr.first()));
42
}
43
44
FilterExpression
fe(expr.at(1), p);
45
46
auto
n =
new
WithLocaleNode
(fe, p);
47
auto
nodeList = p->
parse
(n, QStringLiteral(
"endwith_locale"
));
48
n->setNodeList(nodeList);
49
p->
removeNextToken
();
50
51
return
n;
52
}
53
54
WithLocaleNode::WithLocaleNode(
const
FilterExpression
&localeName,
55
QObject
*parent)
56
:
Node
(parent), m_localeName(localeName)
57
{
58
}
59
60
void
WithLocaleNode::setNodeList(
const
NodeList
&nodeList)
61
{
62
m_list = nodeList;
63
}
64
65
void
WithLocaleNode::render
(
OutputStream
*stream,
Context
*c)
const
66
{
67
const
QString
name =
Cutelee::getSafeString
(m_localeName.resolve(c)).
get
();
68
69
c->
push
();
70
c->
localizer
()->pushLocale(name);
71
m_list.render(stream, c);
72
c->
localizer
()->popLocale();
73
c->
pop
();
74
}
Cutelee::AbstractNodeFactory::smartSplit
Q_INVOKABLE QStringList smartSplit(const QString &str) const
Definition
node.cpp:202
Cutelee::Context
The Context class holds the context to render a Template with.
Definition
context.h:119
Cutelee::Context::pop
void pop()
Definition
context.cpp:131
Cutelee::Context::push
void push()
Definition
context.cpp:123
Cutelee::Context::localizer
std::shared_ptr< AbstractLocalizer > localizer() const
Definition
context.cpp:230
Cutelee::Exception
An exception for use when implementing template tags.
Definition
exception.h:85
Cutelee::FilterExpression
A FilterExpression object represents a filter expression in a template.
Definition
filterexpression.h:120
Cutelee::NodeList
A list of Nodes with some convenience API for rendering them.
Definition
node.h:148
Cutelee::Node
Base class for all nodes.
Definition
node.h:78
Cutelee::OutputStream
The OutputStream class is used to render templates to a QTextStream.
Definition
outputstream.h:81
Cutelee::Parser
The Parser class processes a string template into a tree of nodes.
Definition
parser.h:49
Cutelee::Parser::parse
NodeList parse(Node *parent, const QStringList &stopAt={})
Definition
parser.cpp:180
Cutelee::Parser::removeNextToken
void removeNextToken()
Definition
parser.cpp:297
Cutelee::SafeString::get
const NestedString & get() const
Definition
safestring.h:340
WithLocaleNodeFactory::getNode
Node * getNode(const QString &tagContent, Parser *p) const override
Definition
with_locale.cpp:32
WithLocaleNode
Definition
with_locale.h:38
WithLocaleNode::render
void render(OutputStream *stream, Context *c) const override
Definition
with_locale.cpp:65
Cutelee::getSafeString
Cutelee::SafeString getSafeString(const QVariant &input)
Definition
util.cpp:108
QObject
QString
util.h
Utility functions used throughout Cutelee.
templates
i18n
with_locale.cpp
Generated by
1.16.1