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 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177
|
# -*- coding: utf-8 -*-
# Copyright (C) 2009 Søren Roug, European Environment Agency
#
# 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 Street, Fifth Floor, Boston, MA 02110-1301 USA
#
# Contributor(s):
#
from odf import grammar
from odf.namespaces import *
from odf import style, text
textfd = None
def header(module):
global textfd
print >>textfd, """<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-gb">
<head>
<title>ODFPY</title>
<link rel="stylesheet" type="text/css" href="../styles/screen.css" media="screen"/>
<link rel="stylesheet" type="text/css" href="../styles/print.css" media="print"/>
<script type="text/javascript" src="../styles/mark_special_links.js"></script>
</head>
<body>
<div id="container">
<div id="pagehead"> ODFPY - a Python library to manipulate ODF files </div>
<div class="breadcrumbtrail">
<div class="breadcrumbhead">You are here:</div>
<div class="breadcrumbitem">
<a href="/">ODFPY</a>
</div>
<div class="breadcrumbitem">
<a href="/manual">Manual</a>
</div>
<div class="breadcrumbitemlast">%s module</div>
<div class="breadcrumbtail"/>
</div>
<div id="leftcolumn">
<ul>
<li>
<a href="http://forge.osor.eu/projects/odfpy/">OSOR Project page</a>
</li>
<li>
<a href="http://pypi.python.org/pypi/odfpy/">Python package index</a>
</li>
<li>
<a href="http://forge.osor.eu/frs/?group_id=33">Download</a>
</li>
<li>
<a href="../manual">Manual</a>
</li>
<li>
<a href="../examples.html">Examples</a>
</li>
</ul>
</div>
<div id="content">
""" % module
def footer():
global textfd
print >>textfd, """
</div>
<!-- content -->
</div>
<!-- container -->
<div id="pagefoot"> søn mar 15 15:15:53 CET 2009 </div>
</body>
</html>"""
def elmcmp(e1, e2):
n1 = nsdict[e1[0]]
n2 = nsdict[e2[0]]
if cmp(n1,n2) != 0: return cmp(n1,n2)
return cmp(e1[1], e2[1])
def listofelements(elements, anytext, nonetext):
global textfd
if elements is None:
x = anytext
elif elements is () or elements is []:
x = nonetext
else:
elclasses = [ makehref(e) for e in elements]
elclasses.sort()
x = ", ".join(elclasses)
print >>textfd, """<span class="elements">%s</span>.""" % x
# Invert the children dictionary to construct parents
parents = {}
ns=''
for parent, children in grammar.allowed_children.items():
if children:
for child in children:
if not parents.has_key(child):
parents[child] = []
if not parent in parents[child]:
parents[child].append(parent)
def makeid(t):
return t[1].title().replace('-','')
def makehref(t):
return """<a href="%s.html#%s">%s.%s</a>""" % ( nsdict[t[0]], t[1].title().replace('-',''),
nsdict[t[0]], t[1].title().replace('-',''))
def makeclass(t):
return "%s.%s" % ( nsdict[t[0]], t[1].title().replace('-',''))
childkeys = grammar.allowed_children.keys()
childkeys.sort(elmcmp)
ns = ''
for element in childkeys:
children = grammar.allowed_children[element]
if ns != nsdict[element[0]]:
if ns != '':
footer()
textfd.close()
ns = nsdict[element[0]]
textfd = open("%s.html" % ns, "w")
header(ns)
print >>textfd, "<h1>%s module</h1>" % ns
classname = makeclass(element)
print >>textfd, """<h2 id="%s">%s</h2>""" % ( makeid(element), classname)
# Required attributes
print >>textfd, "<p>Requires the following attributes:",
required_attributes = grammar.required_attributes.get(element)
if required_attributes is None or required_attributes is ():
info = "No attribute is required"
else:
required_args = [ a[1].lower().replace('-','') for a in required_attributes]
required_args.sort()
info = ', '.join(required_args)
print >>textfd, """<span class="attributes">%s.</span></p>""" % info
# Allowed attributes
print >>textfd, "<p>Allows the following attributes:",
allowed_attrs = grammar.allowed_attributes.get(element)
if allowed_attrs is None or allowed_attrs is ():
info = "No attribute is allowed"
else:
allowed_args = [ a[1].lower().replace('-','') for a in allowed_attrs]
allowed_args.sort()
info = ', '.join(allowed_args)
print >>textfd, """<span class="attributes">%s.</span></p>""" % info
#PARENTS
print >>textfd, "<p>These elements contain %s:" % classname,
listofelements(parents.get(element),"This is a toplevel element","This is a toplevel element")
print >>textfd, "</p>"
#CHILDREN
print >>textfd, "<p>The following elements occur in %s: " % classname,
listofelements(children,"Any element is allowed","No element is allowed")
print >>textfd, "</p>"
|