diff --git a/.gitignore b/.gitignore index ba58399..b4715e3 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ .settings/ /Debug/ /build/ +CMakeFiles/ diff --git a/apps/website-generator/ContentFile.h b/apps/website-generator/ContentFile.h index 86e9e94..c5f9a12 100644 --- a/apps/website-generator/ContentFile.h +++ b/apps/website-generator/ContentFile.h @@ -13,7 +13,7 @@ public: using FileMetadata = std::unordered_map; using FileContentBody = std::vector; - ContentFile(const std::string& filename) + ContentFile(const Path& filename) : mFilename(filename) { @@ -21,7 +21,7 @@ public: virtual ~ContentFile() = default; - std::string getFilename() const + Path getFilename() const { return mFilename; } @@ -49,7 +49,7 @@ public: } protected: - std::string mFilename; + Path mFilename; FileMetadata mMetadata; FileContentBody mContentBody; }; @@ -58,7 +58,7 @@ class ContentPage : public ContentFile { public: - ContentPage(const std::string& filename) + ContentPage(const Path& filename) : ContentFile(filename) { @@ -80,7 +80,7 @@ class ContentArticle : public ContentFile { public: - ContentArticle(const std::string& filename) + ContentArticle(const Path& filename) : ContentFile(filename) { diff --git a/apps/website-generator/MarkdownContentParser.cpp b/apps/website-generator/MarkdownContentParser.cpp index e69de29..c9b357d 100644 --- a/apps/website-generator/MarkdownContentParser.cpp +++ b/apps/website-generator/MarkdownContentParser.cpp @@ -0,0 +1,72 @@ +#include "MarkdownContentParser.h" + +void MarkdownContentParser::run(const Path& path) +{ + FileMetadata metadata; + + const auto lines = File(path).readLines(); + bool metadata_finished = false; + for (const auto& line : lines) + { + if (!metadata_finished) + { + const auto metadata = checkForMetadataItem(line); + if (!metadata) + { + metadata_finished = true; + mContentBody.push_back(line); + } + else + { + mMetadata[metadata->first] = metadata->second; + } + } + else + { + mContentBody.push_back(line); + } + } +} + +MarkdownContentParser::FileContentBody MarkdownContentParser::getContentBody() const +{ + return mContentBody; +} + +MarkdownContentParser::FileMetadata MarkdownContentParser::getFileMetadata() const +{ + return mMetadata; +} + +std::optional MarkdownContentParser::checkForMetadataItem(const std::string& line) const +{ + unsigned char_count = 0; + std::string prefix; + std::string suffix; + bool building_prefix = true; + for (const auto c : line) + { + if (c == ':' && char_count > 0 && building_prefix) + { + building_prefix = false; + } + else if (building_prefix) + { + prefix += c; + } + else + { + suffix += c; + } + char_count++; + } + + if (!prefix.empty() && !building_prefix) + { + return FileMetadataItem{ prefix, suffix }; + } + else + { + return std::nullopt; + } +} \ No newline at end of file diff --git a/apps/website-generator/MarkdownContentParser.h b/apps/website-generator/MarkdownContentParser.h index 7f288c0..44f4f5c 100644 --- a/apps/website-generator/MarkdownContentParser.h +++ b/apps/website-generator/MarkdownContentParser.h @@ -13,79 +13,14 @@ public: using FileMetadata = std::unordered_map; using FileContentBody = std::vector; - void run(const std::string& path) - { - FileMetadata metadata; + void run(const Path& path); - const auto lines = File(path).readLines(); - bool metadata_finished = false; + FileContentBody getContentBody() const; - for (const auto& line : lines) - { - if (!metadata_finished) - { - const auto metadata = checkForMetadataItem(line); - if (!metadata) - { - metadata_finished = true; - mContentBody.push_back(line); - } - else - { - mMetadata[metadata->first] - metadata->second; - } - } - else - { - mContentBody.push_back(line); - } - } - } - - FileContentBody getContentBody() const - { - return mContentBody; - } - - FileMetadata getFileMetadata() const - { - return mMetadata; - } + FileMetadata getFileMetadata() const; private: - - std::optional checkForMetadataItem(const std::string& line) const - { - unsigned char_count = 0; - std::string prefix; - std::string suffix; - bool building_prefix = true; - for (const auto c : line) - { - if (c == ':' && char_count > 0 && building_prefix) - { - building_prefix = false; - } - else if (building_prefix) - { - prefix += c; - } - else - { - suffix += c; - } - char_count ++; - } - - if (!prefix.empty() && !building_prefix) - { - return FileMetadataItem{prefix, suffix}; - } - else - { - return std::nullopt; - } - } + std::optional checkForMetadataItem(const std::string& line) const; FileMetadata mMetadata; FileContentBody mContentBody; diff --git a/apps/website-generator/WebsiteGenerator.cpp b/apps/website-generator/WebsiteGenerator.cpp index e69de29..247e497 100644 --- a/apps/website-generator/WebsiteGenerator.cpp +++ b/apps/website-generator/WebsiteGenerator.cpp @@ -0,0 +1,95 @@ +#include "WebsiteGenerator.h" + +void WebsiteGenerator::findProject(const std::string& searchPath) +{ + const auto config_path = std::filesystem::path(searchPath) / "config.toml"; + if (std::filesystem::exists(config_path)) + { + mProjectPath = searchPath; + std::cout << "Found config.toml in " << searchPath << std::endl; + } +} + +Path WebsiteGenerator::getConfigPath() const +{ + return mProjectPath / "config"; +} + +void WebsiteGenerator::readConfig() +{ + const auto lines = File(getConfigPath()).readLines(); + + enum class LineState + { + UNSET, + IN_SECTION_TAG, + BEFORE_EQUALS + }; + + + for (const auto& lines : lines) + { + auto line_state = + //if () + } + +} + +void WebsiteGenerator::parseContentFiles() +{ + findContentFiles(); + + for (auto& page : mPages) + { + page.load(); + } +} + +void WebsiteGenerator::parseTemplateFiles() +{ + +} + +void WebsiteGenerator::doSubstitutions() +{ + +} + +void WebsiteGenerator::write() +{ + // Setup output dir + const auto output_dir = mProjectPath / "output_custom"; + std::filesystem::create_directory(output_dir); + + // Write each page +} + +void WebsiteGenerator::findContentFiles() +{ + const auto pages_files = Directory::getFilesWithExtension(getPagesPath(), ".md"); + for (const auto& path : pages_files) + { + mPages.push_back(ContentPage(path)); + } + + const auto article_files = Directory::getFilesWithExtension(getArticlesPath(), ".md"); + for (const auto& path : article_files) + { + mArticles.push_back(ContentArticle(path)); + } +} + +Path WebsiteGenerator::getContentPath() const +{ + return mProjectPath / "content"; +} + +Path WebsiteGenerator::getPagesPath() const +{ + return getContentPath() / "pages"; +} + +Path WebsiteGenerator::getArticlesPath() const +{ + return getContentPath() / "articles"; +} diff --git a/apps/website-generator/WebsiteGenerator.h b/apps/website-generator/WebsiteGenerator.h index b6c94d0..57a73f1 100644 --- a/apps/website-generator/WebsiteGenerator.h +++ b/apps/website-generator/WebsiteGenerator.h @@ -11,88 +11,48 @@ class GeneratorConfig { + void setThemePath(const Path& path) + { + mThemesPath = path; + } + + void setActiveTheme(const std::string& theme) + { + mActiveTheme = theme; + } + +private: + Path mThemesPath; + std::string mActiveTheme; }; class WebsiteGenerator { public: - void findProject(const std::string& searchPath) - { - const auto config_path = std::filesystem::path(searchPath) / "config.toml"; - if (std::filesystem::exists(config_path)) - { - mProjectPath = searchPath; - std::cout << "Found config.toml in " << searchPath << std::endl; - } - } + void findProject(const std::string& searchPath); - void readConfig() - { + void readConfig(); - } + void parseContentFiles(); - void parseContentFiles() - { - findContentFiles(); + void parseTemplateFiles(); - for (auto& page : mPages) - { - page.load(); - } - } - - void parseTemplateFiles() - { - - } - - void doSubstitutions() - { - - } - - void write() - { - // Setup output dir - const auto output_dir = mProjectPath / "output_custom"; - std::filesystem::create_directory(output_dir); - - // Write each page - } + void doSubstitutions(); + void write(); private: - void findContentFiles() - { - const auto pages_files = Directory::getFilesWithExtension(getPagesPath(), ".md"); - for (const auto& path : pages_files) - { - mPages.push_back(ContentPage(path)); - } + void findContentFiles(); - const auto article_files = Directory::getFilesWithExtension(getArticlesPath(), ".md"); - for (const auto& path : article_files) - { - mArticles.push_back(ContentArticle(path)); - } - } + Path getContentPath() const; - Path getContentPath() const - { - return mProjectPath / "content"; - } + Path getPagesPath() const; - Path getPagesPath() const - { - return getContentPath() / "pages"; - } + Path getArticlesPath() const; - Path getArticlesPath() const - { - return getContentPath() / "articles"; - } + Path getConfigPath() const; std::filesystem::path mProjectPath; GeneratorConfig mConfig; diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 95cdfe8..2680b00 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -9,7 +9,9 @@ list(APPEND core_HEADERS file_utilities/File.h file_utilities/FileFormats.h StringUtils.h - http/HttpResponse.h) + http/HttpResponse.h + serializers/TomlReader.h +) list(APPEND core_LIB_INCLUDES Event.cpp @@ -27,7 +29,8 @@ list(APPEND core_LIB_INCLUDES streams/BinaryStream.cpp http/HttpResponse.cpp http/HttpHeader.cpp - http/HttpRequest.cpp) + http/HttpRequest.cpp + serializers/TomlReader.cpp) # add the executable add_library(core SHARED ${core_LIB_INCLUDES} ${core_HEADERS}) @@ -39,6 +42,7 @@ target_include_directories(core PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/memory" "${CMAKE_CURRENT_SOURCE_DIR}/streams" "${CMAKE_CURRENT_SOURCE_DIR}/data_structures" + "${CMAKE_CURRENT_SOURCE_DIR}/serializers" ) set_target_properties( core PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS ON ) set_property(TARGET core PROPERTY FOLDER src) \ No newline at end of file diff --git a/src/core/file_utilities/File.cpp b/src/core/file_utilities/File.cpp index ab412c4..e0271f6 100644 --- a/src/core/file_utilities/File.cpp +++ b/src/core/file_utilities/File.cpp @@ -100,9 +100,9 @@ std::vector File::readLines() return content; } -std::string File::getBaseFilename(const std::string& path) +std::string File::getBaseFilename(const Path& path) { - return std::filesystem::path(path).stem(); + return path.stem().string(); } std::string File::ReadText() diff --git a/src/core/file_utilities/File.h b/src/core/file_utilities/File.h index 23cbf6c..c654310 100644 --- a/src/core/file_utilities/File.h +++ b/src/core/file_utilities/File.h @@ -8,6 +8,8 @@ #include #include +using Path = std::filesystem::path; + class File { public: @@ -34,7 +36,7 @@ public: std::vector readLines(); - static std::string getBaseFilename(const std::string& path); + static std::string getBaseFilename(const Path& path); bool PathExists() const; diff --git a/src/core/serializers/TomlReader.cpp b/src/core/serializers/TomlReader.cpp new file mode 100644 index 0000000..e69de29 diff --git a/src/core/serializers/TomlReader.h b/src/core/serializers/TomlReader.h new file mode 100644 index 0000000..5ec6336 --- /dev/null +++ b/src/core/serializers/TomlReader.h @@ -0,0 +1,16 @@ +#pragma once + +#include ; +#include + +using Path = std::filesystem::path; + +class TomlContent +{ + //using SectionContent +}; + +class TomlReader +{ + +}; \ No newline at end of file diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 6072d9e..92d2f56 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -11,6 +11,7 @@ list(APPEND TestFiles audio/TestAudioWriter.cpp audio/TestMidiReader.cpp core/TestBinaryStream.cpp + core/TestTomlReader.cpp compiler/TestLexer.cpp compression/TestStreamCompressor.cpp database/TestDatabase.cpp diff --git a/test/core/TestTomlReader.cpp b/test/core/TestTomlReader.cpp new file mode 100644 index 0000000..cae33b0 --- /dev/null +++ b/test/core/TestTomlReader.cpp @@ -0,0 +1,12 @@ +#include "TomlReader.h" + +#include + +int main() +{ + const auto data_loc = std::filesystem::path(__FILE__) / "../data"; + const auto sample_toml_file = data_loc / "sample_toml.toml"; + + + return 0; +} \ No newline at end of file diff --git a/test/data/sample_toml.toml b/test/data/sample_toml.toml new file mode 100644 index 0000000..86873ac --- /dev/null +++ b/test/data/sample_toml.toml @@ -0,0 +1,4 @@ + +[themes] +location = "../personal-site-themes" +active_theme = "basic" \ No newline at end of file