-
Notifications
You must be signed in to change notification settings - Fork 0
/
juno-wiki.py
61 lines (47 loc) · 1.84 KB
/
juno-wiki.py
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
from juno import *
from wiki import Wiki
from tmpl import Tmpl, quote, unquote
init({'use_templates': False, 'use_db': False})
config('get_template_handler', lambda path: T.get(path))
config('render_template_handler', lambda tmpl, **kwargs: T.render(tmpl, kwargs))
wiki = Wiki()
class T(Tmpl):
_base = """<html>
<head><title>Wiki</title></head>
<body><h1>${block t}${endblock}</h1>${block c}${endblock}</body>
</html>"""
_index = """${extends base}
${block t}All Pages${endblock}
${block c}<ul>
${for page in pages}<li><a href="/view/${page|u}">${page|e}</a></li>${endfor}
</ul>${endblock}"""
_view = """${extends base}
${block t}${name|e}${endblock}
${block c}${text}<p><a href="/edit/${name|u}">Edit</a></p>${endblock}"""
_edit = """${extends base}
${block t}Edit ${name|e}${endblock}
${block c}<form method="post" action="/edit/${name|u}">
<textarea name="text" cols="60" rows="15">${text|e}</textarea><br/>
<input type="submit" value="Save"/>
or <a href="/view/${name|u}">Cancel</a>
</form>${endblock}"""
_404 = """${extends base}${block t}404 not found${endblock}${block c}${error}${endblock}"""
_500 = """${extends base}${block t}500 server error${endblock}${block c}${error}${endblock}"""
@get("/index")
def index(request):
template("index", pages=wiki.pages())
@get("/view/:name")
def view(request, name):
name = unquote(name)
template("view", name=name, text=Wiki.format(wiki.get_page(name), lambda n: "/view/%s" % quote(n)))
@get("/edit/:name")
def edit(request, name):
name = unquote(name)
template("edit", name=name, text=wiki.get_page(name))
@post("/edit/:name")
def save(request, name):
name = unquote(name)
wiki.set_page(name, request.input()['text'])
redirect("/view/%s" % quote(name))
if __name__ == '__main__':
run()