BartleBlog live!
I was thinking: how can I implement page previews in BartleBlog?
The obvious way is to render the page and open the local file. However, the page may link or include pieces that are not updated yet in the static version, so that can give confusing results.
Then it hit me... generate the page on the fly and serve it. And do the same for everything else the browser asks for.
So, after searching for 15 minutes for the simplest python "web framework" that let me use the code already in Bartleblog, and deciding for Colubrid...
Now, this is cute: bartleblog as a dynamic web app in 34 lines.
from colubrid import RegexApplication, HttpResponse, execute from BartleBlog.backend.blog import Blog import BartleBlog.backend.dbclasses as db import os, codecs class webBlog(Blog): def __init__(self): Blog.__init__(self) self.basepath='http://localhost:8080/' self.dest_dir=os.path.expanduser("~/.bartleblog/preview") if not os.path.isdir(self.dest_dir): os.mkdir(self.dest_dir) class MyApplication(RegexApplication): blog=webBlog() urls = [ (r'^(.*?)$', 'page'), (r'^(.*?)/(.*?)$', 'page'), (r'^(.*?)/(.*?)/(.*?)$', 'page'), (r'^(.*?)/(.*?)/(.*?)/(.*?)$', 'page') ] def page(self, *args): path=''.join(args) page=db.pageByPath(path) self.blog.renderPage(page) return HttpResponse(codecs.open(os.path.join(self.blog.dest_dir, path)).read()) app = MyApplication app = StaticExports(app, { '/static': './static' }) if __name__ == '__main__': execute(app)