From 4d5a7d1c33ab7b05947010e0d16b33d18f04ce4d Mon Sep 17 00:00:00 2001 From: pantor Date: Mon, 17 May 2021 20:44:48 +0200 Subject: [PATCH] fix single include --- single_include/inja/inja.hpp | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/single_include/inja/inja.hpp b/single_include/inja/inja.hpp index e6499c5..cdca7e1 100644 --- a/single_include/inja/inja.hpp +++ b/single_include/inja/inja.hpp @@ -3205,22 +3205,22 @@ class Parser { throw_parser_error("expected string, got '" + tok.describe() + "'"); } - // Build the relative path - json json_name = json::parse(tok.text); - std::string pathname = static_cast(path); - pathname += json_name.get_ref(); - if (pathname.compare(0, 2, "./") == 0) { - pathname.erase(0, 2); - } - // sys::path::remove_dots(pathname, true, sys::path::Style::posix); + std::string template_name = json::parse(tok.text).get_ref(); + if (config.search_included_templates_in_files && template_storage.find(template_name) == template_storage.end()) { + // Build the relative path + template_name = static_cast(path) + template_name; + if (template_name.compare(0, 2, "./") == 0) { + template_name.erase(0, 2); + } - if (config.search_included_templates_in_files && template_storage.find(pathname) == template_storage.end()) { - auto include_template = Template(load_file(pathname)); - template_storage.emplace(pathname, include_template); - parse_into_template(template_storage[pathname], pathname); + if (template_storage.find(template_name) == template_storage.end()) { + auto include_template = Template(load_file(template_name)); + template_storage.emplace(template_name, include_template); + parse_into_template(template_storage[template_name], template_name); + } } - current_block->nodes.emplace_back(std::make_shared(pathname, tok.text.data() - tmpl.content.c_str())); + current_block->nodes.emplace_back(std::make_shared(template_name, tok.text.data() - tmpl.content.c_str())); get_next_token();