Grantlee: templates/lib/templateloader.h Source File

Grantlee 5.3.0

templateloader.h
1/*
2 This file is part of the Grantlee template system.
3
4 Copyright (c) 2009,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#ifndef GRANTLEE_TEMPLATELOADER_H
22#define GRANTLEE_TEMPLATELOADER_H
23
24#include "grantlee_templates_export.h"
25#include "template.h"
26
27#include <QtCore/QSharedPointer>
28
29namespace Grantlee
30{
31
32class AbstractLocalizer;
33
35
48 class GRANTLEE_TEMPLATES_EXPORT AbstractTemplateLoader
49{
50public:
54 virtual ~AbstractTemplateLoader();
55
60 virtual Template loadByName(const QString &name,
61 Engine const *engine) const = 0;
62
66 virtual QPair<QString, QString>
67 getMediaUri(const QString &fileName) const = 0;
68
72 virtual bool canLoadTemplate(const QString &name) const = 0;
73};
74
76
77class FileSystemTemplateLoaderPrivate;
78
137 class GRANTLEE_TEMPLATES_EXPORT FileSystemTemplateLoader
138 : public AbstractTemplateLoader
139{
140public:
144 FileSystemTemplateLoader(const QSharedPointer<AbstractLocalizer> localizer
145 = {});
146
150 ~FileSystemTemplateLoader() override;
151
152 Template loadByName(const QString &name, Engine const *engine) const override;
153
154 bool canLoadTemplate(const QString &name) const override;
155
156 QPair<QString, QString> getMediaUri(const QString &fileName) const override;
157
161 void setTheme(const QString &themeName);
162
166 QString themeName() const;
167
171 void setTemplateDirs(const QStringList &dirs);
172
176 QStringList templateDirs() const;
177
178private:
179 Q_DECLARE_PRIVATE(FileSystemTemplateLoader)
180 FileSystemTemplateLoaderPrivate *const d_ptr;
181};
182
184
195 class GRANTLEE_TEMPLATES_EXPORT InMemoryTemplateLoader
196 : public AbstractTemplateLoader
197{
198public:
199 InMemoryTemplateLoader();
200 ~InMemoryTemplateLoader() override;
201
202 Template loadByName(const QString &name, Engine const *engine) const override;
203
204 bool canLoadTemplate(const QString &name) const override;
205
206 QPair<QString, QString> getMediaUri(const QString &fileName) const override;
207
222 void setTemplate(const QString &name, const QString &content);
223
224private:
225 QHash<QString, QString> m_namedTemplates;
226};
227}
228
229#endif
Grantlee::AbstractTemplateLoader
An retrieval interface to a storage location for Template objects.
Definition templateloader.h:49
Grantlee::AbstractTemplateLoader::~AbstractTemplateLoader
virtual ~AbstractTemplateLoader()
Grantlee::AbstractTemplateLoader::canLoadTemplate
virtual bool canLoadTemplate(const QString &name) const =0
Grantlee::AbstractTemplateLoader::getMediaUri
virtual QPair< QString, QString > getMediaUri(const QString &fileName) const =0
Grantlee::AbstractTemplateLoader::loadByName
virtual Template loadByName(const QString &name, Engine const *engine) const =0
Grantlee::Engine
Grantlee::Engine is the main entry point for creating Grantlee Templates.
Definition engine.h:121
Grantlee::FileSystemTemplateLoader
The FileSystemTemplateLoader loads Templates from the file system.
Definition templateloader.h:139
Grantlee::FileSystemTemplateLoader::loadByName
Template loadByName(const QString &name, Engine const *engine) const override
Grantlee::FileSystemTemplateLoader::templateDirs
QStringList templateDirs() const
Grantlee::FileSystemTemplateLoader::themeName
QString themeName() const
Grantlee::FileSystemTemplateLoader::setTemplateDirs
void setTemplateDirs(const QStringList &dirs)
Grantlee::FileSystemTemplateLoader::getMediaUri
QPair< QString, QString > getMediaUri(const QString &fileName) const override
Grantlee::FileSystemTemplateLoader::canLoadTemplate
bool canLoadTemplate(const QString &name) const override
Grantlee::FileSystemTemplateLoader::~FileSystemTemplateLoader
~FileSystemTemplateLoader() override
Grantlee::FileSystemTemplateLoader::setTheme
void setTheme(const QString &themeName)
Grantlee::FileSystemTemplateLoader::FileSystemTemplateLoader
FileSystemTemplateLoader(const QSharedPointer< AbstractLocalizer > localizer={})
Grantlee::InMemoryTemplateLoader
The InMemoryTemplateLoader loads Templates set dynamically in memory.
Definition templateloader.h:197
Grantlee::InMemoryTemplateLoader::setTemplate
void setTemplate(const QString &name, const QString &content)
Grantlee::InMemoryTemplateLoader::getMediaUri
QPair< QString, QString > getMediaUri(const QString &fileName) const override
Grantlee::InMemoryTemplateLoader::canLoadTemplate
bool canLoadTemplate(const QString &name) const override
Grantlee::InMemoryTemplateLoader::loadByName
Template loadByName(const QString &name, Engine const *engine) const override
Grantlee::Template
The Template class is a tree of nodes which may be rendered.
Definition template.h:96
Grantlee
The Grantlee namespace holds all public Grantlee API.
Definition Mainpage.dox:8