RevisionRenderer: Add 'dynamicpostrenderer'

This commit is contained in:
Albert S. 2024-03-16 22:04:33 +01:00
parent 6a12070d0d
commit 61f289625c

View File

@ -1,9 +1,10 @@
#include "revisionrenderer.h" #include "revisionrenderer.h"
#include "templatepage.h" #include "templatepage.h"
#include "dynamic/dynamiccontentpostlist.h" #include "dynamic/dynamiccontentpostlist.h"
#include "dynamic/dynamiccontentincludepage.h" #include "dynamic/dynamiccontentincludepage.h"
#include "dynamic/dynamiccontentgetvar.h" #include "dynamic/dynamiccontentgetvar.h"
#include "dynamic/dynamiccontentsetvar.h" #include "dynamic/dynamiccontentsetvar.h"
#include "dynamic/dynamicpostrenderer.h"
#include "parser.h" #include "parser.h"
#include "htmllink.h" #include "htmllink.h"
@ -19,7 +20,8 @@ std::string RevisionRenderer::dynamicCallback(std::string_view key, std::string_
{ {
auto includePage = this->dynamicContentFactory.createDynamicContent<DynamicContentIncludePage>(); auto includePage = this->dynamicContentFactory.createDynamicContent<DynamicContentIncludePage>();
includePage->setArgument(std::string(value)); includePage->setArgument(std::string(value));
return parser.parseDynamics(includePage->render(), std::bind(&RevisionRenderer::dynamicCallback, this, std::placeholders::_1, std::placeholders::_2)); return parser.parseDynamics(includePage->render(), std::bind(&RevisionRenderer::dynamicCallback, this,
std::placeholders::_1, std::placeholders::_2));
} }
if(key == "dynamic:setvar") if(key == "dynamic:setvar")
{ {
@ -35,6 +37,12 @@ std::string RevisionRenderer::dynamicCallback(std::string_view key, std::string_
getVar->setArgument(std::string(value)); getVar->setArgument(std::string(value));
return getVar->render(); return getVar->render();
} }
if(key == "dynamic:postrenderer")
{
auto renderer = this->dynamicContentFactory.createDynamicContent<DynamicPostRenderer>();
renderer->setArgument(std::string(value));
return renderer->render();
}
return std::string{}; return std::string{};
} }
@ -44,7 +52,8 @@ std::string RevisionRenderer::renderContent(std::string content)
dynamicVarsMap["createdon"] = utils::toISODate(time(NULL)); dynamicVarsMap["createdon"] = utils::toISODate(time(NULL));
dynamicVarsMap["modifydatetime"] = utils::toISODateTime(time(NULL)); dynamicVarsMap["modifydatetime"] = utils::toISODateTime(time(NULL));
std::string resolvedContent = parser.parseDynamics(content, std::bind(&RevisionRenderer::dynamicCallback, this, std::placeholders::_1, std::placeholders::_2)); std::string resolvedContent = parser.parseDynamics(
content, std::bind(&RevisionRenderer::dynamicCallback, this, std::placeholders::_1, std::placeholders::_2));
return parser.parse(*this->db->createPageDao(), *this->urlProvider, resolvedContent); return parser.parse(*this->db->createPageDao(), *this->urlProvider, resolvedContent);
} }
@ -58,12 +67,12 @@ std::string RevisionRenderer::renderContent(const Revision &r, std::string_view
throw std::runtime_error("Could not get first revision for page, which is odd. Solar flares?"); throw std::runtime_error("Could not get first revision for page, which is odd. Solar flares?");
} }
dynamicVarsMap["createdon"] = utils::toISODate(firstRevision.value().timestamp); dynamicVarsMap["createdon"] = utils::toISODate(firstRevision.value().timestamp);
dynamicVarsMap["pagetitle"] = customTitle; dynamicVarsMap["pagetitle"] = customTitle;
dynamicVarsMap["modifydatetime"] = utils::toISODateTime(r.timestamp); dynamicVarsMap["modifydatetime"] = utils::toISODateTime(r.timestamp);
std::string resolvedContent = parser.parseDynamics(r.content, std::bind(&RevisionRenderer::dynamicCallback, this, std::placeholders::_1, std::placeholders::_2)); std::string resolvedContent = parser.parseDynamics(
r.content, std::bind(&RevisionRenderer::dynamicCallback, this, std::placeholders::_1, std::placeholders::_2));
return parser.parse(*this->db->createPageDao(), *this->urlProvider, resolvedContent); return parser.parse(*this->db->createPageDao(), *this->urlProvider, resolvedContent);
} }