Initial site generation
This commit is contained in:
parent
f44c79dc1f
commit
fc44290e3f
35 changed files with 667 additions and 303 deletions
|
@ -1,76 +0,0 @@
|
|||
#include "TemplatingEngine.h"
|
||||
|
||||
#include "Directory.h"
|
||||
#include "FileLogger.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
TemplatingEngine::TemplatingEngine(const Path& workingDirectory)
|
||||
: mWorkingDirectory(workingDirectory)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void TemplatingEngine::loadTemplateFiles()
|
||||
{
|
||||
const auto files = Directory::getFilesWithExtension(mWorkingDirectory, mTemplateExtension);
|
||||
for (const auto& path : files)
|
||||
{
|
||||
mTemplateFiles[path.stem().string()] = std::make_unique<TemplateFile>(path);
|
||||
}
|
||||
MLOG_INFO("Found: " << mTemplateFiles.size() << " templates in " << mWorkingDirectory);
|
||||
}
|
||||
|
||||
std::string TemplatingEngine::processTemplate(const std::string& name)
|
||||
{
|
||||
if (auto file = getTemplateFile(name))
|
||||
{
|
||||
return processTemplate(file);
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
TemplateFile* TemplatingEngine::getTemplateFile(const Path& path)
|
||||
{
|
||||
return getTemplateFile(path.stem().string());
|
||||
}
|
||||
|
||||
TemplateFile* TemplatingEngine::getTemplateFile(const std::string& name)
|
||||
{
|
||||
return mTemplateFiles[name].get();
|
||||
}
|
||||
|
||||
std::string TemplatingEngine::processTemplate(TemplateFile* file, TemplateNode* parent)
|
||||
{
|
||||
file->loadContent();
|
||||
file->dumpContent();
|
||||
|
||||
auto content = file->getContent();
|
||||
if (parent)
|
||||
{
|
||||
content->setExtensionParent(parent);
|
||||
}
|
||||
|
||||
if (auto extension_node = content->getFirstChildShallow<TemplateExtends>())
|
||||
{
|
||||
//std::cout << "Found extension node" << std::endl;
|
||||
if (auto extension_template = getTemplateFile(Path(extension_node->getPath())))
|
||||
{
|
||||
//std::cout << "Found extension template" << std::endl;
|
||||
return processTemplate(extension_template, parent);
|
||||
}
|
||||
else
|
||||
{
|
||||
return render(content);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return render(content);
|
||||
}
|
||||
}
|
||||
|
||||
std::string TemplatingEngine::render(TemplateNode* content)
|
||||
{
|
||||
return content->render();
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue