Grantlee: templates/lib/templateloader.h Source File

Grantlee 5.1.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
29 namespace Grantlee
30 {
31
32 class AbstractLocalizer;
33
35
49 class GRANTLEE_TEMPLATES_EXPORT AbstractTemplateLoader
50 {
51 public:
55 virtual ~AbstractTemplateLoader();
56
62 virtual Template loadByName(const QString &name,
63 Engine const *engine) const = 0;
64
68 virtual QPair<QString, QString>
69 getMediaUri(const QString &fileName) const = 0;
70
74 virtual bool canLoadTemplate(const QString &name) const = 0;
75 };
76
78
79 class FileSystemTemplateLoaderPrivate;
80
133 class GRANTLEE_TEMPLATES_EXPORT FileSystemTemplateLoader
134 : public AbstractTemplateLoader
135 {
136 public:
140 FileSystemTemplateLoader(const QSharedPointer<AbstractLocalizer> localizer
141 = QSharedPointer<AbstractLocalizer>());
142
146 ~FileSystemTemplateLoader() override;
147
148 Template loadByName(const QString &name, Engine const *engine) const override;
149
150 bool canLoadTemplate(const QString &name) const override;
151
152 QPair<QString, QString> getMediaUri(const QString &fileName) const override;
153
157 void setTheme(const QString &themeName);
158
162 QString themeName() const;
163
167 void setTemplateDirs(const QStringList &dirs);
168
172 QStringList templateDirs() const;
173
174 private:
175 Q_DECLARE_PRIVATE(FileSystemTemplateLoader)
176 FileSystemTemplateLoaderPrivate *const d_ptr;
177 };
178
180
190 class GRANTLEE_TEMPLATES_EXPORT InMemoryTemplateLoader
191 : public AbstractTemplateLoader
192 {
193 public:
194 InMemoryTemplateLoader();
195 ~InMemoryTemplateLoader() override;
196
197 Template loadByName(const QString &name, Engine const *engine) const override;
198
199 bool canLoadTemplate(const QString &name) const override;
200
201 QPair<QString, QString> getMediaUri(const QString &fileName) const override;
202
217 void setTemplate(const QString &name, const QString &content);
218
219 private:
220 QHash<QString, QString> m_namedTemplates;
221 };
222 }
223
224 #endif
Grantlee::Template
The Template class is a tree of nodes which may be rendered.
Definition: template.h:94
Grantlee::InMemoryTemplateLoader
The InMemoryTemplateLoader loads Templates set dynamically in memory.
Definition: templateloader.h:190
Grantlee::AbstractTemplateLoader
An retrieval interface to a storage location for Template objects.
Definition: templateloader.h:49
Grantlee::FileSystemTemplateLoader
The FileSystemTemplateLoader loads Templates from the file system.
Definition: templateloader.h:133
Grantlee
The Grantlee namespace holds all public Grantlee API.
Definition: Mainpage.dox:7
Grantlee::Engine
Grantlee::Engine is the main entry point for creating Grantlee Templates.
Definition: engine.h:123