Commit 5f38b93d authored by Ad Schellevis's avatar Ad Schellevis

add alternate root location for template generation (for local testing)

parent 37cadc25
......@@ -4,3 +4,4 @@ parameters:%s
type:inline
message:generate template %s
config:/conf/config.xml
root_dir:/
......@@ -47,7 +47,7 @@ def execute(action,parameters):
if action.command == 'template.reload':
import template
import config
tmpl = template.Template()
tmpl = template.Template(action.root_dir)
conf = config.Config(action.config)
tmpl.setConfig(conf.get())
filenames = tmpl.generate(parameters)
......
......@@ -42,11 +42,16 @@ import jinja2
class Template(object):
def __init__(self):
def __init__(self,target_root_directory="/"):
""" constructor
:return:
"""
# init config (config.xml) data
self._config = {}
# set target root
self._target_root_directory = target_root_directory
# setup jinja2 environment
self._template_dir = os.path.dirname(os.path.abspath(__file__))+'/../templates/'
self._j2_env = jinja2.Environment(loader=jinja2.FileSystemLoader(self._template_dir),trim_blocks=True)
......@@ -229,6 +234,8 @@ class Template(object):
# render page and write to disc
content = j2_page.render(cnf_data)
# prefix filename with defined root directory
filename = ('%s/%s'%(self._target_root_directory, filename)).replace('//','/')
if create_directory:
# make sure the target directory exists
self._create_directory(filename)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment