Exemple #1
0
 def evaluate_template(self, load_name, context):
     fd, filename = tempfile.mkstemp(text=True)
     f = os.fdopen(fd, 'w')
     try:
         f.write(self.get_common_javascript())
         f.write('''
             var tmpl = jsonjinja.getTemplate(%s);
             process.stdout.write(tmpl.render(%s));
         ''' % (json.dumps(load_name), json.dumps(context)))
         f.close()
         c = subprocess.Popen(['node', filename], stdout=subprocess.PIPE)
         stdout, stderr = c.communicate()
     finally:
         os.remove(filename)
     return stdout
Exemple #2
0
 def evaluate_template(self, load_name, context):
     fd, filename = tempfile.mkstemp(text=True)
     f = os.fdopen(fd, 'w')
     try:
         f.write(self.get_common_javascript())
         f.write('''
             var tmpl = jsonjinja.getTemplate(%s);
             process.stdout.write(tmpl.render(%s));
         ''' % (json.dumps(load_name), json.dumps(context)))
         f.close()
         c = subprocess.Popen(['node', filename], stdout=subprocess.PIPE)
         stdout, stderr = c.communicate()
     finally:
         os.remove(filename)
     return stdout
Exemple #3
0
 def compile_javascript_templates(self, filter_func=None, stream=None):
     write_out = False
     if stream is None:
         stream = StringIO()
         write_out = True
     stream.write('{')
     first = True
     for template_name in self.loader.list_templates():
         if filter_func is not None and not filter_func(template_name):
             continue
         if not first:
             stream.write(',')
         stream.write('%s:' % json.dumps(template_name))
         node = self.get_template_as_node(template_name)
         to_javascript(node, stream)
         first = False
     stream.write('}')
     if write_out:
         return stream.getvalue()