~ubuntu-branches/ubuntu/precise/grantlee/precise

« back to all changes in this revision

Viewing changes to corelib/engine.h

  • Committer: Bazaar Package Importer
  • Author(s): Harald Sitter
  • Date: 2010-06-11 23:41:45 UTC
  • Revision ID: james.westby@ubuntu.com-20100611234145-oas7rhdrbwy8j55c
Tags: upstream-0.1.1
ImportĀ upstreamĀ versionĀ 0.1.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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 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
  Library 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_ENGINE_H
 
22
#define GRANTLEE_ENGINE_H
 
23
 
 
24
#include "template.h"
 
25
#include "templateloader.h"
 
26
 
 
27
namespace Grantlee
 
28
{
 
29
class TagLibraryInterface;
 
30
 
 
31
class EnginePrivate;
 
32
 
 
33
/// @headerfile engine.h grantlee/engine.h
 
34
 
 
35
/**
 
36
  @brief Grantlee::Engine is the main entry point for creating %Grantlee Templates.
 
37
 
 
38
  The Grantlee::Engine is responsible for configuring and creating Template objects.
 
39
  In typical use, one or more TemplateLoader objects will be added to the Engine to load template objects, and
 
40
  plugin directories will be set to enable finding template tags and filters.
 
41
 
 
42
  @code
 
43
    Engine *engine = new Engine();
 
44
 
 
45
    FileSystemTemplateLoader::Ptr loader = FileSystemTemplateLoader::Ptr( new FileSystemTemplateLoader() );
 
46
    loader->setTemplateDirs( QStringList() << "/usr/share/myapp/templates" );
 
47
    engine->addTemplateLoader( loader );
 
48
 
 
49
    engine->setPluginPaths( QStringList() << GRANTLEE_PLUGIN_PATH );
 
50
 
 
51
    Template template1 = engine->newTemplate( "Template content", "template name" );
 
52
 
 
53
    Template template2 = engine->loadByName( "templatefile.html" );
 
54
  @endcode
 
55
 
 
56
  Once it is configured, the engine can be used to create new templates by name by loading the templates with the loadByName method,
 
57
  or by defining the content in the newTemplate method.
 
58
 
 
59
  By default the builtin tags and filters distributed with %Grantlee are available in all templates without using the @gr_tag{load}
 
60
  tag in the template. These pre-loaded libraries may be configured if appropriate to the application. For example, an application
 
61
  which defines its own tags and filters may want them to be always available, or it may be desirable to restrict the features
 
62
  available to template authors by removing built in libraries.
 
63
 
 
64
  Different Engine objects can be used to create templates with differing configurations.
 
65
 
 
66
  @author Stephen Kelly <steveire@gmail.com>
 
67
*/
 
68
class GRANTLEE_CORE_EXPORT Engine : public QObject
 
69
{
 
70
  Q_OBJECT
 
71
public:
 
72
  /**
 
73
    Constructor
 
74
  */
 
75
  Engine( QObject *parent = 0 );
 
76
 
 
77
  /**
 
78
    Destructor.
 
79
  */
 
80
  ~Engine();
 
81
 
 
82
  /**
 
83
    Returns the TemplateLoaders currently configured on the Engine.
 
84
  */
 
85
  QList<AbstractTemplateLoader::Ptr> templateLoaders();
 
86
 
 
87
  /**
 
88
    Adds @p loader to the TemplateLoaders currently configured on the Engine.
 
89
  */
 
90
  void addTemplateLoader( AbstractTemplateLoader::Ptr loader );
 
91
 
 
92
  /**
 
93
    Sets the plugin dirs currently configured on the Engine to @p dirs.
 
94
 
 
95
    @see @ref finding_plugins
 
96
  */
 
97
  void setPluginPaths( const QStringList &dirs );
 
98
 
 
99
  /**
 
100
    Returns a URI for a media item with the name @p name.
 
101
 
 
102
    Typically this will be used for images. For example the media URI for the image
 
103
    <tt>"header_logo.png"</tt> may be <tt>"/home/user/common/header_logo.png"</tt> or <tt>"/home/user/some_theme/header_logo.png"</tt>
 
104
    depending on the templateLoaders configured.
 
105
 
 
106
    This method will not usually be called by application code.
 
107
    To load media in a template, use the @gr_tag{media_finder} template tag.
 
108
  */
 
109
  QPair<QString, QString> mediaUri( const QString &fileName ) const;
 
110
 
 
111
  /**
 
112
    Load the Template identified by @p name.
 
113
 
 
114
    The Templates and plugins loaded will be determined by the Engine configuration.
 
115
  */
 
116
  Template loadByName( const QString &name ) const;
 
117
 
 
118
  /**
 
119
    Create a new Template with the content @p content identified by @p name.
 
120
 
 
121
    The secondary Templates and plugins loaded will be determined by the Engine configuration.
 
122
  */
 
123
  Template newTemplate( const QString &content, const QString &name ) const;
 
124
 
 
125
  /**
 
126
    Returns the libraries available by default to new Templates.
 
127
  */
 
128
  QStringList defaultLibraries() const;
 
129
 
 
130
  /**
 
131
    Adds the library named @p libName to the libraries available by default to new Templates.
 
132
  */
 
133
  void addDefaultLibrary( const QString &libName );
 
134
 
 
135
  /**
 
136
    Removes the library named @p libName from the libraries available by default to new Templates.
 
137
  */
 
138
  void removeDefaultLibrary( const QString &libName );
 
139
 
 
140
#ifndef Q_QDOC
 
141
  /**
 
142
    @internal
 
143
 
 
144
    Loads and returns the libraries specified in defaultLibraries or @p state.
 
145
  */
 
146
  void loadDefaultLibraries();
 
147
 
 
148
  /**
 
149
    @internal
 
150
 
 
151
    Loads and returns the library specified by @p name in the current Engine configuration or @p state.
 
152
 
 
153
    Templates wishing to load a library should use the @gr_tag{load} tag.
 
154
  */
 
155
  TagLibraryInterface* loadLibrary( const QString &name );
 
156
#endif
 
157
 
 
158
private:
 
159
  Q_DECLARE_PRIVATE( Engine )
 
160
  EnginePrivate * const d_ptr;
 
161
};
 
162
 
 
163
}
 
164
 
 
165
#endif
 
166