Up to template reading
This commit is contained in:
parent
48d21b9194
commit
c0bcfaccac
5 changed files with 211 additions and 141 deletions
|
@ -1,5 +1,7 @@
|
|||
#include "WebsiteGenerator.h"
|
||||
|
||||
#include "TomlReader.h"
|
||||
|
||||
void WebsiteGenerator::findProject(const std::string& searchPath)
|
||||
{
|
||||
const auto config_path = std::filesystem::path(searchPath) / "config.toml";
|
||||
|
@ -12,27 +14,23 @@ void WebsiteGenerator::findProject(const std::string& searchPath)
|
|||
|
||||
Path WebsiteGenerator::getConfigPath() const
|
||||
{
|
||||
return mProjectPath / "config";
|
||||
return mProjectPath / "config.toml";
|
||||
}
|
||||
|
||||
void WebsiteGenerator::readConfig()
|
||||
{
|
||||
const auto lines = File(getConfigPath()).readLines();
|
||||
auto reader = TomlReader();
|
||||
reader.read(getConfigPath());
|
||||
|
||||
enum class LineState
|
||||
if (auto theme_table = reader.getContent()->getTable("themes"))
|
||||
{
|
||||
UNSET,
|
||||
IN_SECTION_TAG,
|
||||
BEFORE_EQUALS
|
||||
};
|
||||
auto items = theme_table->getKeyValuePairs();
|
||||
auto location = items["location"];
|
||||
auto active_theme = items["active_theme"];
|
||||
|
||||
|
||||
for (const auto& lines : lines)
|
||||
{
|
||||
auto line_state =
|
||||
//if ()
|
||||
mConfig.setThemePath(location);
|
||||
mConfig.setActiveTheme(active_theme);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void WebsiteGenerator::parseContentFiles()
|
||||
|
@ -47,7 +45,14 @@ void WebsiteGenerator::parseContentFiles()
|
|||
|
||||
void WebsiteGenerator::parseTemplateFiles()
|
||||
{
|
||||
const auto template_path = mProjectPath / mConfig.getThemePath() / mConfig.getActiveTheme();
|
||||
|
||||
const auto template_files = Directory::getFilesWithExtension(template_path, ".html");
|
||||
for (const auto& path : template_files)
|
||||
{
|
||||
auto file = TemplateFile(path);
|
||||
mTemplateFiles[path.stem().string()] = file;
|
||||
}
|
||||
}
|
||||
|
||||
void WebsiteGenerator::doSubstitutions()
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
|
||||
class GeneratorConfig
|
||||
{
|
||||
|
||||
public:
|
||||
void setThemePath(const Path& path)
|
||||
{
|
||||
mThemesPath = path;
|
||||
|
@ -21,11 +21,33 @@ class GeneratorConfig
|
|||
mActiveTheme = theme;
|
||||
}
|
||||
|
||||
Path getThemePath() const
|
||||
{
|
||||
return mThemesPath;
|
||||
}
|
||||
|
||||
std::string getActiveTheme() const
|
||||
{
|
||||
return mActiveTheme;
|
||||
}
|
||||
|
||||
private:
|
||||
Path mThemesPath;
|
||||
std::string mActiveTheme;
|
||||
};
|
||||
|
||||
class TemplateFile
|
||||
{
|
||||
public:
|
||||
TemplateFile(const Path& path)
|
||||
: mPath(path)
|
||||
{
|
||||
|
||||
}
|
||||
private:
|
||||
Path mPath;
|
||||
};
|
||||
|
||||
class WebsiteGenerator
|
||||
{
|
||||
public:
|
||||
|
@ -58,4 +80,5 @@ private:
|
|||
GeneratorConfig mConfig;
|
||||
std::vector<ContentPage> mPages;
|
||||
std::vector<ContentArticle> mArticles;
|
||||
std::unordered_map<std::string, TemplateFile> mTemplateFiles;
|
||||
};
|
||||
|
|
|
@ -18,6 +18,7 @@ int main(int argc, char *argv[])
|
|||
generator.parseContentFiles();
|
||||
|
||||
// Find template files
|
||||
generator.parseTemplateFiles();
|
||||
|
||||
// Substitute template files
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue