[svn] jinja webpage update. (one dirty script more)

--HG--
branch : trunk
diff --git a/docs/generate.py b/docs/generate.py
index 0c155c0..a6dbb4e 100755
--- a/docs/generate.py
+++ b/docs/generate.py
@@ -109,7 +109,7 @@
 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>
@@ -156,6 +156,13 @@
 </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:
@@ -238,7 +245,7 @@
     }
 
 
-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()
@@ -248,11 +255,15 @@
     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)]
@@ -262,13 +273,13 @@
         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__':
diff --git a/jinja/datastructure.py b/jinja/datastructure.py
index 3b13ae0..c15519f 100644
--- a/jinja/datastructure.py
+++ b/jinja/datastructure.py
@@ -33,6 +33,10 @@
             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
 
diff --git a/jinja/exceptions.py b/jinja/exceptions.py
index c13725e..0873281 100644
--- a/jinja/exceptions.py
+++ b/jinja/exceptions.py
@@ -47,6 +47,15 @@
         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.
diff --git a/jinja/translators/python.py b/jinja/translators/python.py
index a71a4f5..4caddd9 100644
--- a/jinja/translators/python.py
+++ b/jinja/translators/python.py
@@ -232,6 +232,14 @@
             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):
@@ -851,11 +859,3 @@
         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)
diff --git a/www/documentation.html b/www/documentation.html
index 2edeb79..d674dfe 100644
--- a/www/documentation.html
+++ b/www/documentation.html
@@ -13,21 +13,21 @@
       <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">
       &copy; Copyright 2007 by the Pocoo Team.
diff --git a/www/documentation.tmpl b/www/documentation.tmpl
index 2e6fa97..49ae145 100644
--- a/www/documentation.tmpl
+++ b/www/documentation.tmpl
@@ -1,8 +1,12 @@
 <% 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 %>
diff --git a/www/documentation/item.tmpl b/www/documentation/item.tmpl
new file mode 100644
index 0000000..a5f3009
--- /dev/null
+++ b/www/documentation/item.tmpl
@@ -0,0 +1,11 @@
+<% 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 %>
diff --git a/www/download.html b/www/download.html
index 996fb38..277b46e 100644
--- a/www/download.html
+++ b/www/download.html
@@ -13,11 +13,11 @@
       <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>
@@ -41,9 +41,6 @@
     <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">
       &copy; Copyright 2007 by the Pocoo Team.
diff --git a/www/download.tmpl b/www/download.tmpl
index 53aac92..f8d8d19 100644
--- a/www/download.tmpl
+++ b/www/download.tmpl
@@ -1,5 +1,6 @@
 <% extends 'layout/base.tmpl' %>
-<% block title %>Download<% endblock %>
+<% set title = 'Download' %>
+<% set active_page = 'download' %>
 <% block content %>
   <h1>Download</h1>
   <p>
diff --git a/www/faq.html b/www/faq.html
index 7d0cadc..b0ff3b0 100644
--- a/www/faq.html
+++ b/www/faq.html
@@ -13,11 +13,11 @@
       <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>
@@ -61,9 +61,6 @@
     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">
       &copy; Copyright 2007 by the Pocoo Team.
diff --git a/www/faq.tmpl b/www/faq.tmpl
index 55eb8a3..630aeef 100644
--- a/www/faq.tmpl
+++ b/www/faq.tmpl
@@ -1,5 +1,6 @@
 <% extends 'layout/base.tmpl' %>
-<% block title %>FAQ<% endblock %>
+<% set title = 'FAQ' %>
+<% set active_page = 'faq' %>
 <% block content %>
   <h1>Frequently Asked Questions</h1>
   <p>
diff --git a/www/generate.py b/www/generate.py
index b68818b..6edd973 100755
--- a/www/generate.py
+++ b/www/generate.py
@@ -4,6 +4,8 @@
     ~~~~~~~~~~~~~~~~~~~~~~~
 """
 import os
+import sys
+import re
 from codecs import open
 from jinja import Environment, FileSystemLoader
 from jinja.filters import stringfilter
@@ -11,6 +13,11 @@
 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')
 
@@ -30,6 +37,7 @@
             yield fn
 
 
+# generate static stuff
 for filename in get_files('.'):
     root = './' + ''.join(['../' for _ in os.path.dirname(filename).
                            split(os.path.sep)[1:]])
@@ -37,11 +45,42 @@
     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
diff --git a/www/index.html b/www/index.html
index 8615465..c4fb8b8 100644
--- a/www/index.html
+++ b/www/index.html
@@ -13,11 +13,11 @@
       <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>
@@ -81,9 +81,6 @@
         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">
       &copy; Copyright 2007 by the Pocoo Team.
diff --git a/www/index.tmpl b/www/index.tmpl
index 6e7d4fe..a354486 100644
--- a/www/index.tmpl
+++ b/www/index.tmpl
@@ -1,5 +1,6 @@
 <% extends 'layout/base.tmpl' %>
-<% block title %>Index<% endblock %>
+<% set title = 'Index' %>
+<% set active_page = 'index' %>
 <% block content %>
   <h1>Jinja Templates</h1>
   <p>
diff --git a/www/layout/base.html b/www/layout/base.html
index c4fbe16..bcfd39d 100644
--- a/www/layout/base.html
+++ b/www/layout/base.html
@@ -13,17 +13,14 @@
       <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">
       &copy; Copyright 2007 by the Pocoo Team.
diff --git a/www/layout/base.tmpl b/www/layout/base.tmpl
index 8f6d8c5..b6317ff 100644
--- a/www/layout/base.tmpl
+++ b/www/layout/base.tmpl
@@ -4,12 +4,11 @@
   ('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" />
@@ -21,11 +20,9 @@
     </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 %>
@@ -43,9 +40,6 @@
       <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">
       &copy; Copyright 2007 by the Pocoo Team.
diff --git a/www/static/style.css b/www/static/style.css
index 9070d40..ff33585 100644
--- a/www/static/style.css
+++ b/www/static/style.css
@@ -48,6 +48,69 @@
     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);
@@ -62,8 +125,9 @@
     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 {
@@ -94,6 +158,10 @@
     font-weight: bold;
 }
 
+#navigation li {
+    margin: 0;
+}
+
 #navigation li a {
     display: block;
     text-decoration: none;
@@ -107,9 +175,11 @@
 }
 
 #navigation li.active {
-    padding: 5px 10px 5px 10px;
     background-color: #b41717;
-    color: white;
+}
+
+#navigation li.active a {
+    color: #fff;
 }
 
 #navigation li a:focus {
@@ -130,9 +200,8 @@
     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;
 }