correct write template

This commit is contained in:
pantor
2018-02-23 15:45:34 +01:00
parent b6d464a153
commit c5ea89c87e
2 changed files with 14 additions and 3 deletions

View File

@@ -69,7 +69,7 @@ std::string result = env.render_template(temp, data); // "Hello Inja!"
result = env.render_file("./template.txt", "./data.json");
// Or write a rendered template file
temp.write(data, "./result.txt")
env.write(temp, data, "./result.txt")
env.write("./template.txt", "./data.json", "./result.txt")
```

View File

@@ -902,7 +902,7 @@ public:
return renderer.render(parse(text), data);
}
std::string render_template(const Template temp, json data) {
std::string render_template(const Template& temp, json data) {
renderer.element_notation = element_notation;
return renderer.render(temp, data);
}
@@ -923,11 +923,22 @@ public:
file.close();
}
void write(const std::string& filename, const std::string& filename_data, const std::string& filename_out) {
void write(const Template& temp, json data, const std::string& filename_out) {
std::ofstream file(output_path + filename_out);
file << render_template(temp, data);
file.close();
}
void write_with_json_file(const std::string& filename, const std::string& filename_data, const std::string& filename_out) {
json data = load_json(filename_data);
write(filename, data, filename_out);
}
void write_with_json_file(const Template& temp, const std::string& filename_data, const std::string& filename_out) {
json data = load_json(filename_data);
write(temp, data, filename_out);
}
std::string load_global_file(const std::string& filename) {
return parser.load_file(input_path + filename);
}