Package: pyramid-breve
Brevetemplate engine renderer forPyramidframework that usesasset specificationto locate and load templates.
Please useGitHub repositoryto access latest sources,
report bugs and make feature requestsInstallationIf you prefer pip:$pipinstallpyramid-breveOtherwise:$easy_installpyramid-breveUsageCallconfig.include('pyramid_breve')in yourWSGIapplicatication factory function as following:defmain(global_config,**settings):config=Configurator(settings=settings)config.include('pyramid_breve')config.add_static_view('static','static',cache_max_age=3600)config.scan()returnconfig.make_wsgi_app()Another way is to add it topyramid.includesin your INI-file:[app:main]pyramid.includes=pyramid_breveNow use it to render templates:# using absolute asset specification@view_config(route_name='home',renderer='my.lovely.app:templates/home.b')defhome_view(request):return{real:'content'}# using relative asset specification@view_config(route_name='login',renderer='templates/login.b')deflogin_view(request):Configuration parametersThere are few configuration parameters that control rendering. They can be set in
INI-file as following:[app:main]breve.tags=my_package.breve.tagsbreve.doctype=html# optionally, enforce default package name if pyramid-breve fails to detect itbreve.default_package=myappBreve renderer accepts following parameters:breve.default_packagePackage name to use for resolvingrelative asset specifications, i.e. assets without explicit package
name. Pyramid-breve tries to detect your application name and use it as default package name but it’s
a tricky business and this parameter allowes to enforce default package name.breve.tagsThis parameter will be resolved from dotted name string into Python object.
Default isbreve.tags.html.tags.breve.doctype“<!DOCTYPE html>” or just “html”.
Default is content ofbreve.tags.html.doctype.breve.xmlnsWill be sent as-is to the constructor.
Default is content ofbreve.tags.html.xmlns.breve.fragmentThis boolean variable will be used asfragmentparameter to
breve.Template.render call. This parameter can also be controlled by settingbreve_fragmenttemplate variable as following:@view_config(renderer='templates/home.b')defhome_view(request):return{# other variables used in template'breve_fragment':True,}Template variablebreve_fragmentoverrides globalbreve.fragmentsetting.
If none is set default is False.Template file modification monitoringStarting from version 0.6dev there ispyramid_breve.monitor.IFileMonitorinterface.
Implementations of that interface can be used to helppyramid_breve.renderer.TemplateLoaderto get template file status without calling os.stat each time template is about to be rendered.There ispyramid_breve.monitor.IntervalMonitorimplementation of that interface which is used
byBreveRendererFactoryby default. That class simply caches os.stat value for fixed amount
of time. Its constructor accepts single parameterintervalthat should be interval in seconds
between invalidating cached values. This parameter can be configure via INI-file variablebreve.monitor_intervallike following:[app:main]# cache os.stat calls for 15 secondsbreve.monitor_interval=15It is possible to implement customIFileMonitorusing more advanced techiques,
likeinotifyorFile Alteration Monitorfeatures.Lets create simpleIFileMonitorimplementation and configurepyramid_breveto
use it.First, we need to implementIFileMonitorinterface:# myapp/utils.pyfromzope.interfaceimportimplementsfrompyramid_breve.monitorimportIFileMonitorclassDummyMonitor(object):implements(IFileMonitor)deflast_modified(self,name):# Never even look at real modification time and# make it look like templates never changereturn0monitor=DummyMonitor()Usebreve.monitorvariable in INI-file:[app:main]breve.monitor=myapp.utils.monitor