mirror of
https://github.com/valitydev/salt.git
synced 2024-11-08 01:18:58 +00:00
Adding Template renderer for Cheetah
This commit is contained in:
parent
6be96f82a6
commit
faeba57e01
36
salt/renderers/cheetah.py
Normal file
36
salt/renderers/cheetah.py
Normal file
@ -0,0 +1,36 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
'''
|
||||
Cheetah Renderer for Salt
|
||||
'''
|
||||
|
||||
from __future__ import absolute_import
|
||||
|
||||
# Import 3rd party libs
|
||||
try:
|
||||
from Cheetah.Template import Template
|
||||
HAS_LIBS = True
|
||||
except ImportError:
|
||||
HAS_LIBS = False
|
||||
|
||||
# Import salt libs
|
||||
from salt._compat import string_types
|
||||
|
||||
|
||||
def render(cheetah_data, saltenv='base', sls='', method='xml', **kws):
|
||||
'''
|
||||
Render a Cheetah template.
|
||||
|
||||
:rtype: A Python data structure
|
||||
'''
|
||||
if not HAS_LIBS:
|
||||
return {}
|
||||
|
||||
if not isinstance(cheetah_data, string_types):
|
||||
cheetah_data = cheetah_data.read()
|
||||
|
||||
if cheetah_data.startswith('#!'):
|
||||
cheetah_data = cheetah_data[(cheetah_data.find('\n') + 1):]
|
||||
if not cheetah_data.strip():
|
||||
return {}
|
||||
|
||||
return str(Template(cheetah_data, searchList=[kws]))
|
@ -383,6 +383,14 @@ def render_genshi_tmpl(tmplstr, context, tmplpath=None):
|
||||
return tmpl.generate(**context).render(method)
|
||||
|
||||
|
||||
def render_cheetah_tmpl(tmplstr, context, tmplpath=None):
|
||||
'''
|
||||
Render a Cheetah template.
|
||||
'''
|
||||
from Cheetah.Template import Template
|
||||
return str(Template(tmplstr, searchList=[context]))
|
||||
|
||||
|
||||
def py(sfn, string=False, **kwargs): # pylint: disable=C0103
|
||||
'''
|
||||
Render a template from a python source file
|
||||
@ -430,6 +438,7 @@ JINJA = wrap_tmpl_func(render_jinja_tmpl)
|
||||
MAKO = wrap_tmpl_func(render_mako_tmpl)
|
||||
WEMPY = wrap_tmpl_func(render_wempy_tmpl)
|
||||
GENSHI = wrap_tmpl_func(render_genshi_tmpl)
|
||||
CHEETAH = wrap_tmpl_func(render_cheetah_tmpl)
|
||||
|
||||
TEMPLATE_REGISTRY = {
|
||||
'jinja': JINJA,
|
||||
@ -437,4 +446,5 @@ TEMPLATE_REGISTRY = {
|
||||
'py': py,
|
||||
'wempy': WEMPY,
|
||||
'genshi': GENSHI,
|
||||
'cheetah': CHEETAH,
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user