mirror of
https://github.com/pantor/inja.git
synced 2026-03-31 21:32:47 +00:00
correct write template
This commit is contained in:
@@ -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")
|
||||
```
|
||||
|
||||
|
||||
15
src/inja.hpp
15
src/inja.hpp
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user