Using jinja2 environment to load the template file.

This enables the use of template inheritance, see
http://jinja.pocoo.org/docs/templates/#template-inheritance
pull/444/head
Christian Taedcke 2014-06-21 16:35:32 +02:00
parent 005c3a7b87
commit cc09416bd2
1 changed files with 5 additions and 3 deletions

View File

@ -3,7 +3,8 @@ import uuid, shutil, os, logging, fnmatch
from os import walk, remove from os import walk, remove
from os.path import join, dirname, isdir, split from os.path import join, dirname, isdir, split
from copy import copy from copy import copy
from jinja2 import Template from jinja2 import Template, FileSystemLoader
from jinja2.environment import Environment
from contextlib import closing from contextlib import closing
from zipfile import ZipFile, ZIP_DEFLATED from zipfile import ZipFile, ZIP_DEFLATED
@ -23,6 +24,8 @@ class Exporter():
self.program_name = program_name self.program_name = program_name
self.toolchain = TOOLCHAIN_CLASSES[self.get_toolchain()](TARGET_MAP[target]) self.toolchain = TOOLCHAIN_CLASSES[self.get_toolchain()](TARGET_MAP[target])
self.build_url_resolver = build_url_resolver self.build_url_resolver = build_url_resolver
jinja_loader = FileSystemLoader(os.path.dirname(os.path.abspath(__file__)))
self.jinja_environment = Environment(loader=jinja_loader)
def get_toolchain(self): def get_toolchain(self):
return self.TOOLCHAIN return self.TOOLCHAIN
@ -87,8 +90,7 @@ class Exporter():
def gen_file(self, template_file, data, target_file): def gen_file(self, template_file, data, target_file):
template_path = join(Exporter.TEMPLATE_DIR, template_file) template_path = join(Exporter.TEMPLATE_DIR, template_file)
template_text = open(template_path).read() template = self.jinja_environment.get_template(template_file)
template = Template(template_text)
target_text = template.render(data) target_text = template.render(data)
target_path = join(self.inputDir, target_file) target_path = join(self.inputDir, target_file)