Mercurial > hg > SimpleWiki
changeset 2:2464e2051b78
[mq]: index
author | Jeff Hammel <jhammel@mozilla.com> |
---|---|
date | Tue, 07 Sep 2010 21:00:46 -0700 |
parents | 4c83f7715993 |
children | 56ab6b90cd1a |
files | simplewiki/dispatcher.py simplewiki/handlers.py simplewiki/templates/index.html simplewiki/templates/navigation.html |
diffstat | 4 files changed, 35 insertions(+), 32 deletions(-) [+] |
line wrap: on
line diff
--- a/simplewiki/dispatcher.py Tue Sep 07 18:11:04 2010 -0700 +++ b/simplewiki/dispatcher.py Tue Sep 07 21:00:46 2010 -0700 @@ -5,7 +5,7 @@ import os -from handlers import GenshiRenderer +from handlers import GenshiRenderer, Index from genshi.template import TemplateLoader from paste.fileapp import FileApp @@ -30,7 +30,7 @@ assert self.directory and os.path.exists(self.directory), "Must specify an existing directory" # request handlers - self.handlers = [ GenshiRenderer ] + self.handlers = [ GenshiRenderer, Index ] # template loader self.template_dirs = self.template_dirs.split()
--- a/simplewiki/handlers.py Tue Sep 07 18:11:04 2010 -0700 +++ b/simplewiki/handlers.py Tue Sep 07 21:00:46 2010 -0700 @@ -84,8 +84,35 @@ return getattr(self, self.request.method.title())() def Get(self): - # needs to have self.template set template = self.app.loader.load(self.template) return Response(content_type='text/html', body=template.generate(**self.data).render('html')) + +class Index(Handler): + + template = 'index.html' + + def __init__(self, app, request): + Handler.__init__(self, app, request) + self.directory = os.path.join(app.directory, *request.environ['path']) + if not os.path.isdir(self.directory): + raise HandlerMatchException + path = request.environ['path'] + files = [] + files = os.listdir(self.directory) + self.data = { 'request': request, + 'link': self.link, + 'directory': '/' + '/'.join(path), + 'files': files } + + def __call__(self): + return getattr(self, self.request.method.title())() + + def Get(self): + if not self.request.path_info.endswith('/'): + self.redirect(self.request.path_info + '/') + template = self.app.loader.load(self.template) + return Response(content_type='text/html', + body=template.generate(**self.data).render('html')) +
--- a/simplewiki/templates/index.html Tue Sep 07 18:11:04 2010 -0700 +++ b/simplewiki/templates/index.html Tue Sep 07 21:00:46 2010 -0700 @@ -5,18 +5,12 @@ xmlns:py="http://genshi.edgewall.org/" xmlns:xi="http://www.w3.org/2001/XInclude"> <head> -<title>Hello world</title> -<script src="${link('jquery.js')}"></script> -<script type="text/javascript"> -$(document).ready(function(){ -$(".text-input").click(function(){ -$(this).replaceWith('<form method="post"><input type="text" name="name" value="${name}"/><input type="submit" value="Go!"/></form>'); -}); -}); -</script> +<title>${directory}</title> </head> <body> -<xi:include href="navigation.html" /> -Hello <span class="text-input">${name}</span>! +<ul> + <li py:if="request.path_info != '/'"><a href="..">..</a></li> + <li py:for="f in files"><a href="${f}">${f}</a></li> +</ul> </body> </html>
--- a/simplewiki/templates/navigation.html Tue Sep 07 18:11:04 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,18 +0,0 @@ -<!DOCTYPE html - PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" - "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> -<html xmlns="http://www.w3.org/1999/xhtml" - xmlns:py="http://genshi.edgewall.org/" - xmlns:xi="http://www.w3.org/2001/XInclude" - py:strip="True"> - - <!-- nav bar --> - <div class="site-nav"> - <ul> - <li py:for="link, name in links"> - <a href="${link}">${name}</a> - </li> - </ul> - </div> - -</html>