summaryrefslogtreecommitdiff
path: root/repoze/bfg/zcml.py
diff options
context:
space:
mode:
authorMalthe Borch <mborch@gmail.com>2009-08-24 17:21:10 +0000
committerMalthe Borch <mborch@gmail.com>2009-08-24 17:21:10 +0000
commit241390d911639cb658bbbbbf1bf3d8c21e0c0270 (patch)
tree7ebcc33709c8c715debf9b94e5157a1464df260c /repoze/bfg/zcml.py
parent45b545c377945812a83d926d11f1635d279069a6 (diff)
downloadpyramid-241390d911639cb658bbbbbf1bf3d8c21e0c0270.tar.gz
pyramid-241390d911639cb658bbbbbf1bf3d8c21e0c0270.tar.bz2
pyramid-241390d911639cb658bbbbbf1bf3d8c21e0c0270.zip
Added ZCML directive to serve up static files from a directory.
Diffstat (limited to 'repoze/bfg/zcml.py')
-rw-r--r--repoze/bfg/zcml.py34
1 files changed, 34 insertions, 0 deletions
diff --git a/repoze/bfg/zcml.py b/repoze/bfg/zcml.py
index 7c1a74ec2..e38fd3449 100644
--- a/repoze/bfg/zcml.py
+++ b/repoze/bfg/zcml.py
@@ -46,6 +46,7 @@ from repoze.bfg.security import ViewPermissionFactory
from repoze.bfg.secpols import registerBBBAuthn
+from repoze.bfg.view import static as static_view
import martian
@@ -338,6 +339,39 @@ def connect_route(path, name, factory):
mapper = getUtility(IRoutesMapper)
mapper.connect(path, name, factory)
+class IStaticDirective(Interface):
+ name = TextLine(
+ title=u"The URL prefix of the static view",
+ description=u"""
+ The directory will be served up for the route that starts with
+ this prefix.""",
+ required=True)
+
+ path = TextLine(
+ title=u'Path to the directory which contains resources',
+ description=u'May be package-relative by using a colon to '
+ 'seperate package name and path relative to the package directory.',
+ required=True)
+
+ cache_max_age = Int(
+ title=u"Cache maximum age",
+ required=False,
+ default=None)
+
+def static(_context, name, path, cache_max_age=3600):
+ """ Handle ``static`` ZCML directives
+ """
+
+ if ':' in path:
+ package_name, path = path.split(':')
+ else:
+ package_name = _context.resolve('.').__name__
+
+ view = static_view(
+ path, cache_max_age=cache_max_age, package_name=package_name)
+
+ route(_context, name, "%s*subpath" % name, view=view)
+
class IViewDirective(Interface):
for_ = GlobalObject(
title=u"The interface or class this view is for.",