~ubuntu-branches/ubuntu/trusty/grantlee/trusty

« back to all changes in this revision

Viewing changes to templates/tests/templatedirs/main.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Scott Kitterman
  • Date: 2010-12-07 09:19:01 UTC
  • Revision ID: james.westby@ubuntu.com-20101207091901-hsfsvnkxdshv4k8g
Tags: 0.1.7-0ubuntu3
Revert previous upload and try again with the correct patch

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) 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
1
 
21
2
#include <QCoreApplication>
22
3
#include <QDebug>
25
6
 
26
7
#include "grantlee_paths.h"
27
8
 
28
 
static void renderTemplate( Grantlee::Engine *engine, const QString &templateName )
29
 
{
 
9
static void renderTemplate( Grantlee::Engine *engine, const QString &templateName ) {
30
10
 
31
11
  Grantlee::Template t = engine->loadByName( templateName );
32
12
 
33
 
  if ( t->error() ) {
 
13
  if ( t->error() )
 
14
  {
34
15
    qDebug() << t->errorString();
35
 
    Q_ASSERT( !"Failed to get template" );
 
16
    Q_ASSERT(!"Failed to get template");
36
17
  }
37
18
 
38
19
  Grantlee::Context c;
39
20
 
40
 
  QString result = t->render( &c );
 
21
  QString result = t->render(&c);
41
22
 
42
 
  if ( t->error() ) {
 
23
  if ( t->error() )
 
24
  {
43
25
    qDebug() << t->errorString();
44
 
    Q_ASSERT( !"Failed to render template" );
 
26
    Q_ASSERT(!"Failed to render template");
45
27
  }
46
28
 
47
29
  qDebug() << result;
48
30
}
49
31
 
50
 
int main( int argc, char **argv )
 
32
int main(int argc, char **argv)
51
33
{
52
 
  QCoreApplication app( argc, argv );
 
34
  QCoreApplication app(argc, argv);
53
35
 
54
36
  Grantlee::Engine *engine = new Grantlee::Engine();
55
37
 
56
38
  Grantlee::FileSystemTemplateLoader::Ptr loader = Grantlee::FileSystemTemplateLoader::Ptr( new Grantlee::FileSystemTemplateLoader() );
57
39
  loader->setTemplateDirs( QStringList()
58
 
                           << ( QCoreApplication::applicationDirPath() + "/template_dir_1" )
59
 
                           << ( QCoreApplication::applicationDirPath() + "/template_dir_2" )
60
 
                         );
 
40
                          << ( QCoreApplication::applicationDirPath() + "/template_dir_1" )
 
41
                          << ( QCoreApplication::applicationDirPath() + "/template_dir_2" )
 
42
  );
61
43
 
62
44
  engine->addTemplateLoader( loader );
63
45
 
81
63
                             "file://" + QCoreApplication::applicationDirPath() + "/template_dir_2/blue.png";
82
64
  renderTemplate( engine, "mediatemplate2.txt" );
83
65
 
84
 
  app.exit( 0 );
 
66
  app.exit(0);
85
67
}
86
68