diff options
author | Toni Uhlig <matzeton@googlemail.com> | 2021-09-30 21:12:57 +0200 |
---|---|---|
committer | Toni Uhlig <matzeton@googlemail.com> | 2021-09-30 21:12:57 +0200 |
commit | 6c04dfe2caff1e03ba5c898b591327439452f616 (patch) | |
tree | 11c6f6955de188c48015641c1ae2e63b0d0e50d6 /src/ContentManager.cpp | |
parent | ec7cfa85530082127703278cf1ae5167990c0f45 (diff) |
CMS functionality works just find..minimal-working-example
Signed-off-by: Toni Uhlig <matzeton@googlemail.com>
Diffstat (limited to 'src/ContentManager.cpp')
-rw-r--r-- | src/ContentManager.cpp | 89 |
1 files changed, 59 insertions, 30 deletions
diff --git a/src/ContentManager.cpp b/src/ContentManager.cpp index a1787bd..6beef5a 100644 --- a/src/ContentManager.cpp +++ b/src/ContentManager.cpp @@ -1,61 +1,90 @@ #include "ContentManager.hpp" +void ContentManager::SetStaticFilesystem(std::shared_ptr<Filesystem> & static_fs) +{ + m_StaticFilesystem = static_fs; +} + +void ContentManager::SetTemplateSystem(std::shared_ptr<TemplateManager> & tmgr) +{ + m_TemplateManager = tmgr; +} + bool ContentManager::RegisterModule(std::shared_ptr<Content> ctnt) { - std::string const & basePath = ctnt->GetBaseUri(); - Redirections const & rs = ctnt->GetRedirections(); + std::string const & basePath = ctnt->GetUriBasePath(); + Redirections const & rs = ctnt->GetRedirections(); - m_ContentModules[basePath] = ctnt; - for (auto & redirect : rs) - { - m_ContentModules[redirect] = ctnt; - } + m_ContentModules[basePath] = ctnt; + for (auto & redirect : rs) + { + m_ContentModules[redirect] = ctnt; + } - return false; + return false; } bool ContentManager::InitAll(void) { - bool ret = true; + bool ret = true; - for (auto & content : m_ContentModules) - { - if (content.second->Init() == false) + for (auto & content : m_ContentModules) { - ret = false; + if (content.second->Init() == false) + { + ret = false; + } } - } - return ret; + return ret; } void ContentManager::ShutdownAll(void) { - std::unordered_map<std::shared_ptr<Content>, bool> shutdownModules; + std::unordered_map<std::shared_ptr<Content>, bool> shutdownModules; - for (auto & content : m_ContentModules) - { - auto const & search = shutdownModules.find(content.second); - if (search != shutdownModules.end()) + for (auto & content : m_ContentModules) { - continue; - } else { - content.second->Shutdown(); - shutdownModules[content.second] = true; + auto const & search = shutdownModules.find(content.second); + if (search != shutdownModules.end()) + { + continue; + } + else + { + content.second->Shutdown(); + shutdownModules[content.second] = true; + } } - } - m_ContentModules.clear(); + m_ContentModules.clear(); } -bool ContentManager::Render(std::string & basePath) +bool ContentManager::Render(char const * basePath, RequestResponse & rr, std::string & out) { - (void)basePath; + if (m_ContentModules.find(basePath) == m_ContentModules.end()) + { + return false; + } + + RenderData rd; + auto & cntm = m_ContentModules[basePath]; + auto & main = cntm->GetMainTemplate(); + + if (m_ContentModules[basePath]->Render(rr, rd) == false) + { + return false; + } + + if (m_TemplateManager->RenderTemplate(main, rd, out) == false) + { + return false; + } - return false; + return true; } ContentModules const & ContentManager::GetAllModules() const { - return m_ContentModules; + return m_ContentModules; } |