def replace_string(path, tup, code): with open(path, "r") as file: text = file.read() # print(text) pojo_camel = tup.pojo[0].lower() + tup.pojo[1:] pojo_lower = tup.pojo.lower() fields = [x for x in tup.fields.split(";") if "_" not in x] id_fields = [x for x in tup.fields.split(";") if "_" in x][0].replace("_ENCRYPTED", "") print(fields, id_fields) out_text = Template(text).safe_substitute(pojo=tup.pojo, pojo_camel=pojo_camel, pojo_lower=pojo_lower, genId=tup.genCol, code=code,id_fields=id_fields) \ .replace("{} ".format(tup.pojo), tup.pojo) \ .replace("{} ".format(pojo_lower), pojo_lower) \ .replace("{} ".format(pojo_camel), pojo_camel) \ .replace("_scope", "$scope") \ .replace("_(", "$(") out_text = JTemplate(out_text).render(fields=fields, id_fields=id_fields) return out_text
def jinja_render(content, params): # keep_trailing_newline is in jinja2 2.7+, not 2.6 add = "\n" if content.endswith("\n") else "" return (JTemplate( content, undefined=UndefinedJinjaVariable, trim_blocks=True, extensions=["jinja2.ext.do"], ).render(**params) + add)
def render(self, path): file_path = os.path.join(path, self.name) template_path = os.path.join(_template_root, self.origin) if self.params: with open(template_path, 'r') as f: template = JTemplate(f.read(), trim_blocks=True) content = template.render(**self.params) content += '\n' with open(file_path, 'w') as f: f.write(content) else: copyfile(template_path, file_path)
def template_wrapper(*args, **kwargs): if not cache: #Reload file with open(path, "r") as templatefile: templ = JTemplate(templatefile.read()) else: templ = template try: args[0].template = templ except: pass return f(*args, **kwargs)
def jinja_render(content, params): # keep_trailing_newline is in jinja2 2.7+, not 2.6 add = "\n" if content.endswith("\n") else "" return JTemplate(content, undefined=jinja2.StrictUndefined, trim_blocks=True).render(**params) + add
def jinja_render(content, params): return JTemplate(content, undefined=jinja2.StrictUndefined, trim_blocks=True).render(**params)