comparison frontends/src/jp/output_template.py @ 2248:a81261cee29b

jp (output/template): initialize template rendered only if a rendering is actually needed
author Goffi <goffi@goffi.org>
date Sun, 21 May 2017 15:52:23 +0200
parents 4ec72927a222
children 18d71226b3a8
comparison
equal deleted inserted replaced
2247:0f3bfe89999e 2248:a81261cee29b
35 """outputs data using SàT templates""" 35 """outputs data using SàT templates"""
36 36
37 def __init__(self, jp): 37 def __init__(self, jp):
38 self.host = jp 38 self.host = jp
39 jp.register_output(C.OUTPUT_COMPLEX, TEMPLATE, self.render) 39 jp.register_output(C.OUTPUT_COMPLEX, TEMPLATE, self.render)
40 self.renderer = template.Renderer(jp)
41 40
42 def render(self, data): 41 def render(self, data):
43 """render output data using requested template 42 """render output data using requested template
44 43
45 template to render the data can be either command's TEMPLATE or 44 template to render the data can be either command's TEMPLATE or
47 @param data(dict): data is a dict which map from variable name to use in template 46 @param data(dict): data is a dict which map from variable name to use in template
48 to the variable itself. 47 to the variable itself.
49 command's template_data_mapping attribute will be used if it exists to convert 48 command's template_data_mapping attribute will be used if it exists to convert
50 data to a dict usable by the template. 49 data to a dict usable by the template.
51 """ 50 """
51 self.renderer = template.Renderer(self.host)
52 cmd = self.host.command 52 cmd = self.host.command
53 options = self.host.parse_output_options() 53 options = self.host.parse_output_options()
54 self.host.check_output_options(OPTIONS, options) 54 self.host.check_output_options(OPTIONS, options)
55 try: 55 try:
56 template_path = cmd.TEMPLATE 56 template_path = cmd.TEMPLATE