Skip to content

Enable the use of template inheritance for exporters #444

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 18, 2014
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions workspace_tools/export/exporters.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
from os import walk, remove
from os.path import join, dirname, isdir, split
from copy import copy
from jinja2 import Template
from jinja2 import Template, FileSystemLoader
from jinja2.environment import Environment
from contextlib import closing
from zipfile import ZipFile, ZIP_DEFLATED

Expand All @@ -23,6 +24,8 @@ def __init__(self, target, inputDir, program_name, build_url_resolver):
self.program_name = program_name
self.toolchain = TOOLCHAIN_CLASSES[self.get_toolchain()](TARGET_MAP[target])
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):
return self.TOOLCHAIN
Expand Down Expand Up @@ -87,8 +90,7 @@ def scan_and_copy_resources(self, prj_path, trg_path):

def gen_file(self, template_file, data, target_file):
template_path = join(Exporter.TEMPLATE_DIR, template_file)
template_text = open(template_path).read()
template = Template(template_text)
template = self.jinja_environment.get_template(template_file)
target_text = template.render(data)

target_path = join(self.inputDir, target_file)
Expand Down