Permalink
Browse files

Ability to control fragment parameter od breve.Template.render

  • Loading branch information...
momyc committed Dec 18, 2012
1 parent 99d0c84 commit 3023965762dce4e2f85481fcb160133e210e003b
Showing with 34 additions and 18 deletions.
  1. +26 −6 README.md
  2. +7 −11 pyramid_breve.py
  3. +1 −1 setup.py
View
@@ -35,7 +35,18 @@ pyramid.includes =
Configuration parameters
------------------------
-`pyramid_breve.BreveRendererFactory` will pass the following configuration parameters to `breve.Template` constructor:
+There are few configuration parameters that control rendering. They can be set in INI-file as following:
+
+```
+[app:main]
+# other application parameters ...
+
+breve.tags = my_package.breve.tags
+breve.doctype = html
+breve.fragment = on
+```
+
+Breve renderer accepts following parameters:
* _breve.tags_
@@ -49,14 +60,23 @@ Configuration parameters
Will be sent as-is to the constructor.
Default is content of `breve.tags.html.xmlns`.
+* _breve.fragment_
-To configure it via INI-file add parameters as following:
+ This boolean variable will be used as `fragment` parameter to breve.Template.render call. This parameter
+ can be also controlled by setting `breve_fragment` template variable as following:
+```python
+
+@view_config(renderer='templates/home.b')
+def home_view(request):
+ return {
+ # other variables used in template
+ 'breve_fragment': True,
+ }
```
-[app:main]
-breve.tags = my_package.breve.tags
-breve.doctype = html6
-```
+
+ Template variable `breve_fragment` overrides global `breve.fragment` setting. If none is set default is False.
+
Notes
-----
View
@@ -2,6 +2,7 @@
import re
from zope.interface import implements
from pyramid.interfaces import IRendererFactory
+from pyramid.settings import asbool
from pyramid.path import AssetResolver, DottedNameResolver
from breve import Template
from breve.tags import html
@@ -14,29 +15,24 @@ def includeme(config):
class BreveRendererFactory(object):
implements(IRendererFactory)
- tags = html.tags
- doctype = html.doctype
- xmlns = html.xmlns
-
def __init__(self, config):
registry = config.registry
self.loader = BreveAssetLoader(registry.__name__)
settings = dict((name[6:], value) for name, value in registry.settings.items() if name.startswith('breve.'))
-
- self.tags = config.maybe_dotted(settings.get('tags', self.tags))
-
- self.doctype = settings.get('doctype', self.doctype)
+ self.tags = config.maybe_dotted(settings.get('tags', html.tags))
+ self.doctype = settings.get('doctype', html.doctype)
if self.doctype and not self.doctype.startswith('<!DOCTYPE '):
self.doctype = '<!DOCTYPE %s>' % self.doctype
-
- self.xmlns = settings.get('xmlns', self.xmlns)
+ self.xmlns = settings.get('xmlns', html.xmlns)
+ self.fragment = asbool(settings.get('fragment', False))
def __call__(self, info):
def render(value, system):
value.update(system)
+ fragment = value.pop('breve_fragment', self.fragment)
template = Template(self.tags, xmlns=self.xmlns, doctype=self.doctype)
- return template.render(info.name, vars=value, loader=self.loader)
+ return template.render(info.name, vars=value, fragment=fragment, loader=self.loader)
return render
View
@@ -1,6 +1,6 @@
from setuptools import setup, find_packages
-version = '0.4'
+version = '0.5'
setup(name='pyramid_breve',
version=version,

0 comments on commit 3023965

Please sign in to comment.