Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding chevron as a templating option #1476

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion bottle.py
Original file line number Diff line number Diff line change
@@ -4030,6 +4030,21 @@ def render(self, *args, **kwargs):
_defaults.update(kwargs)
return self.tpl.render(**_defaults)

class ChevronTemplate(BaseTemplate):
def prepare(self, **options):
if self.source:
self.template = self.source
else:
self.template = self.filename

def render(self, *args, **kwargs):
import chevron
for dictarg in args:
kwargs.update(dictarg)
_defaults = self.defaults.copy()
_defaults.update(kwargs)
with open(self.template, 'r') as f:
return chevron.render(f, **_defaults)

class CheetahTemplate(BaseTemplate):
def prepare(self, **options):
@@ -4383,7 +4398,7 @@ def template(*args, **kwargs):
cheetah_template = functools.partial(template,
template_adapter=CheetahTemplate)
jinja2_template = functools.partial(template, template_adapter=Jinja2Template)

chevron_template = functools.partial(template, template_adapter=ChevronTemplate)

def view(tpl_name, **defaults):
""" Decorator: renders a template for a handler.