Template: Use MapCache, getPage(): Return value, not reference
This commit is contained in:
25
template.cpp
25
template.cpp
@@ -24,12 +24,25 @@ SOFTWARE.
|
||||
#include "htmllink.h"
|
||||
#include "logger.h"
|
||||
Template::Template(std::string templateprefix, std::string templatepath, ConfigUrls &configUrls,
|
||||
ConfigVariableResolver &configVarsResolver)
|
||||
ConfigVariableResolver &configVarsResolver, MapCache<TemplatePage> &pageCache)
|
||||
{
|
||||
this->templateprefix = templateprefix;
|
||||
this->templatepath = templatepath;
|
||||
this->configUrls = &configUrls;
|
||||
this->configVarResolver = &configVarsResolver;
|
||||
this->pageCache = &pageCache;
|
||||
}
|
||||
|
||||
TemplatePage Template::getPage(const std::string &pagename)
|
||||
{
|
||||
auto result = this->pageCache->find(pagename);
|
||||
if(result)
|
||||
{
|
||||
return *result;
|
||||
}
|
||||
auto page = createPage(pagename);
|
||||
this->pageCache->set(pagename, page);
|
||||
return page;
|
||||
}
|
||||
|
||||
std::string Template::getPartPath(std::string_view partname)
|
||||
@@ -65,16 +78,6 @@ TemplatePage Template::createPage(std::string name)
|
||||
return TemplatePage(replacer.parse(content));
|
||||
}
|
||||
|
||||
TemplatePage &Template::getPage(const std::string &pagename)
|
||||
{
|
||||
if(utils::hasKey(pagesMap, pagename))
|
||||
{
|
||||
return pagesMap[pagename];
|
||||
}
|
||||
pagesMap.insert(std::make_pair(pagename, createPage(pagename)));
|
||||
return pagesMap[pagename];
|
||||
}
|
||||
|
||||
// TODO: this restricts template a bit
|
||||
std::string Template::renderSearch(const std::vector<std::string> &results,
|
||||
std::function<std::string(std::string)> callback) const
|
||||
|
Reference in New Issue
Block a user