mirror of
https://github.com/lucaspalomodevelop/core.git
synced 2026-03-17 01:54:49 +00:00
add alternate root location for template generation (for local testing)
This commit is contained in:
parent
37cadc2547
commit
5f38b93d67
@ -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)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user