Skip to content

Commit 771e47f

Browse files
committed
fix search directory for string templates
1 parent 4526fb4 commit 771e47f

File tree

4 files changed

+18
-15
lines changed

4 files changed

+18
-15
lines changed

include/inja/environment.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class Environment {
3333
std::string output_path;
3434

3535
public:
36-
Environment(): Environment("") {}
36+
Environment(): Environment("./") {}
3737

3838
explicit Environment(const std::string& global_path): input_path(global_path), output_path(global_path) {}
3939

@@ -95,7 +95,7 @@ class Environment {
9595

9696
Template parse(std::string_view input) {
9797
Parser parser(parser_config, lexer_config, template_storage, function_storage);
98-
return parser.parse(input);
98+
return parser.parse(input, input_path);
9999
}
100100

101101
Template parse_template(const std::string& filename) {

include/inja/parser.hpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -631,10 +631,6 @@ class Parser {
631631
return result;
632632
}
633633

634-
Template parse(std::string_view input) {
635-
return parse(input, "./");
636-
}
637-
638634
void parse_into_template(Template& tmpl, std::string_view filename) {
639635
std::string_view path = filename.substr(0, filename.find_last_of("/\\") + 1);
640636

single_include/inja/inja.hpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2045,10 +2045,6 @@ class Parser {
20452045
return result;
20462046
}
20472047

2048-
Template parse(std::string_view input) {
2049-
return parse(input, "./");
2050-
}
2051-
20522048
void parse_into_template(Template& tmpl, std::string_view filename) {
20532049
std::string_view path = filename.substr(0, filename.find_last_of("/\\") + 1);
20542050

@@ -2735,7 +2731,7 @@ class Environment {
27352731
std::string output_path;
27362732

27372733
public:
2738-
Environment(): Environment("") {}
2734+
Environment(): Environment("./") {}
27392735

27402736
explicit Environment(const std::string& global_path): input_path(global_path), output_path(global_path) {}
27412737

@@ -2797,7 +2793,7 @@ class Environment {
27972793

27982794
Template parse(std::string_view input) {
27992795
Parser parser(parser_config, lexer_config, template_storage, function_storage);
2800-
return parser.parse(input);
2796+
return parser.parse(input, input_path);
28012797
}
28022798

28032799
Template parse_template(const std::string& filename) {

test/test-files.cpp

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,23 @@ TEST_CASE("global-path") {
6969
}
7070
}
7171

72-
TEST_CASE("include-without-local-files") {
72+
TEST_CASE("include-files") {
7373
inja::Environment env {test_file_directory};
74-
env.set_search_included_templates_in_files(false);
74+
inja::json data;
75+
data["name"] = "Jeff";
76+
77+
SUBCASE("from text") {
78+
CHECK(env.render_file("include.txt", data) == "Answer: Hello Jeff.");
79+
CHECK(env.render("Answer: {% include \"simple.txt\" %}", data) == "Answer: Hello Jeff.");
7580

76-
CHECK_THROWS_WITH(env.render_file_with_json_file("html/template.txt", "html/data.json"),
81+
CHECK_NOTHROW(env.render_file_with_json_file("html/template.txt", "html/data.json"));
82+
}
83+
84+
SUBCASE("without local files") {
85+
env.set_search_included_templates_in_files(false);
86+
CHECK_THROWS_WITH(env.render_file_with_json_file("html/template.txt", "html/data.json"),
7787
"[inja.exception.render_error] (at 3:14) include 'header.txt' not found");
88+
}
7889
}
7990

8091
TEST_CASE("include-in-memory-and-file-template") {

0 commit comments

Comments
 (0)