Add ability to call commands directly from a template string

This commit is contained in:
Thomas S Hatch 2011-05-08 23:29:41 -06:00
parent 6fbc3ee570
commit 6b95927832

View File

@ -134,7 +134,18 @@ class State(object):
''' '''
if not os.path.isfile(template): if not os.path.isfile(template):
return {} return {}
high = self.rend[self.opts['renderer']](template) return self.rend[self.opts['renderer']](template)
def compile_template_str(self, template):
'''
Take the path to a template and return the high data structure derived from the
template.
'''
fn_ = tempfile.mkstemp()[1]
open(fn_, 'w+').write(template)
high = self.rend[self.opts['renderer']](fn_)
os.remove(fn_)
return high
def call(self, data): def call(self, data):
''' '''
@ -172,3 +183,12 @@ class State(object):
if high: if high:
return self.call_high(high) return self.call_high(high)
return high return high
def call_template_str(self, template):
'''
Enforce the states in a template, pass the template as a string
'''
high = self.compile_template_str(template)
if high:
return self.call_high(high)
return high