diff options
| author | Tres Seaver <tseaver@palladion.com> | 2008-07-16 15:32:03 +0000 |
|---|---|---|
| committer | Tres Seaver <tseaver@palladion.com> | 2008-07-16 15:32:03 +0000 |
| commit | a15e35f5f0978f3d524aea5eafc648fc220311d6 (patch) | |
| tree | c21db5151b4345524b8031a68e4f72b2d7e6de16 /repoze/bfg/push.py | |
| parent | d62151ed86b65b6f980bc64f666defed376d7354 (diff) | |
| download | pyramid-a15e35f5f0978f3d524aea5eafc648fc220311d6.tar.gz pyramid-a15e35f5f0978f3d524aea5eafc648fc220311d6.tar.bz2 pyramid-a15e35f5f0978f3d524aea5eafc648fc220311d6.zip | |
Added 'repoze.bfg.push:pushpage' decorator
o Creates BFG views from callables which take (context, request) and return
a mapping of top-level names.
Diffstat (limited to 'repoze/bfg/push.py')
| -rw-r--r-- | repoze/bfg/push.py | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/repoze/bfg/push.py b/repoze/bfg/push.py new file mode 100644 index 000000000..205c7f26e --- /dev/null +++ b/repoze/bfg/push.py @@ -0,0 +1,25 @@ +import os.path +from repoze.bfg.template import render_template + +class pushpage(object): + """ Decorator for functions which return template namespaces. + + E.g.: + + @pushpage('www/my_template.pt') + def my_view(context, request): + return {'a': 1, 'b': ()} + """ + def __init__(self, template): + self.template = template + + def __call__(self, wrapped): + prefix = os.path.dirname(wrapped.func_globals['__file__']) + path = os.path.join(prefix, self.template) + + def _curried(context, request): + kw = wrapped(context, request) + return render_template(path, **kw) + _curried.__name__ = wrapped.__name__ + + return _curried |
