[svn] fixed loop context bug, added new jinja webpage
Before adoption: this commit came in with the history the project adopted, so no landing records it.
--HG-- branch : trunk
authored by Armin Ronacher · committed by Armin Ronacher · parent e55ed10 · Browse files · 20 files·+737 added−8 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
20 files+737 added−8 removed
- other:+737 added−8 removed
Provenance
- Commit
0a1742e- Tree
d30159d- Author
Armin Ronacher <armin.ronacher@active-4.com>- Committer
Armin Ronacher <armin.ronacher@active-4.com>- Parent
e55ed10
20 files changed+737 added−8 removed
modified:jinja/__init__.py+3 added
6 unmodified lines7 :license: BSD, see LICENSE for more details.8 """9 from jinja.environment import Environment10 from jinja.loaders import *11+12+13+from_string = Environment().from_stringmodified:jinja/datastructure.py+7 added-1 removed
64 unmodified lines65 66 def __float__(self):67 return 168 69+ def __call__(self, *args, **kwargs):70+ return self71 72+73 Undefined = UndefinedType()74 75 76 class Deferred(object):139 unmodified lines216 if self.loop_function is not None:217 return self.loop_function(seq)218 return Undefined219 220+ def __repr__(self):221+ return str(self._stack)222 223+224 class CycleContext(object):225 """226 Helper class used for cycling.227 """40 unmodified lines268 return False269 return True270 271 eos = property(lambda x: not x.__nonzero__(), doc=__nonzero__.__doc__)266-272+ 273 def next(self):274 """Return the next token from the stream."""275 if self._pushed:276 rv = self._pushed.pop()28 unmodified linesmodified:jinja/environment.py+6 added-7 removed
131 unmodified lines132 def get_attribute(self, obj, name):133 """134 Get the attribute name from obj.135 """136- if name in obj:136+ try:137 return obj[name]138- elif hasattr(obj, name):139- rv = getattr(obj, name)140- r = getattr(obj, 'jinja_allowed_attributes', None)141- if r is not None:142- if name not in r:138+ except (TypeError, KeyError, IndexError):139+ if hasattr(obj, name):140+ r = getattr(obj, 'jinja_allowed_attributes', None)141+ if r is not None and name not in r:142 raise SecurityException('unsafe attributed %r accessed' % name)144- return rv143+ return getattr(obj, name)144 return Undefined145 146 def call_function(self, f, args, kwargs, dyn_args, dyn_kwargs):147 """31 unmodified linesmodified:jinja/parser.py+1 added
24 unmodified lines25 end_of_if = lambda p, t, d: t == 'name' and d == 'endif'26 end_of_filter = lambda p, t, d: t == 'name' and d == 'endfilter'27 end_of_macro = lambda p, t, d: t == 'name' and d == 'endmacro'28 end_of_block_tag = lambda p, t, d: t == 'name' and d == 'endblock'29+end_of_raw = lambda p, t, d: t == 'name' and d == 'endraw'30 31 32 class Parser(object):33 """319 unmodified linesadded:www/layout/base.html+32 added
1234567891011121314151617181920212223242526272829303132<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd"><html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Untitled | Jinja Template Engine</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="stylesheet" href="./../static/style.css" type="text/css" /> <link rel="stylesheet" href="./../static/print.css" type="text/css" media="print" /> <link rel="stylesheet" href="./../static/pygments.css" type="text/css" /> </head> <body> <div id="header"> <h1>Jinja</h1> </div> <ul id="navigation"> <li><a href="./../index.html">Index</a></li> <li><a href="./../faq.html">FAQ</a></li> <li><a href="./../documentation.html">Documentation</a></li> <li><a href="./../download.html">Download</a></li> </ul> <div id="content"> <div id="contentwrapper"> </div> <p id="meta"> <a href="./../layout/base.tmpl">show template source</a> </p> </div> <div id="footer"> © Copyright 2007 by the Pocoo Team. </div> </body></html>No newline at end of fileadded:www/layout/base.tmpl+54 added
1+<% set navigation = [2+ ('index', 'Index'),3+ ('faq', 'FAQ'),4+ ('documentation', 'Documentation'),5+ ('download', 'Download')6+] %>7+<% block code %><% endblock %>8+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML Frameset//EN"9+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">10+<html xmlns="http://www.w3.org/1999/xhtml">11+ <head>12+ <title><% block title %>Untitled<% endblock %> | Jinja Template Engine</title>13+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />14+ <link rel="stylesheet" href="<%= root %>static/style.css" type="text/css" />15+ <link rel="stylesheet" href="<%= root %>static/print.css" type="text/css" media="print" />16+ <link rel="stylesheet" href="<%= root %>static/pygments.css" type="text/css" />17+ </head>18+ <body>19+ <div id="header">20+ <h1>Jinja</h1>21+ </div>22+ <ul id="navigation">23+ <% for id, caption in navigation %>24+ <% if id == file_id or id.startswith(file_id + '/') %>25+ <li class="active"><%= caption|escape %></li>26+ <% else %>27+ <li><a href="<%= root %><%= id|escape %>.html"><%= caption|escape %></a></li>28+ <% endif %>29+ <% endfor %>30+ </ul>31+ <% if trace %>32+ <div id="trace">33+ <% for href, caption in trace %>34+ <% if loop.last %>35+ <%= caption %>36+ <% else %>37+ <a href="<%= href|escape %>"><%= caption %></a> »38+ <% endif %>39+ <% endfor %>40+ </div>41+ <% endif %>42+ <div id="content">43+ <div id="contentwrapper">44+ <% block content %><% endblock %>45+ </div>46+ <p id="meta">47+ <a href="<%= root + file_id + '.tmpl' %>">show template source</a>48+ </p>49+ </div>50+ <div id="footer">51+ © Copyright 2007 by the Pocoo Team.52+ </div>53+ </body>54+</html>added:www/static/jinjabanner.pngbinary
A binary file, added.
added:www/static/jinjalogo.pngbinary
A binary file, added.
added:www/static/pygments.css+58 added
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758.syntax { background: #ffffff; }.syntax .c { color: #888888 } /* Comment */.syntax .err { color: #a61717; background-color: #e3d2d2 } /* Error */.syntax .k { color: #008800; font-weight: bold } /* Keyword */.syntax .cm { color: #888888 } /* Comment.Multiline */.syntax .cp { color: #cc0000; font-weight: bold } /* Comment.Preproc */.syntax .c1 { color: #888888 } /* Comment.Single */.syntax .cs { color: #cc0000; font-weight: bold; background-color: #fff0f0 } /* Comment.Special */.syntax .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */.syntax .ge { font-style: italic } /* Generic.Emph */.syntax .gr { color: #aa0000 } /* Generic.Error */.syntax .gh { color: #999999 } /* Generic.Heading */.syntax .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */.syntax .go { color: #888888 } /* Generic.Output */.syntax .gp { color: #555555 } /* Generic.Prompt */.syntax .gs { font-weight: bold } /* Generic.Strong */.syntax .gu { color: #aaaaaa } /* Generic.Subheading */.syntax .gt { color: #aa0000 } /* Generic.Traceback */.syntax .kc { color: #008800; font-weight: bold } /* Keyword.Constant */.syntax .kd { color: #008800; font-weight: bold } /* Keyword.Declaration */.syntax .kp { color: #008800 } /* Keyword.Pseudo */.syntax .kr { color: #008800; font-weight: bold } /* Keyword.Reserved */.syntax .kt { color: #888888; font-weight: bold } /* Keyword.Type */.syntax .m { color: #0000DD; font-weight: bold } /* Literal.Number */.syntax .s { color: #dd2200; background-color: #fff0f0 } /* Literal.String */.syntax .na { color: #336699 } /* Name.Attribute */.syntax .nb { color: #003388 } /* Name.Builtin */.syntax .nc { color: #bb0066; font-weight: bold } /* Name.Class */.syntax .no { color: #003366; font-weight: bold } /* Name.Constant */.syntax .nd { color: #555555 } /* Name.Decorator */.syntax .ne { color: #bb0066; font-weight: bold } /* Name.Exception */.syntax .nf { color: #0066bb; font-weight: bold } /* Name.Function */.syntax .nl { color: #336699; font-style: italic } /* Name.Label */.syntax .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */.syntax .py { color: #336699; font-weight: bold } /* Name.Property */.syntax .nt { color: #bb0066; font-weight: bold } /* Name.Tag */.syntax .nv { color: #336699 } /* Name.Variable */.syntax .ow { color: #008800 } /* Operator.Word */.syntax .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */.syntax .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */.syntax .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */.syntax .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */.syntax .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */.syntax .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */.syntax .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */.syntax .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */.syntax .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */.syntax .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */.syntax .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */.syntax .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */.syntax .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */.syntax .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */.syntax .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */.syntax .bp { color: #003388 } /* Name.Builtin.Pseudo */.syntax .vc { color: #336699 } /* Name.Variable.Class */.syntax .vg { color: #dd7700 } /* Name.Variable.Global */.syntax .vi { color: #3333bb } /* Name.Variable.Instance */.syntax .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */No newline at end of fileadded:www/static/style.css+137 added
1+/**2+ * Jinja Webpage Design3+ */4+5+body {6+ background-color: #333;7+ margin: 0;8+ padding: 0;9+ font-family: 'Georgia', serif;10+ font-size: 15px;11+ color: #111;12+}13+14+p, li, dd, dt, blockquote {15+ color: #333;16+}17+18+p {19+ line-height: 150%;20+ margin-bottom: 0;21+ margin-top: 10px;22+ text-align: justify;23+}24+25+hr {26+ border-top: 1px solid #ccc;27+ border-bottom: 0;28+ border-right: 0;29+ border-left: 0;30+ margin-bottom: 10px;31+ margin-top: 20px;32+}33+34+a {35+ color: #b41717;36+}37+38+a:hover {39+ color: #444;40+}41+42+pre {43+ background-color: #f9f9f9;44+ border-top: 1px solid #ccc;45+ border-bottom: 1px solid #ccc;46+ padding: 5px;47+ font-size: 13px;48+ font-family: 'Bitstream Vera Sans Mono', 'Monaco', monospace;49+}50+51+#content {52+ background-color: white;53+ background-image: url(watermark.png);54+ padding: 10px;55+ margin: 25px 25px 0 25px;56+ border: 4px solid #ddd;57+ border-bottom: none;58+}59+60+#footer {61+ margin: 0 25px 25px 25px;62+ border-bottom: 4px solid #ddd;63+ background-color: #fff;64+ text-align: right;65+ padding: 0 10px 5px 0;66+}67+68+#contentwrapper {69+ max-width: 700px;70+ padding: 0 10px 0 20px;71+}72+73+#header {74+ height: 80px;75+ background-color: #eee;76+ background-image: url(jinjabanner.png);77+ background-repeat: no-repeat;78+ border-bottom: 4px solid #ccc;79+}80+81+#header h1 {82+ display: none83+}84+85+#navigation {86+ background-color: #fff;87+ border: 1px solid #ccc;88+ border-right: none;89+ margin: 50px 29px 10px 10px;90+ padding: 0;91+ float: right;92+ list-style: none;93+ font-weight: bold;94+}95+96+#navigation li a {97+ display: block;98+ text-decoration: none;99+ padding: 5px 10px 5px 10px;100+ color: #333;101+}102+103+#navigation li a:hover {104+ color: #fff;105+ background-color: #444;106+}107+108+#navigation li.active {109+ padding: 5px 10px 5px 10px;110+ background-color: #b41717;111+ color: white;112+}113+114+#navigation li a:focus {115+ outline: none;116+ background-color: #222;117+ color: #fff;118+}119+120+#contentwrapper h1 {121+ color: #b41717;122+ font-size: 26px;123+ margin: 20px 0 0 -5px;124+}125+126+#contentwrapper h2 {127+ color: #444;128+ font-size: 20px;129+ margin: 20px 0 0 0;130+}131+132+#meta {133+ clear: both;134+ text-align: right;135+ color: #888;136+ font-size: 13px;137+}added:www/static/watermark.pngbinary
A binary file, added.
added:www/documentation.html+36 added
123456789101112131415161718192021222324252627282930313233343536<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd"><html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Documentation | Jinja Template Engine</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="stylesheet" href="./static/style.css" type="text/css" /> <link rel="stylesheet" href="./static/print.css" type="text/css" media="print" /> <link rel="stylesheet" href="./static/pygments.css" type="text/css" /> </head> <body> <div id="header"> <h1>Jinja</h1> </div> <ul id="navigation"> <li><a href="./index.html">Index</a></li> <li><a href="./faq.html">FAQ</a></li> <li class="active">Documentation</li> <li><a href="./download.html">Download</a></li> </ul> <div id="content"> <div id="contentwrapper"> <h1>Documentation</h1> <p> You can browse the documentation either online or download it: </p> </div> <p id="meta"> <a href="./documentation.tmpl">show template source</a> </p> </div> <div id="footer"> © Copyright 2007 by the Pocoo Team. </div> </body></html>No newline at end of fileadded:www/documentation.tmpl+8 added
1+<% extends 'layout/base.tmpl' %>2+<% block title %>Documentation<% endblock %>3+<% block content %>4+ <h1>Documentation</h1>5+ <p>6+ You can browse the documentation either online or download it:7+ </p>8+<% endblock %>added:www/download.html+52 added
1+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML Frameset//EN"2+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">3+<html xmlns="http://www.w3.org/1999/xhtml">4+ <head>5+ <title>Download | Jinja Template Engine</title>6+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />7+ <link rel="stylesheet" href="./static/style.css" type="text/css" />8+ <link rel="stylesheet" href="./static/print.css" type="text/css" media="print" />9+ <link rel="stylesheet" href="./static/pygments.css" type="text/css" />10+ </head>11+ <body>12+ <div id="header">13+ <h1>Jinja</h1>14+ </div>15+ <ul id="navigation">16+ <li><a href="./index.html">Index</a></li>17+ <li><a href="./faq.html">FAQ</a></li>18+ <li><a href="./documentation.html">Documentation</a></li>19+ <li class="active">Download</li>20+ </ul>21+ <div id="content">22+ <div id="contentwrapper">23+ <h1>Download</h1>24+ <p>25+ If you want to install the release with26+ <a href="http://peak.telecommunity.com/DevCenter/EasyInstall">easy_install</a>,27+ you can do it using this command:28+ </p>29+ <pre>easy_install Pygments</pre>30+ <p>31+ You can also get the development source from subversion using this command:32+ </p>33+ <pre>svn co http://trac.pocoo.org/repos/jinja/trunk jinja</pre>34+ <p>35+ Installing the current subversion trunk as a Python egg is done with:36+ </p>37+ <pre>easy_install Jinja==dev</pre>38+ <p>39+ Development takes place at the <a href="http://trac.pocoo.org/">Pocoo trac</a>,40+ you can browse the source online41+ <a href="http://trac.pocoo.org/browser/jinja/trunk">here</a>.42+ </p>43+ </div>44+ <p id="meta">45+ <a href="./download.tmpl">show template source</a>46+ </p>47+ </div>48+ <div id="footer">49+ © Copyright 2007 by the Pocoo Team.50+ </div>51+ </body>52+</html>added:www/download.tmpl+24 added
1+<% extends 'layout/base.tmpl' %>2+<% block title %>Download<% endblock %>3+<% block content %>4+ <h1>Download</h1>5+ <p>6+ If you want to install the release with7+ <a href="http://peak.telecommunity.com/DevCenter/EasyInstall">easy_install</a>,8+ you can do it using this command:9+ </p>10+ <pre>easy_install Pygments</pre>11+ <p>12+ You can also get the development source from subversion using this command:13+ </p>14+ <pre>svn co http://trac.pocoo.org/repos/jinja/trunk jinja</pre>15+ <p>16+ Installing the current subversion trunk as a Python egg is done with:17+ </p>18+ <pre>easy_install Jinja==dev</pre>19+ <p>20+ Development takes place at the <a href="http://trac.pocoo.org/">Pocoo trac</a>,21+ you can browse the source online22+ <a href="http://trac.pocoo.org/browser/jinja/trunk">here</a>.23+ </p>24+<% endblock %>added:www/faq.html+72 added
1+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML Frameset//EN"2+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">3+<html xmlns="http://www.w3.org/1999/xhtml">4+ <head>5+ <title>FAQ | Jinja Template Engine</title>6+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />7+ <link rel="stylesheet" href="./static/style.css" type="text/css" />8+ <link rel="stylesheet" href="./static/print.css" type="text/css" media="print" />9+ <link rel="stylesheet" href="./static/pygments.css" type="text/css" />10+ </head>11+ <body>12+ <div id="header">13+ <h1>Jinja</h1>14+ </div>15+ <ul id="navigation">16+ <li><a href="./index.html">Index</a></li>17+ <li class="active">FAQ</li>18+ <li><a href="./documentation.html">Documentation</a></li>19+ <li><a href="./download.html">Download</a></li>20+ </ul>21+ <div id="content">22+ <div id="contentwrapper">23+ <h1>Frequently Asked Questions</h1>24+ <p>25+ Here a list of frequently asked questions.26+ </p>27+ <h2>Why the Name?</h2>28+ <p>29+ The name Jinja was chosen because it's the name of a Japanese temple and30+ temple and template share a similar pronunciation.31+ </p>32+ <h2>How fast is it?</h2>33+ <p>34+ I really hate benchmarks especially since they don't reflect much. The35+ performance of a template depends on many factors and you would have to36+ benchmark different engines in differen situations. However Jinja isn't37+ slow. The benchmarks from the testsuite show that Jinja is about twice38+ as fast as Django templates and about three times as slow as39+ <a href="http://www.makotemplates.org/">mako</a>. That's not bad for a40+ sandboxed template engine that has to sanitize template input on the fly.41+ If you really need the best performance of a template engine consider42+ using mako.43+ </p>44+ <h2>What happened to Jinja < 1?</h2>45+ <p>46+ Before Jinja 1 there was a template engine too with the same name. Beside47+ the name and the same maintainer those two projects don't share a single48+ line of code. If you have an application using Jinja < 1 you should try49+ to make it Jinja 1 compatible. If that's not possible, the old project is50+ still available as 51+ <a href="http://trac.pocoo.org/repos/jinja/branches/0.9-maint/">0.9-maint</a>52+ in the Jinja subversion repository.53+ </p>54+ <h2>Why should I use Jinja?</h2>55+ <p>56+ There are dozens of template engines for Python, many of them try to57+ achieve different things. If you are looking for a XML based template58+ engine have a look at <a href="http://genshi.edgewall.org/">genshi</a>,59+ if you want a bleezing fast template engine with the full range of60+ python constructs have a look at mako. If you want sandboxed templates61+ you probably want to check out Jinja.62+ </p>63+ </div>64+ <p id="meta">65+ <a href="./faq.tmpl">show template source</a>66+ </p>67+ </div>68+ <div id="footer">69+ © Copyright 2007 by the Pocoo Team.70+ </div>71+ </body>72+</html>added:www/faq.tmpl+44 added
1+<% extends 'layout/base.tmpl' %>2+<% block title %>FAQ<% endblock %>3+<% block content %>4+ <h1>Frequently Asked Questions</h1>5+ <p>6+ Here a list of frequently asked questions.7+ </p>8+ <h2>Why the Name?</h2>9+ <p>10+ The name Jinja was chosen because it's the name of a Japanese temple and11+ temple and template share a similar pronunciation.12+ </p>13+ <h2>How fast is it?</h2>14+ <p>15+ I really hate benchmarks especially since they don't reflect much. The16+ performance of a template depends on many factors and you would have to17+ benchmark different engines in differen situations. However Jinja isn't18+ slow. The benchmarks from the testsuite show that Jinja is about twice19+ as fast as Django templates and about three times as slow as20+ <a href="http://www.makotemplates.org/">mako</a>. That's not bad for a21+ sandboxed template engine that has to sanitize template input on the fly.22+ If you really need the best performance of a template engine consider23+ using mako.24+ </p>25+ <h2>What happened to Jinja < 1?</h2>26+ <p>27+ Before Jinja 1 there was a template engine too with the same name. Beside28+ the name and the same maintainer those two projects don't share a single29+ line of code. If you have an application using Jinja < 1 you should try30+ to make it Jinja 1 compatible. If that's not possible, the old project is31+ still available as 32+ <a href="http://trac.pocoo.org/repos/jinja/branches/0.9-maint/">0.9-maint</a>33+ in the Jinja subversion repository.34+ </p>35+ <h2>Why should I use Jinja?</h2>36+ <p>37+ There are dozens of template engines for Python, many of them try to38+ achieve different things. If you are looking for a XML based template39+ engine have a look at <a href="http://genshi.edgewall.org/">genshi</a>,40+ if you want a bleezing fast template engine with the full range of41+ python constructs have a look at mako. If you want sandboxed templates42+ you probably want to check out Jinja.43+ </p>44+<% endblock %>added:www/generate.py+46 added
1+#!/usr/bin/env python2+"""3+ jinja webpage generator4+ ~~~~~~~~~~~~~~~~~~~~~~~5+"""6+import os7+from codecs import open8+from jinja import Environment, FileSystemLoader9+from jinja.filters import stringfilter10+from pygments import highlight11+from pygments.lexers import get_lexer_by_name12+from pygments.formatters import HtmlFormatter13+14+15+formatter = HtmlFormatter(cssclass='syntax', encoding=None, style='pastie')16+17+env = Environment('<%', '%>', '<%=', '%>', loader=FileSystemLoader('.'), trim_blocks=True)18+env.filters['pygmentize'] = stringfilter(lambda v, l:19+ highlight(v.strip(), get_lexer_by_name(l), formatter))20+21+22+def get_files(folder):23+ for fn in os.listdir(folder):24+ fn = os.path.join(folder, fn)25+ if os.path.isdir(fn):26+ for item in get_files(fn):27+ yield item28+ elif fn.endswith('.tmpl'):29+ yield fn30+31+32+for filename in get_files('.'):33+ root = './' + ''.join(['../' for _ in os.path.dirname(filename).34+ split(os.path.sep)[1:]])35+36+ t = env.get_template(filename)37+ f = open(filename[:-5] + '.html', 'w', 'utf-8')38+ f.write(t.render(39+ file_id=filename[2:-5],40+ root=root41+ ))42+ f.close()43+44+f = file('static/pygments.css', 'w')45+f.write(formatter.get_style_defs('.syntax'))46+f.close()added:www/index.html+92 added
1+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML Frameset//EN"2+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">3+<html xmlns="http://www.w3.org/1999/xhtml">4+ <head>5+ <title>Index | Jinja Template Engine</title>6+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />7+ <link rel="stylesheet" href="./static/style.css" type="text/css" />8+ <link rel="stylesheet" href="./static/print.css" type="text/css" media="print" />9+ <link rel="stylesheet" href="./static/pygments.css" type="text/css" />10+ </head>11+ <body>12+ <div id="header">13+ <h1>Jinja</h1>14+ </div>15+ <ul id="navigation">16+ <li class="active">Index</li>17+ <li><a href="./faq.html">FAQ</a></li>18+ <li><a href="./documentation.html">Documentation</a></li>19+ <li><a href="./download.html">Download</a></li>20+ </ul>21+ <div id="content">22+ <div id="contentwrapper">23+ <h1>Jinja Templates</h1>24+ <p>25+ Jinja is a26+ <a href="http://en.wikipedia.org/wiki/Sandbox_%28computer_security%29">sandboxed</a>27+ template engine written in pure <a href="http://www.python.org/">Python</a>. It28+ provides a <a href="http://www.djangoproject.com/">Django</a>-like non-XML syntax29+ and compiles templates into executable python code. It's basically a combination30+ of Django templates and python code.31+ </p>32+ <h2>Nutshell</h2>33+ <div class="syntax"><pre><span class="cp">{%</span> <span class="k">extends</span> <span class="s1">'base.html'</span> <span class="cp">%}</span>34+<span class="cp">{%</span> <span class="k">block</span> <span class="nv">title</span> <span class="cp">%}</span>Memberlist<span class="cp">{%</span> <span class="k">endblock</span> <span class="cp">%}</span>35+<span class="cp">{%</span> <span class="k">block</span> <span class="nv">content</span> <span class="cp">%}</span>36+ <span class="nt"><ul></span>37+ <span class="cp">{%</span> <span class="k">for</span> <span class="nv">user</span> <span class="k">in</span> <span class="nv">users</span> <span class="cp">%}</span>38+ <span class="nt"><li><a</span> <span class="na">href=</span><span class="s">"</span><span class="cp">{{</span> <span class="nv">user.url</span><span class="o">|</span><span class="nf">e</span> <span class="cp">}}</span><span class="s">"</span><span class="nt">></span><span class="cp">{{</span> <span class="nv">user.username</span><span class="o">|</span><span class="nf">e</span> <span class="cp">}}</span><span class="nt"></a></li></span>39+ <span class="cp">{%</span> <span class="k">endfor</span> <span class="cp">%}</span>40+ <span class="nt"></ul></span>41+<span class="cp">{%</span> <span class="k">endblock</span> <span class="cp">%}</span>42+</pre></div>43+ <h2>Philosphy</h2>44+ <p>45+ Application logic is for the controller but don't try to make the live for the46+ template designer too hard by giving him too less functionality.47+ </p>48+ <h2>Features</h2>49+ <ul>50+ <li><strong>Simple API</strong>. For basic usage just one function is needed:51+<div class="syntax"><pre><span class="k">from</span> <span class="nn">jinja</span> <span class="k">import</span> <span class="n">from_string</span>52+<span class="k">print</span> <span class="n">from_string</span><span class="p">(</span><span class="s">'Hello {{ data }}!'</span><span class="p">)</span><span class="o">.</span><span class="n">render</span><span class="p">(</span><span class="n">data</span><span class="o">=</span><span class="s">'World'</span><span class="p">)</span>53+</pre></div>54+</li>55+ <li><strong>Sandboxed</strong>. The whole engine is completely sandboxed. A56+ template designer won't be able to modify application data or execute57+ dangerous code.</li>58+ <li><strong>Python expressions</strong>. You can use nearly every python59+ expression. Not supported are the binary operators and list comprehensions /60+ generator expressions.</li>61+ <li><strong>Inheritance</strong>. Jinja uses the same concept for inheritance62+ Django uses. It's very powerful and easy to understand.</li>63+ <li><strong>Macros</strong>. Jinja provides so called macros that allow you to64+ put often used template snippets into callable blocks:65+<div class="syntax"><pre><span class="cp">{%</span> <span class="k">macro</span> <span class="nv">dialog</span> <span class="nv">title</span><span class="o">,</span> <span class="nv">text</span> <span class="cp">%}</span>66+ <span class="nt"><div</span> <span class="na">class=</span><span class="s">"dialog"</span><span class="nt">></span>67+ <span class="nt"><h2</span> <span class="na">class=</span><span class="s">"title"</span><span class="nt">></span><span class="cp">{{</span> <span class="nv">title</span> <span class="cp">}}</span><span class="nt"></h2></span>68+ <span class="nt"><div</span> <span class="na">class=</span><span class="s">"text"</span><span class="nt">></span><span class="cp">{{</span> <span class="nv">text</span> <span class="cp">}}</span><span class="nt"></div></span>69+ <span class="nt"></div></span>70+<span class="cp">{%</span> <span class="k">endmacro</span> <span class="cp">%}</span>71+</pre></div>72+You can then use this block by calling it:73+<div class="syntax"><pre><span class="cp">{{</span> <span class="nv">dialog</span><span class="o">(</span><span class="s1">'Notification'</span><span class="o">,</span> <span class="s1">'Here the text for the macro.'</span><span class="o">)</span> <span class="cp">}}</span>74+</pre></div>75+</li>76+ <li><strong>Designer friendly</strong>. Jinja simplifies many things for a77+ template designer. Loops can be used in a recursive way, filters are78+ available to format values, loops know about their iteration etc.</li>79+ <li><strong>Dynamic Syntax</strong>. You don't like the Django block syntax?80+ You can override the syntax elements on environment initialisation. It's81+ no problem to use ASP/PHP/Ruby syntax, html comments for blocks etc.</li>82+ </ul>83+ </div>84+ <p id="meta">85+ <a href="./index.tmpl">show template source</a>86+ </p>87+ </div>88+ <div id="footer">89+ © Copyright 2007 by the Pocoo Team.90+ </div>91+ </body>92+</html>added:www/index.tmpl+65 added
1+<% extends 'layout/base.tmpl' %>2+<% block title %>Index<% endblock %>3+<% block content %>4+ <h1>Jinja Templates</h1>5+ <p>6+ Jinja is a7+ <a href="http://en.wikipedia.org/wiki/Sandbox_%28computer_security%29">sandboxed</a>8+ template engine written in pure <a href="http://www.python.org/">Python</a>. It9+ provides a <a href="http://www.djangoproject.com/">Django</a>-like non-XML syntax10+ and compiles templates into executable python code. It's basically a combination11+ of Django templates and python code.12+ </p>13+ <h2>Nutshell</h2>14+ <% filter pygmentize('html+jinja') %>15+{% extends 'base.html' %}16+{% block title %}Memberlist{% endblock %}17+{% block content %}18+ <ul>19+ {% for user in users %}20+ <li><a href="{{ user.url|e }}">{{ user.username|e }}</a></li>21+ {% endfor %}22+ </ul>23+{% endblock %}24+<% endfilter %>25+ <h2>Philosphy</h2>26+ <p>27+ Application logic is for the controller but don't try to make the live for the28+ template designer too hard by giving him too less functionality.29+ </p>30+ <h2>Features</h2>31+ <ul>32+ <li><strong>Simple API</strong>. For basic usage just one function is needed:33+<% filter pygmentize('python') %>34+from jinja import from_string35+print from_string('Hello {{ data }}!').render(data='World')36+<% endfilter %></li>37+ <li><strong>Sandboxed</strong>. The whole engine is completely sandboxed. A38+ template designer won't be able to modify application data or execute39+ dangerous code.</li>40+ <li><strong>Python expressions</strong>. You can use nearly every python41+ expression. Not supported are the binary operators and list comprehensions /42+ generator expressions.</li>43+ <li><strong>Inheritance</strong>. Jinja uses the same concept for inheritance44+ Django uses. It's very powerful and easy to understand.</li>45+ <li><strong>Macros</strong>. Jinja provides so called macros that allow you to46+ put often used template snippets into callable blocks:47+<% filter pygmentize('html+jinja') %>48+{% macro dialog title, text %}49+ <div class="dialog">50+ <h2 class="title">{{ title }}</h2>51+ <div class="text">{{ text }}</div>52+ </div>53+{% endmacro %}54+<% endfilter %>You can then use this block by calling it:55+<% filter pygmentize('html+jinja') %>56+{{ dialog('Notification', 'Here the text for the macro.') }}57+<% endfilter %></li>58+ <li><strong>Designer friendly</strong>. Jinja simplifies many things for a59+ template designer. Loops can be used in a recursive way, filters are60+ available to format values, loops know about their iteration etc.</li>61+ <li><strong>Dynamic Syntax</strong>. You don't like the Django block syntax?62+ You can override the syntax elements on environment initialisation. It's63+ no problem to use ASP/PHP/Ruby syntax, html comments for blocks etc.</li>64+ </ul>65+<% endblock %>