From 241390d911639cb658bbbbbf1bf3d8c21e0c0270 Mon Sep 17 00:00:00 2001 From: Malthe Borch Date: Mon, 24 Aug 2009 17:21:10 +0000 Subject: Added ZCML directive to serve up static files from a directory. --- repoze/bfg/zcml.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'repoze/bfg/zcml.py') 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.", -- cgit v1.2.3