PageRenderTime 22ms CodeModel.GetById 15ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

/examples/web/wiki/macros/include.py

https://bitbucket.org/prologic/circuits/
Python | 55 lines | 26 code | 18 blank | 11 comment | 9 complexity | c1caa85bae2ebd856eeef141458c2853 MD5 | raw file
 1"""Include macros
 2
 3Macros for inclusion of other wiki pages
 4"""
 5
 6from genshi import builder
 7
 8
 9def include(macro, environ, pagename=None, *args, **kwargs):
10    """Return the parsed content of the page identified by arg_string"""
11
12    if pagename is None:
13        return None
14
15    db = environ["db"]
16    page = db.get(pagename, None)
17
18    if page is not None:
19        environ["page.name"] = pagename
20
21        return environ["parser"].generate(page, environ=environ)
22
23
24def include_raw(macro, environ, pagename=None, *args, **kwargs):
25    """Return the raw text of the page identified by arg_string, rendered
26    in a <pre> block.
27    """
28
29    if pagename is None:
30        return None
31
32    db = environ["db"]
33    page = db.get(pagename, None)
34
35    if page is not None:
36        return builder.tag.pre(page, class_="plain")
37
38
39def include_source(macro, environ, pagename=None, *args, **kwargs):
40    """Return the parsed text of the page identified by arg_string, rendered
41    in a <pre> block.
42    """
43
44    if pagename is None:
45        return None
46
47    db = environ["db"]
48    page = db.get(pagename, None)
49
50    if page is not None:
51        environ["page.name"] = pagename
52
53        return builder.tag.pre(environ["parser"].render(
54            page,  environ=environ).decode("utf-8")
55        )