<%doc>formatting.myt - library of HTML formatting functions to operate on a TOCElement tree <%global> import string, re import highlight <%def printtocelement> <%doc>prints a TOCElement as a table of contents item and prints its immediate child items <%args> item includefile bold = False full = False children = True % if children: % <%def printsmtocelem> <%args> item includefile children = False <%method printtoc> <%args> root includefile current = None full = False children = True % header = False % for i in root.children: % if i.header: % if header: % % header = True <% i.header %>
% <& printtocelement, item=i, includefile = includefile, bold = (i == current and includefile), full = full, children=children &> % % if header:
% <%method paramtable> <% m.content() %>
<%method param> <%args> name classname type users = 'all' default = None version = None % if default is None: default = 'None' <&|SELF:fliprow, flip=True &> <% name %> (<% type %>)
% if users is not None: for users: <% users %>
% default: <% default %>
used by: <% classname %> % if version:
since version: <% version %> %
<&|SELF:fliprow, flip=False &>

<% m.content() %>

<%method function_doc> <%args> name = "" alt = None arglist = [] rettype = None <&|SELF:fliprow, flip=True&> <% name %>(<% string.join(map(lambda k: "%s" % k, arglist), ", ")%>) <&|SELF:fliprow, flip=False&>
<% m.content() %> % if alt is not None:

Also called as: <% alt %> %
<%method member_doc> <%args> name = "" type = None <&|SELF:fliprow, flip=True&> <% name %> <&|SELF:fliprow, flip=False&>
<% m.content() %>
<%method fliprow trim="both"> <%args>flip=True <%python> flipper = m.get_attribute("formatflipper") if flipper is None: flipper = Value("light") m.set_attribute("formatflipper", flipper) % if flip: flipper({"light":"dark", "dark": "light"}[flipper()]) <% m.content() %> <%method printitem> <%doc>prints the description and contents of a TOC element and recursively prints its child items <%args> item indentlevel = 0 includefile omitheader = False root = None % if root is None: root = item % if not omitheader: %
% if not omitheader: <% item.description %> %
<%python> regexp = re.compile(r"__FORMAT:LINK{(?:\@path=(.+?))?(?:\@xtra=(.+?))?(?:\@text=(.+?))?(?:\@href=(.+?))?(?:\@class=(.+?))?}") def link(matchobj): path = matchobj.group(1) xtra = matchobj.group(2) text = matchobj.group(3) href = matchobj.group(4) class_ = matchobj.group(5) if class_ is not None: class_ = 'class="%s"' % class_ else: class_ = '' if href: return '%s' % (href, class_, text or href) else: try: element = item.lookup(path) if xtra is not None: return '%s' % (element.get_link(includefile), xtra, class_, text or xtra) else: return '%s' % (element.get_link(includefile), class_, text or element.description) except KeyError: if xtra is not None: return '%s' % (text or xtra) else: return '%s' % text or path re2 = re.compile(r"'''PYESC(.+?)PYESC'''", re.S) content = regexp.sub(link, item.content) content = re2.sub(lambda m: m.group(1), content) #m.write(item.content) m.write(content)
% for i in item.children: <& printitem, item=i, indentlevel=indentlevel + 1, includefile = includefile, root=root &> % % if root is not None and len(item.children) == 0: back to section top % % if indentlevel == 0: % if includefile: <& SELF:pagenav, item=item, includefile=includefile &> % else:
% # %
<%method pagenav> <%args> item includefile
% if not includefile: Top | % % if item.previous is not None: Previous: <& SELF:itemlink, item=item.previous, includefile = includefile &> % # end if % if item.next is not None: % if item.previous is not None: | % # end if Next: <& SELF:itemlink, item=item.next, includefile = includefile &> % # end if
<%method formatplain> <%filter> import re f = re.sub(r'\n[\s\t]*\n[\s\t]*', '

\n

', f, re.S) f = "

" + f + "

" return f <% m.content() | h%> <%method itemlink trim="both"> <%args> item includefile <% item.description %> <%method codeline trim="both"> <% m.content() %> <%method code autoflush=False> <%args> title = None syntaxtype = 'myghty' html_escape = True <%init> def fix_indent(f): f =string.expandtabs(f, 4) g = '' lines = string.split(f, "\n") whitespace = None for line in lines: if whitespace is None: match = re.match(r"^([ ]*).+", line) if match is not None: whitespace = match.group(1) if whitespace is not None: line = re.sub(r"^%s" % whitespace, "", line) if whitespace is not None or re.search(r"\w", line) is not None: g += (line + "\n") return g.rstrip() content = highlight.highlight(fix_indent(m.content()), html_escape = html_escape, syntaxtype = syntaxtype)
% if title is not None:
<% title %>
%
<% content %>
<%method link trim="both"> <%args> path = None param = None method = None member = None text = None href = None class_ = None <%init> if href is None and path is None: path = m.comp('doclib.myt:current').path extra = (param or method or member) __FORMAT:LINK{<% path and "@path=" + path or "" %><% extra and "@xtra=" + extra or "" %><% text and "@text=" + text or "" %><% href and "@href=" + href or "" %><% class_ and "@class=" + class_ or "" %>} <%method popboxlink trim="both"> <%args> name=None show='show' hide='hide' <%init> if name is None: name = m.attributes.setdefault('popbox_name', 0) name += 1 m.attributes['popbox_name'] = name name = "popbox_" + repr(name) javascript:togglePopbox('<% name %>', '<% show %>', '<% hide %>') <%method popbox trim="both"> <%args> name = None class_ = None <%init> if name is None: name = 'popbox_' + repr(m.attributes['popbox_name']) <%method poplink trim="both"> <%args> link='sql' <%init> href = m.scomp('SELF:popboxlink') '''PYESC<& SELF:link, href=href, text=link, class_="codepoplink" &>PYESC''' <%method codepopper trim="both"> '''PYESC<&|SELF:popbox, class_="codepop" &><% m.content() %>PYESC''' <%method poppedcode trim="both"> '''PYESC
<% m.content() %>
PYESC'''