diff --git a/include/inja/environment.hpp b/include/inja/environment.hpp index 86db816..13779cf 100644 --- a/include/inja/environment.hpp +++ b/include/inja/environment.hpp @@ -33,7 +33,7 @@ protected: std::string output_path; public: - Environment(): Environment("") {} + Environment(): Environment("./") {} explicit Environment(const std::string& global_path): input_path(global_path), output_path(global_path) {} @@ -95,7 +95,7 @@ public: Template parse(std::string_view input) { Parser parser(parser_config, lexer_config, template_storage, function_storage); - return parser.parse(input); + return parser.parse(input, input_path); } Template parse_template(const std::string& filename) { diff --git a/include/inja/parser.hpp b/include/inja/parser.hpp index 3ea1793..3fbbfcc 100644 --- a/include/inja/parser.hpp +++ b/include/inja/parser.hpp @@ -631,10 +631,6 @@ public: return result; } - Template parse(std::string_view input) { - return parse(input, "./"); - } - void parse_into_template(Template& tmpl, std::string_view filename) { std::string_view path = filename.substr(0, filename.find_last_of("/\\") + 1); diff --git a/single_include/inja/inja.hpp b/single_include/inja/inja.hpp index 2c69ccd..0951788 100644 --- a/single_include/inja/inja.hpp +++ b/single_include/inja/inja.hpp @@ -2045,10 +2045,6 @@ public: return result; } - Template parse(std::string_view input) { - return parse(input, "./"); - } - void parse_into_template(Template& tmpl, std::string_view filename) { std::string_view path = filename.substr(0, filename.find_last_of("/\\") + 1); @@ -2735,7 +2731,7 @@ protected: std::string output_path; public: - Environment(): Environment("") {} + Environment(): Environment("./") {} explicit Environment(const std::string& global_path): input_path(global_path), output_path(global_path) {} @@ -2797,7 +2793,7 @@ public: Template parse(std::string_view input) { Parser parser(parser_config, lexer_config, template_storage, function_storage); - return parser.parse(input); + return parser.parse(input, input_path); } Template parse_template(const std::string& filename) { diff --git a/test/test-files.cpp b/test/test-files.cpp index aa01cff..e95f396 100644 --- a/test/test-files.cpp +++ b/test/test-files.cpp @@ -69,12 +69,23 @@ TEST_CASE("global-path") { } } -TEST_CASE("include-without-local-files") { +TEST_CASE("include-files") { inja::Environment env {test_file_directory}; - env.set_search_included_templates_in_files(false); + inja::json data; + data["name"] = "Jeff"; - CHECK_THROWS_WITH(env.render_file_with_json_file("html/template.txt", "html/data.json"), + SUBCASE("from text") { + CHECK(env.render_file("include.txt", data) == "Answer: Hello Jeff."); + CHECK(env.render("Answer: {% include \"simple.txt\" %}", data) == "Answer: Hello Jeff."); + + CHECK_NOTHROW(env.render_file_with_json_file("html/template.txt", "html/data.json")); + } + + SUBCASE("without local files") { + env.set_search_included_templates_in_files(false); + CHECK_THROWS_WITH(env.render_file_with_json_file("html/template.txt", "html/data.json"), "[inja.exception.render_error] (at 3:14) include 'header.txt' not found"); + } } TEST_CASE("include-in-memory-and-file-template") {