Created
May 10, 2013 14:53
-
-
Save diyan/5554903 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from jinja2 import evalcontextfilter, escape | |
from markdown import Markdown | |
from bottle import app, route, run, redirect, static_file | |
from bottle import jinja2_template as template | |
""" | |
import bottle | |
from bottle_debugtoolbar import DebugToolbarPlugin | |
config = { | |
'DEBUG_TB_ENABLED': True, | |
'DEBUG_TB_INTERCEPT_REDIRECTS': True, | |
} | |
plugin = DebugToolbarPlugin(config) | |
bottle.install(plugin) | |
""" | |
class StripTrailingSlashMiddleware(object): | |
def __init__(self, app): | |
self.app = app | |
def __call__(self, e, h): | |
e['PATH_INFO'] = e['PATH_INFO'].rstrip('/') | |
return self.app(e, h) | |
@evalcontextfilter | |
def markdown_filter(eval_ctx, stream): | |
if eval_ctx.autoescape: | |
return Markdown().convert(escape(stream)) | |
else: | |
return Markdown().convert(stream) | |
@route('/static/<file_path:path>') | |
def send_static(file_path): | |
return static_file(file_path, root='static') | |
@route('/docs') | |
def doc_root(): | |
#return redirect(url('show_doc_entry', page='index')) | |
return redirect('/docs/index') | |
@route('/docs/<page>', name='show_doc_entry') | |
def show_doc_entry(page='index'): | |
return template( | |
'templates/docs/{0}.md'.format(page), | |
page=page, | |
template_settings={'filters': {'markdown': markdown_filter}}) | |
@route('/hello') | |
def hello(): | |
return "Hello World!" | |
@route('/') | |
def root(): | |
return redirect('/docs') | |
app = StripTrailingSlashMiddleware(app()) | |
run(app=app, host='localhost', port=8080, debug=True, reloader=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment