mirror of
https://github.com/pantor/inja.git
synced 2026-02-17 09:03:58 +00:00
static load file
This commit is contained in:
@@ -21,7 +21,7 @@
|
||||
</a>
|
||||
</p>
|
||||
|
||||
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;
|
||||
|
||||
@@ -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<std::string>(filename)));
|
||||
auto result = Template(Parser::load_file(input_path + static_cast<std::string>(filename)));
|
||||
parser.parse_into_template(result, input_path + static_cast<std::string>(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) {
|
||||
|
||||
@@ -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()) {
|
||||
|
||||
@@ -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<std::string>(filename)));
|
||||
auto result = Template(Parser::load_file(input_path + static_cast<std::string>(filename)));
|
||||
parser.parse_into_template(result, input_path + static_cast<std::string>(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) {
|
||||
|
||||
Reference in New Issue
Block a user