1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
|
#!/usr/bin/python
"""
Reference documentation generator for Templayer
http://excess.org/templayer/
library to build dynamic html that provides clean separation of form
(html+css+javascript etc..) and function (python code) as well as
making cross-site scripting attacks and improperly generated html
very difficult.
Copyright (c) 2003-2006 Ian Ward
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
02110-1301, USA.
"""
import pydoc
import types
import templayer
html_template = """<html>
<head>
<title>Templayer ((version)) Reference</title>
<style type="text/css">
h1 { text-align: center; }
h2 { margin: 40px 0 0 0; padding: 10px; background: #6d96e8;}
h3 { margin: 0 0 3px 0; padding: 12px 6px 6px 6px; background: #efef96;}
.l1 { margin: 12px 0 0 0; }
.l2 { margin-left: 20px; }
</style>
<body>
<a name="top"></a>
<h1>Templayer ((version)) Reference</h1>
<div style="text-align: center;">
<a href="http://excess.org/templayer/">Templayer Home Page</a> /
<a href="tutorial.html">Tutorial</a> /
Reference
</div>
<br>
%toc%
<br>
%contents%
</body>
</html>"""
class TemplayerHTMLDoc( pydoc.HTMLDoc ):
def heading(self, title, fgcol, bgcol, extras=''):
return extras
def section(self, title, fgcol, bgcol, contents, width=6,
prelude='', marginalia=None, gap=' '):
if " = " in title:
visible, tail = title.split(" = ",1)
aname = tail.split('">',1)[0]
aname = aname.split('"',1)[1]
aname = aname.replace(" ","_")
title = '<a name="'+aname+'"></a>'+visible
return '<h3>%s <span style="font-size:small; padding-left: 20px">[<a href="#top">back to top</a>]</span></h3>%s' % (title,contents)
def namelink(self, name, *ignore):
return name
def classlink(self, obj, modname):
return obj.__name__
def modulelink(self, obj):
return obj.__name__
def modpkglink(self, (name, path, ispackage, shadowed) ):
return name
def markup(self, text, escape=None, funcs={}, classes={}, methods={}):
return pydoc.HTMLDoc.markup( self, text, escape )
def main():
html = TemplayerHTMLDoc()
contents = []
doc = []
contents.append('<table width="100%"><tr><td width="50%" valign="top">')
for obj, name in [
(None,"Template classes"),
(templayer.Template,"Template"),
(templayer.HTMLTemplate,"HTMLTemplate"),
(None,"Layer classes"),
(templayer.FileLayer,"FileLayer"),
(templayer.Layer,"Layer"),
(None,"HTML Markup"),
(templayer.expand_html_markup,"expand_html_markup"),
(templayer.RawHTML,"RawHTML"),
(None,None),
(None,"Utility functions"),
(templayer.html_url_encode,"html_url_encode"),
(templayer.html_href,"html_href"),
(templayer.html_target,"html_target"),
(templayer.html_escape,"html_escape"),
(templayer.django_form,"django_form"),
]:
if name is None:
contents.append('</td><td width="50%" valign="top">')
elif obj is None:
contents.append('<div class="l1">%s</div>' % name)
doc.append('<h2>%s</h2>' % name )
else:
lname = name
if type(obj) != types.ClassType: #dirty hack
doc.append('<a name="%s"></a><h3>function %s <span style="font-size:small; padding-left: 20px">[<a href="#top">back to top</a>]</span></h3>' % (name,name) )
lname = lname.replace(" ","_")
contents.append('<div class="l2">' +
'<a href="#%s">%s</a></div>' %
(lname,name) )
doc.append( html.document( obj, name ) )
contents.append("</td></tr></table>")
h = html_template
h = h.replace("%toc%", "".join(contents))
h = h.replace("%contents%", "".join(doc))
print h
if __name__ == "__main__":
main()
|