templating - init work on global templates

This commit is contained in:
bunkerity
2021-05-21 17:12:13 +02:00
parent 801530baf3
commit 996c45df42
10 changed files with 76 additions and 58 deletions

View File

@@ -40,4 +40,6 @@ class Configurator :
real_var = var
elif var[len(var.split("_")[0])+1:] in self.__settings :
real_var = var[len(var.split("_")[0])+1:]
print(real_var)
print(var[len(var.split("_")[0])+1:])
return real_var != "" and re.search(self.__settings[real_var]["regex"], value) and (not multisite_only or self.__settings[real_var]["context"] == "multisite")

View File

@@ -21,9 +21,17 @@ class Templator :
if os.path.isfile(filename) :
relative_filename = filename.replace(self.__input_path, "").replace(type + "/", "")
template = self.__template_env.get_template(type + "/" + relative_filename)
output = template.render(real_config)
template.globals["has_value"] = Templator.has_value
output = template.render(real_config, all=real_config)
if "/" in relative_filename :
directory = relative_filename.replace(relative_filename.split("/")[-1], "")
pathlib.Path(output_path + "/" + directory).mkdir(parents=True, exist_ok=True)
with open(output_path + "/" + relative_filename, "w") as f :
f.write(output)
@jinja2.contextfunction
def has_value(context, name, value) :
for k, v in context.items() :
if (k == name or k.endswith("_" + name)) and v == value :
return True
return False