Skip to content

Commit

Permalink
routr.static: fix
Browse files Browse the repository at this point in the history
  • Loading branch information
andreypopp committed Jul 21, 2012
1 parent 6b26234 commit baadc7f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
5 changes: 5 additions & 0 deletions CHANGES
@@ -1,3 +1,8 @@
0.3.1
-----

* fix ``routr.static`` behaviour

0.3
---

Expand Down
14 changes: 9 additions & 5 deletions routr/static.py
Expand Up @@ -8,17 +8,21 @@
"""

from os.path import join
from webob.static import FileApp
from routr import route, GET

__all__ = ("static", "static_view")
__all__ = ("static",)

def static(prefix, directory):
""" Define a route which serves static files"""
if prefix.endswith("/"):
prefix = prefix[:-1]
return route(GET, "%s/{path:path}" % prefix, static_view)
return route(GET, "%s/{path:path}" % prefix, make_static_view(directory))

def static_view(request, path):
""" View for serving static files"""
return FileApp(path)(request)
def make_static_view(directory):
def static_view(request, path):
""" View for serving static files"""
return FileApp(join(directory, path))(request)
static_view.static_view = True
return static_view

0 comments on commit baadc7f

Please sign in to comment.