template: Make template path optional, use embedded resources
This commit is contained in:
18
template.cpp
18
template.cpp
@@ -24,11 +24,11 @@ SOFTWARE.
|
|||||||
#include "urlprovider.h"
|
#include "urlprovider.h"
|
||||||
#include "htmllink.h"
|
#include "htmllink.h"
|
||||||
#include "logger.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)
|
ConfigVariableResolver &configVarsResolver, MapCache<TemplatePage> &pageCache)
|
||||||
{
|
{
|
||||||
this->templateprefix = templateprefix;
|
this->templateprefix = templateprefix;
|
||||||
this->templatepath = templatepath;
|
|
||||||
this->configUrls = &configUrls;
|
this->configUrls = &configUrls;
|
||||||
this->configVarResolver = &configVarsResolver;
|
this->configVarResolver = &configVarsResolver;
|
||||||
this->pageCache = &pageCache;
|
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 Template::loadPartContent(std::string_view partname)
|
||||||
{
|
{
|
||||||
std::string partpath = getPartPath(partname);
|
if(!this->templatepath.empty())
|
||||||
return utils::readCompleteFile(partpath);
|
{
|
||||||
|
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)
|
std::string Template::loadResolvedPart(std::string_view partname)
|
||||||
{
|
{
|
||||||
return resolveIncludes(loadPartContent(partname));
|
return resolveIncludes(loadPartContent(partname));
|
||||||
@@ -178,3 +183,8 @@ std::string Template::renderRevisionList(const std::vector<Revision> &revisions,
|
|||||||
|
|
||||||
return stream.str();
|
return stream.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Template::setPath(std::string path)
|
||||||
|
{
|
||||||
|
this->templatepath = path;
|
||||||
|
}
|
||||||
@@ -26,7 +26,7 @@ class Template
|
|||||||
TemplatePage createPage(std::string_view name);
|
TemplatePage createPage(std::string_view name);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Template(std::string templateprefix, std::string templatepath, ConfigUrls &configUrls,
|
Template(std::string templateprefix, ConfigUrls &configUrls,
|
||||||
ConfigVariableResolver &configVarsResolver, MapCache<TemplatePage> &pageCache);
|
ConfigVariableResolver &configVarsResolver, MapCache<TemplatePage> &pageCache);
|
||||||
|
|
||||||
TemplatePage getPage(const std::string &pagename);
|
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<std::string> &results) const;
|
||||||
std::string renderSearch(const std::vector<SearchResult> &results) const;
|
std::string renderSearch(const std::vector<SearchResult> &results) const;
|
||||||
std::string renderRevisionList(const std::vector<Revision> &revisions, bool withpage = false) const;
|
std::string renderRevisionList(const std::vector<Revision> &revisions, bool withpage = false) const;
|
||||||
|
|
||||||
|
void setPath(std::string path);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // TEMPLATE_H
|
#endif // TEMPLATE_H
|
||||||
|
|||||||
Reference in New Issue
Block a user