From 3e0c30f27f1a9eddb865c0b2ba2bc582fcd48d1e Mon Sep 17 00:00:00 2001
From: pantor
Date: Sun, 3 Sep 2023 16:26:32 +0200
Subject: [PATCH] static load file
---
README.md | 2 +-
include/inja/environment.hpp | 4 ++--
include/inja/parser.hpp | 2 +-
single_include/inja/inja.hpp | 6 +++---
4 files changed, 7 insertions(+), 7 deletions(-)
diff --git a/README.md b/README.md
index 809d838..b0fd11b 100644
--- a/README.md
+++ b/README.md
@@ -21,7 +21,7 @@
-Inja is a template engine for modern C++, loosely inspired by [jinja](http://jinja.pocoo.org) for python. It has an easy and yet powerful template syntax with all variables, loops, conditions, includes, callbacks, and comments you need, nested and combined as you like. Inja uses the wonderful [json](https://github.com/nlohmann/json) library by nlohmann for data input. Most importantly, inja needs only two header files, which is (nearly) as trivial as integration in C++ can get. Of course, everything is tested on all relevant compilers. Here is what it looks like:
+Inja is a template engine for modern C++, loosely inspired by [jinja](http://jinja.pocoo.org) for python. It has an easy and yet powerful template syntax with all variables, loops, conditions, includes, callbacks, and comments you need, nested and combined as you like. Of course, everything is tested in CI on all relevant compilers. Here is what it looks like:
```.cpp
json data;
diff --git a/include/inja/environment.hpp b/include/inja/environment.hpp
index 9cab39c..fdb2962 100644
--- a/include/inja/environment.hpp
+++ b/include/inja/environment.hpp
@@ -100,7 +100,7 @@ public:
Template parse_template(const std::string& filename) {
Parser parser(parser_config, lexer_config, template_storage, function_storage);
- auto result = Template(parser.load_file(input_path + static_cast(filename)));
+ auto result = Template(Parser::load_file(input_path + static_cast(filename)));
parser.parse_into_template(result, input_path + static_cast(filename));
return result;
}
@@ -157,7 +157,7 @@ public:
std::string load_file(const std::string& filename) {
Parser parser(parser_config, lexer_config, template_storage, function_storage);
- return parser.load_file(input_path + filename);
+ return Parser::load_file(input_path + filename);
}
json load_json(const std::string& filename) {
diff --git a/include/inja/parser.hpp b/include/inja/parser.hpp
index 0cd2233..bda271c 100644
--- a/include/inja/parser.hpp
+++ b/include/inja/parser.hpp
@@ -634,7 +634,7 @@ public:
sub_parser.parse_into(tmpl, path);
}
- std::string load_file(const std::string& filename) {
+ static std::string load_file(const std::string& filename) {
std::ifstream file;
file.open(filename);
if (file.fail()) {
diff --git a/single_include/inja/inja.hpp b/single_include/inja/inja.hpp
index 78b431c..b2011f4 100644
--- a/single_include/inja/inja.hpp
+++ b/single_include/inja/inja.hpp
@@ -2046,7 +2046,7 @@ public:
sub_parser.parse_into(tmpl, path);
}
- std::string load_file(const std::string& filename) {
+ static std::string load_file(const std::string& filename) {
std::ifstream file;
file.open(filename);
if (file.fail()) {
@@ -2789,7 +2789,7 @@ public:
Template parse_template(const std::string& filename) {
Parser parser(parser_config, lexer_config, template_storage, function_storage);
- auto result = Template(parser.load_file(input_path + static_cast(filename)));
+ auto result = Template(Parser::load_file(input_path + static_cast(filename)));
parser.parse_into_template(result, input_path + static_cast(filename));
return result;
}
@@ -2846,7 +2846,7 @@ public:
std::string load_file(const std::string& filename) {
Parser parser(parser_config, lexer_config, template_storage, function_storage);
- return parser.load_file(input_path + filename);
+ return Parser::load_file(input_path + filename);
}
json load_json(const std::string& filename) {