[svn] jinja webpage update. (one dirty script more)
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 2b76513 · Browse files · 17 files·+212 added−80 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
17 files+212 added−80 removed
- other:+212 added−80 removed
Provenance
- Commit
9356b7b- Tree
9f0f81a- Author
Armin Ronacher <armin.ronacher@active-4.com>- Committer
Armin Ronacher <armin.ronacher@active-4.com>- Parent
2b76513
17 files changed+212 added−80 removed
modified:docs/generate.py+18 added-7 removed
107 unmodified lines108 LIST_OF_FILTERS = generate_list_of_filters()109 LIST_OF_TESTS = generate_list_of_tests()110 LIST_OF_LOADERS = generate_list_of_loaders()111 112-TEMPLATE = e.from_string('''\112+FULL_TEMPLATE = e.from_string('''\113 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"114 "http://www.w3.org/TR/html4/strict.dtd">115 <html>116 <head>38 unmodified lines155 file id: {{ file_id }} -->156 </html>\157 ''')158 159+PREPROC_TEMPLATE = e.from_string('''\160+<!-- TITLE -->{{ title }}<!-- ENDTITLE -->161+<!-- TOC -->{% for key, value in toc %}<li><a href="{{162+ key }}">{{ value }}</a></li>{% endfor %}<!-- ENDTOC -->163+<!-- BODY -->{{ body }}<!-- ENDBODY -->\164+''')165+166 def pygments_directive(name, arguments, options, content, lineno,167 content_offset, block_text, state, state_machine):168 try:169 lexer = get_lexer_by_name(arguments[0])74 unmodified lines244 'toc': parts['toc']245 }246 247 241-def handle_file(filename, fp, dst):248+def handle_file(filename, fp, dst, preproc):249 now = datetime.now()250 title = os.path.basename(filename)[:-4]251 content = fp.read()252 parts = generate_documentation(content, (lambda x: './%s.html' % x))1 unmodified line254 c = dict(parts)255 c['style'] = PYGMENTS_FORMATTER.get_style_defs('.syntax')256 c['generation_date'] = now257 c['file_id'] = title258+ if preproc:259+ tmpl = PREPROC_TEMPLATE260+ else:261+ tmpl = FULL_TEMPLATE251- result.write(TEMPLATE.render(c).encode('utf-8'))262+ result.write(tmpl.render(c).encode('utf-8'))263 result.close()264 265 255-def run(dst, sources=()):266+def run(dst, preproc, sources=(), handle_file=handle_file):267 path = os.path.abspath(os.path.join(os.path.dirname(__file__), 'src'))268 if not sources:269 sources = [os.path.join(path, fn) for fn in os.listdir(path)]270 for fn in sources:1 unmodified line272 continue273 print 'Processing %s' % fn274 f = open(fn)275 try:265- handle_file(fn, f, dst)276+ handle_file(fn, f, dst, preproc)277 finally:278 f.close()279 280 270-def main(dst='build/', *sources):271- return run(os.path.realpath(dst), sources)281+def main(dst='build/', preproc=False, *sources):282+ run(os.path.realpath(dst), str(preproc).lower() == 'true', sources)283 284 285 if __name__ == '__main__':286 main(*sys.argv[1:])modified:jinja/translators/python.py+8 added-8 removed
230 unmodified lines231 else:232 raise AssertionError('unhandled node %r' % node.__class__)233 return out234 235+ def reset(self):236+ self.indention = 0237+ self.last_cycle_id = 0238+239+ def translate(self):240+ self.reset()241+ return self.handle_node(self.node)242+243 # -- jinja nodes244 245 def handle_template(self, node):246 """611 unmodified lines858 args = []859 for n in node.nodes:860 args.append(self.handle_node(n))861 return '[%s]' % ':'.join(args)854-855- def reset(self):856- self.indention = 0857- self.last_cycle_id = 0858-859- def translate(self):860- self.reset()861- return self.handle_node(self.node)modified:jinja/datastructure.py+4 added
31 unmodified lines32 else:33 raise TypeError('cannot create %r instances' %34 self.__class__.__name__)35 36+ def __add__(self, other):37+ return other38+ __sub__ = __mul__ = __div__ = __add__39+40 def __getitem__(self, arg):41 return self42 43 def __iter__(self):303 unmodified linesmodified:jinja/exceptions.py+9 added
45 unmodified lines46 def __init__(self, message):47 KeyError.__init__(self, message)48 49 50+class TestArgumentError(TypeError, TemplateError):51+ """52+ An argument passed to a test function was invalid.53+ """54+55+ def __init__(self, message):56+ TypeError.__init__(self, message)57+58+59 class TemplateNotFound(IOError, TemplateError):60 """61 Raised if a template does not exist.62 """20 unmodified linesadded:www/documentation/item.tmpl+11 added
1+<% extends 'layout/base.tmpl' %>2+<% set title = page_title + " | Documentation" %>3+<% set active_page = 'documentation' %>4+<% block content %>5+ <h1><%= page_title %></h1>6+ <% if page_toc %>7+ <h2 class="toc">Table Of Contents</h2>8+ <ul><%= page_toc %></ul>9+ <% endif %>10+ <%= page_body %>11+<% endblock %>modified:www/layout/base.html+5 added-8 removed
11 unmodified lines1213141516171819201617181920212223242526242526272 unmodified lines11 unmodified lines <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> <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>2 unmodified linesmodified:www/layout/base.tmpl+4 added-10 removed
2 unmodified lines3 ('faq', 'FAQ'),4 ('documentation', 'Documentation'),5 ('download', 'Download')6 ] %>7-<% block code %><% endblock %>7 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML Frameset//EN"8 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">9 <html xmlns="http://www.w3.org/1999/xhtml">10 <head>12- <title><% block title %>Untitled<% endblock %> | Jinja Template Engine</title>11+ <title><%= title or 'Untitled' %> | Jinja Template Engine</title>12 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />13 <link rel="stylesheet" href="<%= root %>static/style.css" type="text/css" />14 <link rel="stylesheet" href="<%= root %>static/print.css" type="text/css" media="print" />15 <link rel="stylesheet" href="<%= root %>static/pygments.css" type="text/css" />3 unmodified lines19 <h1>Jinja</h1>20 </div>21 <ul id="navigation">22 <% 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 %>23+ <li<% if id == active_page %> class="active"<% endif24+ %>><a href="<%= root %><%= id|escape %>.html"><%= caption|escape25+ %></a></li>26 <% endfor %>27 </ul>28 <% if trace %>29 <div id="trace">9 unmodified lines39 <div id="content">40 <div id="contentwrapper">41 <% block content %><% endblock %>42 </div>46- <p id="meta">47- <a href="<%= root + file_id + '.tmpl' %>">show template source</a>48- </p>43 </div>44 <div id="footer">45 © Copyright 2007 by the Pocoo Team.46 </div>2 unmodified linesmodified:www/static/style.css+77 added-8 removed
46 unmodified lines47 font-size: 13px;48 font-family: 'Bitstream Vera Sans Mono', 'Monaco', monospace;49 }50 51+table.docutils {52+ border-collapse: collapse;53+ border: 2px solid #aaa;54+ margin: 0.5em 1.5em 0.5em 1.5em;55+}56+57+table.docutils td {58+ padding: 2px;59+ border: 1px solid #ddd;60+}61+62+dl {63+ margin-left: 10px;64+}65+66+li, dt {67+ margin-top: 5px;68+}69+70+dt {71+ font-weight: bold;72+}73+74+th {75+ text-align: left;76+ padding: 3px;77+ background-color: #f2f2f2;78+}79+80+tt {81+ font-size: 13px;82+ font-family: 'Bitstream Vera Sans Mono', 'Monaco', monospace;83+ color: black;84+ padding: 1px 2px 1px 2px;85+ background-color: #f0f0f0;86+}87+88+cite {89+ /* abusing <cite>, it's generated by ReST for `x` */90+ font-size: 13px;91+ font-family: 'Bitstream Vera Sans Mono', 'Monaco', monospace;92+ font-weight: bold;93+ font-style: normal;94+}95+96+div.admonition {97+ margin: 10px 0 10px 0;98+ padding: 10px;99+ border: 1px solid #ccc;100+ background-color: #f8f8f8;101+}102+103+div.admonition p.admonition-title {104+ margin: -3px 0 5px 0;105+ font-weight: bold;106+ color: #b41717;107+ font-size: 16px;108+}109+110+div.admonition p {111+ margin: 0 0 0 40px;112+}113+114 #content {115 background-color: white;116 background-image: url(watermark.png);117 padding: 10px;6 unmodified lines124 margin: 0 25px 25px 25px;125 border: 4px solid #ddd;126 border-top: none;127 background-color: #fff;128+ color: #999;129 text-align: right;66- padding: 0 10px 5px 0;130+ padding: 0 20px 20px 0;131 }132 133 #contentwrapper {134 max-width: 700px;22 unmodified lines157 list-style: none;158 font-weight: bold;159 }160 161+#navigation li {162+ margin: 0;163+}164+165 #navigation li a {166 display: block;167 text-decoration: none;168 padding: 5px 10px 5px 10px;5 unmodified lines174 background-color: #444;175 }176 177 #navigation li.active {110- padding: 5px 10px 5px 10px;178 background-color: #b41717;112- color: white;179 }180 181+#navigation li.active a {182+ color: #fff;183+}184+185 #navigation li a:focus {186 outline: none;187 background-color: #222;188 color: #fff;10 unmodified lines199 font-size: 20px;200 margin: 20px 0 0 0;201 }202 133-#meta {134- clear: both;135- text-align: right;136- color: #888;137- font-size: 13px;203+#contentwrapper h2.toc {204+ color: #222;205+ font-size: 16px;206+ margin: 20px 0 0 0;207 }modified:www/documentation.html+9 added-9 removed
11 unmodified lines12 <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 class="active">Documentation</li>19- <li><a href="./download.html">Download</a></li>20- </ul>16+ <li><a href="./index.html">Index</a></li>17+ <li><a href="./faq.html">FAQ</a></li>18+ <li class="active"><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>Documentation</h1>24 <p>25- You can browse the documentation either online or download it:25+ Currently Jinja 1 in still under heavy development and we have neither26+ released a final version nor do we provide a documentation you can download.27+ However you can browse the documentation of the current SVN version online:28 </p>29+ <p><a href="./documentation/index.html">browse online documentation</a></p>30 </div>28- <p id="meta">29- <a href="./documentation.tmpl">show template source</a>30- </p>31 </div>32 <div id="footer">33 © Copyright 2007 by the Pocoo Team.34 </div>2 unmodified linesmodified:www/documentation.tmpl+6 added-2 removed
1 <% extends 'layout/base.tmpl' %>2-<% block title %>Documentation<% endblock %>2+<% set title = 'Documentation' %>3+<% set active_page = 'documentation' %>4 <% block content %>5 <h1>Documentation</h1>6 <p>6- You can browse the documentation either online or download it:7+ Currently Jinja 1 in still under heavy development and we have neither8+ released a final version nor do we provide a documentation you can download.9+ However you can browse the documentation of the current SVN version online:10 </p>11+ <p><a href="./documentation/index.html">browse online documentation</a></p>12 <% endblock %>modified:www/download.html+5 added-8 removed
11 unmodified lines12 <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>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"><a href="./download.html">Download</a></li>20+ </ul>21 <div id="content">22 <div id="contentwrapper">23 <h1>Download</h1>24 <p>15 unmodified lines40 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>44 </div>45 <div id="footer">46 © Copyright 2007 by the Pocoo Team.47 </div>2 unmodified linesmodified:www/download.tmpl+2 added-1 removed
1 <% extends 'layout/base.tmpl' %>2-<% block title %>Download<% endblock %>2+<% set title = 'Download' %>3+<% set active_page = 'download' %>4 <% block content %>5 <h1>Download</h1>6 <p>7 If you want to install the release with18 unmodified linesmodified:www/faq.html+5 added-8 removed
11 unmodified lines12 <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>16+ <li><a href="./index.html">Index</a></li>17+ <li class="active"><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>Frequently Asked Questions</h1>24 <p>35 unmodified lines60 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>64 </div>65 <div id="footer">66 © Copyright 2007 by the Pocoo Team.67 </div>2 unmodified linesmodified:www/faq.tmpl+2 added-1 removed
1 <% extends 'layout/base.tmpl' %>2-<% block title %>FAQ<% endblock %>2+<% set title = 'FAQ' %>3+<% set active_page = 'faq' %>4 <% block content %>5 <h1>Frequently Asked Questions</h1>6 <p>7 Here a list of frequently asked questions.38 unmodified linesmodified:www/generate.py+40 added-1 removed
2 unmodified lines3 jinja webpage generator4 ~~~~~~~~~~~~~~~~~~~~~~~5 """6 import os7+import sys8+import re9 from codecs import open10 from jinja import Environment, FileSystemLoader11 from jinja.filters import stringfilter12 from pygments import highlight13 from pygments.lexers import get_lexer_by_name14 from pygments.formatters import HtmlFormatter15 16+_data_re = re.compile(17+ r'<!-- TITLE -->(?P<page_title>.*?)<!-- ENDTITLE -->.*?'18+ r'<!-- TOC -->(?P<page_toc>.*?)<!-- ENDTOC -->.*?'19+ r'<!-- BODY -->(?P<page_body>.*?)<!-- ENDBODY -->(?sm)'20+)21 22 formatter = HtmlFormatter(cssclass='syntax', encoding=None, style='pastie')23 24 env = Environment('<%', '%>', '<%=', '%>', loader=FileSystemLoader('.',11 unmodified lines36 elif fn.endswith('.tmpl'):37 yield fn38 39 40+# generate static stuff41 for filename in get_files('.'):42 root = './' + ''.join(['../' for _ in os.path.dirname(filename).43 split(os.path.sep)[1:]])44 45 t = env.get_template(filename)46 f = open(filename[:-5] + '.html', 'w', 'utf-8')47 f.write(t.render(40- file_id=filename[2:-5],48 root=root49 ))50 f.close()51+ print filename52 53+# generate pygments stylesheet54 f = file('static/pygments.css', 'w')55 f.write(formatter.get_style_defs('.syntax'))56 f.close()57+58+# generate documentation59+os.system(sys.executable + ' ../docs/generate.py documentation true')60+61+# render documentation with documentation template62+tmpl = env.get_template('documentation/item.tmpl')63+64+for filename in os.listdir('documentation'):65+ if not filename.endswith('.html'):66+ continue67+ filename = 'documentation/' + filename68+ f = open(filename, 'r', 'utf-8')69+ try:70+ data = f.read()71+ finally:72+ f.close()73+ match = _data_re.search(data)74+ if match is None:75+ continue76+ data = match.groupdict()77+ data['page_toc'] = data['page_toc'].strip()78+ if data['page_toc'].count('</li') < 2:79+ data['page_toc'] = ''80+ f = open(filename, 'w', 'utf-8')81+ f.write(tmpl.render(82+ root='./../',83+ **data84+ ))85+ f.close()86+ print 'postprocessed', filenamemodified:www/index.html+5 added-8 removed
11 unmodified lines12 <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>16+ <li class="active"><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><a href="./download.html">Download</a></li>20+ </ul>21 <div id="content">22 <div id="contentwrapper">23 <h1>Jinja Templates</h1>24 <p>55 unmodified lines80 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>84 </div>85 <div id="footer">86 © Copyright 2007 by the Pocoo Team.87 </div>2 unmodified linesmodified:www/index.tmpl+2 added-1 removed
1 <% extends 'layout/base.tmpl' %>2-<% block title %>Index<% endblock %>2+<% set title = 'Index' %>3+<% set active_page = 'index' %>4 <% block content %>5 <h1>Jinja Templates</h1>6 <p>7 Jinja is a59 unmodified lines