template: Make template path optional, use embedded resources
此提交包含在:
18
template.cpp
18
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<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;
|
||||
}
|
||||
@@ -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
|
||||
|
||||
新增問題並參考
封鎖使用者