Grantlee  5.0.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 "template.h"
25 #include "grantlee_templates_export.h"
26 
27 #include <QtCore/QSharedPointer>
28 
29 namespace Grantlee
30 {
31 
32 class AbstractLocalizer;
33 
35 
46 class GRANTLEE_TEMPLATES_EXPORT AbstractTemplateLoader
47 {
48 public:
52  virtual ~AbstractTemplateLoader();
53 
57  virtual Template loadByName( const QString &name, Engine const *engine ) const = 0;
58 
62  virtual QPair<QString, QString> getMediaUri( const QString &fileName ) const = 0;
63 
67  virtual bool canLoadTemplate( const QString &name ) const = 0;
68 
69 };
70 
72 
73 class FileSystemTemplateLoaderPrivate;
74 
120 class GRANTLEE_TEMPLATES_EXPORT FileSystemTemplateLoader : public AbstractTemplateLoader
121 {
122 public:
126  FileSystemTemplateLoader(const QSharedPointer<AbstractLocalizer> localizer = QSharedPointer<AbstractLocalizer>());
127 
131  virtual ~FileSystemTemplateLoader();
132 
133  /* reimp */ Template loadByName( const QString &name, Engine const *engine ) const;
134 
135  /* reimp */ bool canLoadTemplate( const QString &name ) const;
136 
137  /* reimp */ QPair<QString, QString> getMediaUri( const QString& fileName ) const;
138 
142  void setTheme( const QString &themeName );
143 
147  QString themeName() const;
148 
152  void setTemplateDirs( const QStringList &dirs );
153 
157  QStringList templateDirs() const;
158 
159 private:
160  Q_DECLARE_PRIVATE( FileSystemTemplateLoader )
161  FileSystemTemplateLoaderPrivate * const d_ptr;
162 };
163 
165 
173 class GRANTLEE_TEMPLATES_EXPORT InMemoryTemplateLoader : public AbstractTemplateLoader
174 {
175 public:
177  virtual ~InMemoryTemplateLoader();
178 
179  /* reimp */ Template loadByName( const QString &name, Engine const *engine ) const;
180 
181  /* reimp */ bool canLoadTemplate( const QString &name ) const;
182 
183  /* reimp */ QPair<QString, QString> getMediaUri( const QString& fileName ) const;
184 
199  void setTemplate( const QString &name, const QString &content );
200 
201 private:
202  QHash<QString, QString> m_namedTemplates;
203 };
204 
205 }
206 
207 #endif
The Template class is a tree of nodes which may be rendered.
Definition: template.h:89
The InMemoryTemplateLoader loads Templates set dynamically in memory.
An retrieval interface to a storage location for Template objects.
The FileSystemTemplateLoader loads Templates from the file system.
The Grantlee namespace holds all public Grantlee API.
Definition: Mainpage.dox:7
Grantlee::Engine is the main entry point for creating Grantlee Templates.
Definition: engine.h:110