template: Make template path optional, use embedded resources

This commit is contained in:
2025-12-22 10:07:55 +01:00
orang tua 03b2f44744
melakukan ab0a6f1e27
2 mengubah file dengan 17 tambahan dan 5 penghapusan

Melihat File

@@ -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<TemplatePage> &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<Revision> &revisions,
return stream.str();
}
void Template::setPath(std::string path)
{
this->templatepath = path;
}

Melihat File

@@ -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<TemplatePage> &pageCache);
TemplatePage getPage(const std::string &pagename);
@@ -37,6 +37,8 @@ class Template
std::string renderSearch(const std::vector<std::string> &results) const;
std::string renderSearch(const std::vector<SearchResult> &results) const;
std::string renderRevisionList(const std::vector<Revision> &revisions, bool withpage = false) const;
void setPath(std::string path);
};
#endif // TEMPLATE_H