~ubuntu-branches/ubuntu/oneiric/ctemplate/oneiric

« back to all changes in this revision

Viewing changes to doc/index.html

  • Committer: Bazaar Package Importer
  • Author(s): Florian Reinhard
  • Date: 2010-01-14 22:31:32 UTC
  • Revision ID: james.westby@ubuntu.com-20100114223132-w9ritwjg2av4rfb3
Tags: upstream-0.96
ImportĀ upstreamĀ versionĀ 0.96

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
 
2
<html>
 
3
<head>
 
4
  <title>Google Template System</title>
 
5
 
 
6
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
 
7
  <link href="http://www.google.com/favicon.ico" type="image/x-icon"
 
8
        rel="shortcut icon">
 
9
  <link href="designstyle.css" type="text/css" rel="stylesheet">
 
10
  <style type="text/css">
 
11
  <!--
 
12
  ol.bluelist li {
 
13
    color: #3366ff;
 
14
    font-family: sans-serif;
 
15
  }
 
16
  ol.bluelist li p {
 
17
    color: #000;
 
18
    font-family: "Times Roman", times, serif;
 
19
  }
 
20
  ul.blacklist li {  
 
21
    color: #000;
 
22
    font-family: "Times Roman", times, serif;
 
23
  }
 
24
  //-->
 
25
  </style>
 
26
</head>
 
27
<body>
 
28
 
 
29
<h1> <a name="Google_Template_System"></a>Google Template System </h1>
 
30
<center><strong>Status: Current</strong> &nbsp;
 
31
<small>(as of 25 April 2008)</small></center>
 
32
<br>
 
33
 
 
34
Welcome to the Google C++ template system!  As a quick start, here's a
 
35
small but complete program that uses this template library.  For more
 
36
details see, the links below.
 
37
 
 
38
<h3>Template file <code>example.tpl</code></h3>
 
39
<pre>
 
40
   Hello {{NAME}},
 
41
   You have just won ${{VALUE}}!
 
42
   {{#IN_CA}}Well, ${{TAXED_VALUE}}, after taxes.{{/IN_CA}}
 
43
</pre>
 
44
 
 
45
<h3>C++ program <code>example.cc</code></h3>
 
46
<pre>
 
47
   #include &lt;stdlib.h>
 
48
   #include &lt;string>
 
49
   #include &lt;iostream>
 
50
   #include &lt;ctemplate/template.h>
 
51
   int main(int argc, char** argv) {
 
52
      ctemplate::TemplateDictionary dict("example");
 
53
      dict.SetValue("NAME", "John Smith");
 
54
      int winnings = random() % 100000;
 
55
      dict.SetIntValue("VALUE", winnings);
 
56
      dict.SetFormattedValue("TAXED_VALUE", "%.2f", winnings * 0.83);
 
57
      // For now, assume everyone lives in CA.
 
58
      // (Try running the program with a 0 here instead!)
 
59
      if (1) {
 
60
        dict.ShowSection("IN_CA");
 
61
      }
 
62
 
 
63
      ctemplate::Template* tpl = ctemplate::Template::GetTemplate(
 
64
        "example.tpl", ctemplate::DO_NOT_STRIP);
 
65
      std::string output;
 
66
      tpl->Expand(&output, &dict);
 
67
      std::cout &lt;&lt; output;
 
68
      return 0;
 
69
   }
 
70
</pre>
 
71
 
 
72
<h3>Compiling and linking (using gcc)</h3>
 
73
<pre>
 
74
   gcc -o example example.cc -lctemplate_nothreads
 
75
</pre>
 
76
 
 
77
<p>I can use the "nothreads" library because <code>example.cc</code>
 
78
doesn't use threads.  If <code>example.cc</code> were threaded, I
 
79
would do something like this instead:</p>
 
80
<pre>
 
81
   gcc -o example example.cc -lctemplate -pthread
 
82
</pre>
 
83
 
 
84
<p>See the README for more details about the two different ctemplate
 
85
libraries.</p>
 
86
 
 
87
 
 
88
<h2>In-depth Documentation</h2>
 
89
 
 
90
<ol>
 
91
  <li> <A HREF="howto.html">Howto</A>: Introduction to the Google
 
92
       Template system, and a tutorial for using it. </li>
 
93
 
 
94
  <li> <A HREF="auto_escape.html">Auto Escape</A>: Guide to using
 
95
       the optional Auto Escape mode to protect your web application
 
96
       better against XSS.</li>
 
97
 
 
98
  <li> <A HREF="tips.html">Tips</A>: Advice, tips, and recommendations
 
99
       for best practices with templates, to make them easier to write
 
100
       and maintain, and to avoid common template mistakes. </li>
 
101
 
 
102
  <li> <A HREF="example.html">Examples</A>: Some example templates and
 
103
       application code that uses them.  These are taken from actual
 
104
       Google applications. </li>
 
105
</ol>
 
106
 
 
107
<hr>
 
108
<address>
 
109
Craig Silverstein<br>
 
110
Last modified: Wed Feb 15 23:21:42 PST 2006
 
111
</address>
 
112
 
 
113
</body>
 
114
</html>