LIST_OF_TESTS = generate_list_of_tests()
LIST_OF_LOADERS = generate_list_of_loaders()
-TEMPLATE = e.from_string('''\
+FULL_TEMPLATE = e.from_string('''\
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
</html>\
''')
+PREPROC_TEMPLATE = e.from_string('''\
+<!-- TITLE -->{{ title }}<!-- ENDTITLE -->
+<!-- TOC -->{% for key, value in toc %}<li><a href="{{
+ key }}">{{ value }}</a></li>{% endfor %}<!-- ENDTOC -->
+<!-- BODY -->{{ body }}<!-- ENDBODY -->\
+''')
+
def pygments_directive(name, arguments, options, content, lineno,
content_offset, block_text, state, state_machine):
try:
}
-def handle_file(filename, fp, dst):
+def handle_file(filename, fp, dst, preproc):
now = datetime.now()
title = os.path.basename(filename)[:-4]
content = fp.read()
c['style'] = PYGMENTS_FORMATTER.get_style_defs('.syntax')
c['generation_date'] = now
c['file_id'] = title
- result.write(TEMPLATE.render(c).encode('utf-8'))
+ if preproc:
+ tmpl = PREPROC_TEMPLATE
+ else:
+ tmpl = FULL_TEMPLATE
+ result.write(tmpl.render(c).encode('utf-8'))
result.close()
-def run(dst, sources=()):
+def run(dst, preproc, sources=(), handle_file=handle_file):
path = os.path.abspath(os.path.join(os.path.dirname(__file__), 'src'))
if not sources:
sources = [os.path.join(path, fn) for fn in os.listdir(path)]
print 'Processing %s' % fn
f = open(fn)
try:
- handle_file(fn, f, dst)
+ handle_file(fn, f, dst, preproc)
finally:
f.close()
-def main(dst='build/', *sources):
- return run(os.path.realpath(dst), sources)
+def main(dst='build/', preproc=False, *sources):
+ run(os.path.realpath(dst), str(preproc).lower() == 'true', sources)
if __name__ == '__main__':
raise TypeError('cannot create %r instances' %
self.__class__.__name__)
+ def __add__(self, other):
+ return other
+ __sub__ = __mul__ = __div__ = __add__
+
def __getitem__(self, arg):
return self
KeyError.__init__(self, message)
+class TestArgumentError(TypeError, TemplateError):
+ """
+ An argument passed to a test function was invalid.
+ """
+
+ def __init__(self, message):
+ TypeError.__init__(self, message)
+
+
class TemplateNotFound(IOError, TemplateError):
"""
Raised if a template does not exist.
raise AssertionError('unhandled node %r' % node.__class__)
return out
+ def reset(self):
+ self.indention = 0
+ self.last_cycle_id = 0
+
+ def translate(self):
+ self.reset()
+ return self.handle_node(self.node)
+
# -- jinja nodes
def handle_template(self, node):
for n in node.nodes:
args.append(self.handle_node(n))
return '[%s]' % ':'.join(args)
-
- def reset(self):
- self.indention = 0
- self.last_cycle_id = 0
-
- def translate(self):
- self.reset()
- return self.handle_node(self.node)
<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>
+ <li><a href="./index.html">Index</a></li>
+ <li><a href="./faq.html">FAQ</a></li>
+ <li class="active"><a href="./documentation.html">Documentation</a></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:
+ Currently Jinja 1 in still under heavy development and we have neither
+ released a final version nor do we provide a documentation you can download.
+ However you can browse the documentation of the current SVN version online:
</p>
+ <p><a href="./documentation/index.html">browse online documentation</a></p>
</div>
- <p id="meta">
- <a href="./documentation.tmpl">show template source</a>
- </p>
</div>
<div id="footer">
© Copyright 2007 by the Pocoo Team.
<% extends 'layout/base.tmpl' %>
-<% block title %>Documentation<% endblock %>
+<% set title = 'Documentation' %>
+<% set active_page = 'documentation' %>
<% block content %>
<h1>Documentation</h1>
<p>
- You can browse the documentation either online or download it:
+ Currently Jinja 1 in still under heavy development and we have neither
+ released a final version nor do we provide a documentation you can download.
+ However you can browse the documentation of the current SVN version online:
</p>
+ <p><a href="./documentation/index.html">browse online documentation</a></p>
<% endblock %>
--- /dev/null
+<% extends 'layout/base.tmpl' %>
+<% set title = page_title + " | Documentation" %>
+<% set active_page = 'documentation' %>
+<% block content %>
+ <h1><%= page_title %></h1>
+ <% if page_toc %>
+ <h2 class="toc">Table Of Contents</h2>
+ <ul><%= page_toc %></ul>
+ <% endif %>
+ <%= page_body %>
+<% endblock %>
<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 class="active">Download</li>
- </ul>
+ <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 class="active"><a href="./download.html">Download</a></li>
+ </ul>
<div id="content">
<div id="contentwrapper">
<h1>Download</h1>
<a href="http://trac.pocoo.org/browser/jinja/trunk">here</a>.
</p>
</div>
- <p id="meta">
- <a href="./download.tmpl">show template source</a>
- </p>
</div>
<div id="footer">
© Copyright 2007 by the Pocoo Team.
<% extends 'layout/base.tmpl' %>
-<% block title %>Download<% endblock %>
+<% set title = 'Download' %>
+<% set active_page = 'download' %>
<% block content %>
<h1>Download</h1>
<p>
<h1>Jinja</h1>
</div>
<ul id="navigation">
- <li><a href="./index.html">Index</a></li>
- <li class="active">FAQ</li>
- <li><a href="./documentation.html">Documentation</a></li>
- <li><a href="./download.html">Download</a></li>
- </ul>
+ <li><a href="./index.html">Index</a></li>
+ <li class="active"><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">
<h1>Frequently Asked Questions</h1>
you probably want to check out Jinja.
</p>
</div>
- <p id="meta">
- <a href="./faq.tmpl">show template source</a>
- </p>
</div>
<div id="footer">
© Copyright 2007 by the Pocoo Team.
<% extends 'layout/base.tmpl' %>
-<% block title %>FAQ<% endblock %>
+<% set title = 'FAQ' %>
+<% set active_page = 'faq' %>
<% block content %>
<h1>Frequently Asked Questions</h1>
<p>
~~~~~~~~~~~~~~~~~~~~~~~
"""
import os
+import sys
+import re
from codecs import open
from jinja import Environment, FileSystemLoader
from jinja.filters import stringfilter
from pygments.lexers import get_lexer_by_name
from pygments.formatters import HtmlFormatter
+_data_re = re.compile(
+ r'<!-- TITLE -->(?P<page_title>.*?)<!-- ENDTITLE -->.*?'
+ r'<!-- TOC -->(?P<page_toc>.*?)<!-- ENDTOC -->.*?'
+ r'<!-- BODY -->(?P<page_body>.*?)<!-- ENDBODY -->(?sm)'
+)
formatter = HtmlFormatter(cssclass='syntax', encoding=None, style='pastie')
yield fn
+# generate static stuff
for filename in get_files('.'):
root = './' + ''.join(['../' for _ in os.path.dirname(filename).
split(os.path.sep)[1:]])
t = env.get_template(filename)
f = open(filename[:-5] + '.html', 'w', 'utf-8')
f.write(t.render(
- file_id=filename[2:-5],
root=root
))
f.close()
+ print filename
+# generate pygments stylesheet
f = file('static/pygments.css', 'w')
f.write(formatter.get_style_defs('.syntax'))
f.close()
+
+# generate documentation
+os.system(sys.executable + ' ../docs/generate.py documentation true')
+
+# render documentation with documentation template
+tmpl = env.get_template('documentation/item.tmpl')
+
+for filename in os.listdir('documentation'):
+ if not filename.endswith('.html'):
+ continue
+ filename = 'documentation/' + filename
+ f = open(filename, 'r', 'utf-8')
+ try:
+ data = f.read()
+ finally:
+ f.close()
+ match = _data_re.search(data)
+ if match is None:
+ continue
+ data = match.groupdict()
+ data['page_toc'] = data['page_toc'].strip()
+ if data['page_toc'].count('</li') < 2:
+ data['page_toc'] = ''
+ f = open(filename, 'w', 'utf-8')
+ f.write(tmpl.render(
+ root='./../',
+ **data
+ ))
+ f.close()
+ print 'postprocessed', filename
<h1>Jinja</h1>
</div>
<ul id="navigation">
- <li class="active">Index</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>
+ <li class="active"><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">
<h1>Jinja Templates</h1>
no problem to use ASP/PHP/Ruby syntax, html comments for blocks etc.</li>
</ul>
</div>
- <p id="meta">
- <a href="./index.tmpl">show template source</a>
- </p>
</div>
<div id="footer">
© Copyright 2007 by the Pocoo Team.
<% extends 'layout/base.tmpl' %>
-<% block title %>Index<% endblock %>
+<% set title = 'Index' %>
+<% set active_page = 'index' %>
<% block content %>
<h1>Jinja Templates</h1>
<p>
<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>
+ <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.
('documentation', 'Documentation'),
('download', 'Download')
] %>
-<% block code %><% endblock %>
<!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><% block title %>Untitled<% endblock %> | Jinja Template Engine</title>
+ <title><%= title or 'Untitled' %> | Jinja Template Engine</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" href="<%= root %>static/style.css" type="text/css" />
<link rel="stylesheet" href="<%= root %>static/print.css" type="text/css" media="print" />
</div>
<ul id="navigation">
<% for id, caption in navigation %>
- <% if id == file_id or id.startswith(file_id + '/') %>
- <li class="active"><%= caption|escape %></li>
- <% else %>
- <li><a href="<%= root %><%= id|escape %>.html"><%= caption|escape %></a></li>
- <% endif %>
+ <li<% if id == active_page %> class="active"<% endif
+ %>><a href="<%= root %><%= id|escape %>.html"><%= caption|escape
+ %></a></li>
<% endfor %>
</ul>
<% if trace %>
<div id="contentwrapper">
<% block content %><% endblock %>
</div>
- <p id="meta">
- <a href="<%= root + file_id + '.tmpl' %>">show template source</a>
- </p>
</div>
<div id="footer">
© Copyright 2007 by the Pocoo Team.
font-family: 'Bitstream Vera Sans Mono', 'Monaco', monospace;
}
+table.docutils {
+ border-collapse: collapse;
+ border: 2px solid #aaa;
+ margin: 0.5em 1.5em 0.5em 1.5em;
+}
+
+table.docutils td {
+ padding: 2px;
+ border: 1px solid #ddd;
+}
+
+dl {
+ margin-left: 10px;
+}
+
+li, dt {
+ margin-top: 5px;
+}
+
+dt {
+ font-weight: bold;
+}
+
+th {
+ text-align: left;
+ padding: 3px;
+ background-color: #f2f2f2;
+}
+
+tt {
+ font-size: 13px;
+ font-family: 'Bitstream Vera Sans Mono', 'Monaco', monospace;
+ color: black;
+ padding: 1px 2px 1px 2px;
+ background-color: #f0f0f0;
+}
+
+cite {
+ /* abusing <cite>, it's generated by ReST for `x` */
+ font-size: 13px;
+ font-family: 'Bitstream Vera Sans Mono', 'Monaco', monospace;
+ font-weight: bold;
+ font-style: normal;
+}
+
+div.admonition {
+ margin: 10px 0 10px 0;
+ padding: 10px;
+ border: 1px solid #ccc;
+ background-color: #f8f8f8;
+}
+
+div.admonition p.admonition-title {
+ margin: -3px 0 5px 0;
+ font-weight: bold;
+ color: #b41717;
+ font-size: 16px;
+}
+
+div.admonition p {
+ margin: 0 0 0 40px;
+}
+
#content {
background-color: white;
background-image: url(watermark.png);
border: 4px solid #ddd;
border-top: none;
background-color: #fff;
+ color: #999;
text-align: right;
- padding: 0 10px 5px 0;
+ padding: 0 20px 20px 0;
}
#contentwrapper {
font-weight: bold;
}
+#navigation li {
+ margin: 0;
+}
+
#navigation li a {
display: block;
text-decoration: none;
}
#navigation li.active {
- padding: 5px 10px 5px 10px;
background-color: #b41717;
- color: white;
+}
+
+#navigation li.active a {
+ color: #fff;
}
#navigation li a:focus {
margin: 20px 0 0 0;
}
-#meta {
- clear: both;
- text-align: right;
- color: #888;
- font-size: 13px;
+#contentwrapper h2.toc {
+ color: #222;
+ font-size: 16px;
+ margin: 20px 0 0 0;
}