From ab0a6f1e27195efec0c02c65c30439699bea399f Mon Sep 17 00:00:00 2001 From: "Albert S." Date: Mon, 22 Dec 2025 10:07:55 +0100 Subject: [PATCH] template: Make template path optional, use embedded resources --- template.cpp | 18 ++++++++++++++---- template.h | 4 +++- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/template.cpp b/template.cpp index e7eb2cd..9571313 100644 --- a/template.cpp +++ b/template.cpp @@ -24,11 +24,11 @@ SOFTWARE. #include "urlprovider.h" #include "htmllink.h" #include "logger.h" -Template::Template(std::string templateprefix, std::string templatepath, ConfigUrls &configUrls, +#include "embedded.h" +Template::Template(std::string templateprefix, ConfigUrls &configUrls, ConfigVariableResolver &configVarsResolver, MapCache &pageCache) { this->templateprefix = templateprefix; - this->templatepath = templatepath; this->configUrls = &configUrls; this->configVarResolver = &configVarsResolver; this->pageCache = &pageCache; @@ -59,9 +59,14 @@ std::string Template::getPartPath(std::string_view partname) std::string Template::loadPartContent(std::string_view partname) { - std::string partpath = getPartPath(partname); - return utils::readCompleteFile(partpath); + if(!this->templatepath.empty()) + { + std::string partpath = getPartPath(partname); + return utils::readCompleteFile(partpath); + } + return std::string { utils::embedded_get_text_resource(partname) }; } + std::string Template::loadResolvedPart(std::string_view partname) { return resolveIncludes(loadPartContent(partname)); @@ -178,3 +183,8 @@ std::string Template::renderRevisionList(const std::vector &revisions, return stream.str(); } + +void Template::setPath(std::string path) +{ + this->templatepath = path; +} \ No newline at end of file diff --git a/template.h b/template.h index 269d29b..9e44082 100644 --- a/template.h +++ b/template.h @@ -26,7 +26,7 @@ class Template TemplatePage createPage(std::string_view name); public: - Template(std::string templateprefix, std::string templatepath, ConfigUrls &configUrls, + Template(std::string templateprefix, ConfigUrls &configUrls, ConfigVariableResolver &configVarsResolver, MapCache &pageCache); TemplatePage getPage(const std::string &pagename); @@ -37,6 +37,8 @@ class Template std::string renderSearch(const std::vector &results) const; std::string renderSearch(const std::vector &results) const; std::string renderRevisionList(const std::vector &revisions, bool withpage = false) const; + + void setPath(std::string path); }; #endif // TEMPLATE_H