diff --git a/apps/CMakeLists.txt b/apps/CMakeLists.txt index fb5e6ed..4c06224 100644 --- a/apps/CMakeLists.txt +++ b/apps/CMakeLists.txt @@ -29,12 +29,5 @@ target_link_libraries(sample_console PUBLIC console core network set_property(TARGET sample_console PROPERTY FOLDER apps) set_property(TARGET sample_gui PROPERTY FOLDER apps) -# Website Generator -add_executable(website_generator website-generator.cpp) -#target_include_directories(website_generator PUBLIC -# "${PROJECT_SOURCE_DIR}/src/console" -# ) -target_link_libraries(website_generator PUBLIC core web) - -set_property(TARGET website_generator PROPERTY FOLDER apps) +add_subdirectory(website-generator) diff --git a/apps/console-main.cpp b/apps/console-main.cpp index 8492cc1..8679397 100644 --- a/apps/console-main.cpp +++ b/apps/console-main.cpp @@ -3,9 +3,9 @@ int main(int argc, char *argv[]) { - auto command_line_args = CommandLineArgs::CreateUnique(); - command_line_args->Process(argc, argv); - command_line_args->RecordLaunchPath(); + auto command_line_args = CommandLineArgs::Create(); + command_line_args->process(argc, argv); + command_line_args->recordLaunchPath(); // Start the main app auto main_app = MainApplication::Create(); diff --git a/apps/gui-main.cpp b/apps/gui-main.cpp index c9ce6a3..0272962 100644 --- a/apps/gui-main.cpp +++ b/apps/gui-main.cpp @@ -6,9 +6,9 @@ int main(int argc, char *argv[]) { - auto args = CommandLineArgs::CreateUnique(); - args->Process(argc, argv); - args->RecordLaunchPath(); + auto args = CommandLineArgs::Create(); + args->process(argc, argv); + args->recordLaunchPath(); // Start the main app auto main_app = MainApplication::Create(); diff --git a/apps/website-generator/CMakeLists.txt b/apps/website-generator/CMakeLists.txt new file mode 100644 index 0000000..7016903 --- /dev/null +++ b/apps/website-generator/CMakeLists.txt @@ -0,0 +1,18 @@ + +list(APPEND website_generator_LIB_INCLUDES + ContentFile.h + ContentFile.cpp + MarkdownContentParser.h + MarkdownContentParser.cpp) + + +add_executable(website_generator main.cpp ${website_generator_LIB_INCLUDES}) + +target_include_directories(website_generator PUBLIC + "${CMAKE_CURRENT_SOURCE_DIR}" + ) + +target_link_libraries(website_generator PUBLIC core web) + +set_property(TARGET website_generator PROPERTY FOLDER apps/website-generator) + diff --git a/apps/website-generator/ContentFile.cpp b/apps/website-generator/ContentFile.cpp new file mode 100644 index 0000000..e69de29 diff --git a/apps/website-generator/ContentFile.h b/apps/website-generator/ContentFile.h new file mode 100644 index 0000000..e69de29 diff --git a/apps/website-generator/MarkdownContentParser.cpp b/apps/website-generator/MarkdownContentParser.cpp new file mode 100644 index 0000000..e69de29 diff --git a/apps/website-generator/MarkdownContentParser.h b/apps/website-generator/MarkdownContentParser.h new file mode 100644 index 0000000..e69de29 diff --git a/apps/website-generator.cpp b/apps/website-generator/main.cpp similarity index 57% rename from apps/website-generator.cpp rename to apps/website-generator/main.cpp index e0d4251..80d07d9 100644 --- a/apps/website-generator.cpp +++ b/apps/website-generator/main.cpp @@ -1,5 +1,7 @@ #include "CommandLineArgs.h" +#include "Directory.h" + #include #include #include @@ -10,11 +12,11 @@ class GeneratorConfig }; -class ContentPage +class ContentFile { public: - ContentPage(const std::string& filename) + ContentFile(const std::string& filename) : mFilename(filename) { @@ -25,11 +27,32 @@ public: return mFilename; } -private: - +protected: std::string mFilename; }; +class ContentPage : public ContentFile +{ +public: + + ContentPage(const std::string& filename) + : ContentFile(filename) + { + + } +}; + +class ContentArticle : public ContentFile +{ +public: + + ContentArticle(const std::string& filename) + : ContentFile(filename) + { + + } +}; + class WebsiteGenerator { @@ -52,26 +75,16 @@ public: void parseContentFiles() { - const auto content_dir = mProjectPath / "content"; - if (std::filesystem::is_directory(content_dir)) + const auto pages_files = Directory::getFilesWithExtension(getPagesPath(), ".md"); + for (const auto& path : pages_files) { - std::cout << "checking " << content_dir << std::endl; - const auto pages_dir = content_dir / "pages"; - if (std::filesystem::is_directory(pages_dir)) - { - std::cout << "checking " << pages_dir << std::endl; - for (const auto& entry : std::filesystem::directory_iterator(pages_dir)) - { - if (std::filesystem::is_regular_file(entry) && entry.path().extension() == ".md") - { - mPages.push_back(ContentPage(entry.path())); - } - } - } + mPages.push_back(ContentPage(path)); } - else + + const auto article_files = Directory::getFilesWithExtension(getArticlesPath(), ".md"); + for (const auto& path : article_files) { - std::cout << "nope in " << content_dir << std::endl; + mArticles.push_back(ContentArticle(path)); } for(const auto& page : mPages) @@ -79,6 +92,10 @@ public: std::cout << "Got page " << page.getFilename() << std::endl; } + for(const auto& article : mArticles) + { + std::cout << "Got article " << article.getFilename() << std::endl; + } } void parseTemplateFiles() @@ -99,9 +116,25 @@ public: private: + Path getContentPath() const + { + return mProjectPath / "content"; + } + + Path getPagesPath() const + { + return getContentPath() / "pages"; + } + + Path getArticlesPath() const + { + return getContentPath() / "articles"; + } + std::filesystem::path mProjectPath; GeneratorConfig mConfig; std::vector mPages; + std::vector mArticles; }; diff --git a/src/client/GuiApplication.cpp b/src/client/GuiApplication.cpp index 34d7f55..2c21c78 100644 --- a/src/client/GuiApplication.cpp +++ b/src/client/GuiApplication.cpp @@ -49,7 +49,7 @@ void GuiApplication::SetUpWidget() auto tabbedPanel = TabbedPanelWidget::Create(); auto textEditor = TextEditorView::Create(); - auto path = mMainApplication->GetCommandLineArgs()->GetLaunchPath(); + auto path = mMainApplication->GetCommandLineArgs()->getLaunchPath(); path /= "out.txt"; textEditor->GetController()->SetSavePath(path); textEditor->GetController()->SetLoadPath(path); diff --git a/src/console/MainApplication.cpp b/src/console/MainApplication.cpp index f95aea1..ca2bee2 100644 --- a/src/console/MainApplication.cpp +++ b/src/console/MainApplication.cpp @@ -36,7 +36,7 @@ void MainApplication::Initialize(CommandLineArgsUPtr commandLineArgs, std::uniqu } mCommandLineArgs = std::move(commandLineArgs); - const auto launch_path = mCommandLineArgs->GetLaunchPath().string(); + const auto launch_path = mCommandLineArgs->getLaunchPath().string(); FileLogger::GetInstance().SetWorkDirectory(launch_path); FileLogger::GetInstance().Open(); @@ -56,23 +56,23 @@ void MainApplication::Initialize(CommandLineArgsUPtr commandLineArgs, std::uniqu void MainApplication::Run() { std::string program_type; - if(mCommandLineArgs->GetNumberOfArgs() > 1) + if(mCommandLineArgs->getNumberOfArgs() > 1) { - program_type = mCommandLineArgs->GetArg(1); + program_type = mCommandLineArgs->getArg(1); } std::string input_path; std::string output_path; - for(unsigned idx=1; idxGetNumberOfArgs(); idx++) + for(unsigned idx=1; idxgetNumberOfArgs(); idx++) { - auto arg = mCommandLineArgs->GetArg(idx); - if(arg == "-input" && mCommandLineArgs->GetNumberOfArgs() > idx+1) + auto arg = mCommandLineArgs->getArg(idx); + if(arg == "-input" && mCommandLineArgs->getNumberOfArgs() > idx+1) { - input_path = mCommandLineArgs->GetArg(idx + 1); + input_path = mCommandLineArgs->getArg(idx + 1); } - else if(arg == "-output" && mCommandLineArgs->GetNumberOfArgs() > idx+1) + else if(arg == "-output" && mCommandLineArgs->getNumberOfArgs() > idx+1) { - output_path = mCommandLineArgs->GetArg(idx + 1); + output_path = mCommandLineArgs->getArg(idx + 1); } } diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 94e0d6a..95cdfe8 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -5,6 +5,7 @@ list(APPEND core_HEADERS Color.h CommandLineArgs.h loggers/FileLogger.h + file_utilities/Directory.h file_utilities/File.h file_utilities/FileFormats.h StringUtils.h @@ -17,6 +18,7 @@ list(APPEND core_LIB_INCLUDES CommandLineArgs.cpp data_structures/Tree.cpp loggers/FileLogger.cpp + file_utilities/Directory.cpp file_utilities/File.cpp file_utilities/FileFormats.cpp memory/SharedMemory.cpp diff --git a/src/core/file_utilities/Directory.cpp b/src/core/file_utilities/Directory.cpp new file mode 100644 index 0000000..1bffcd4 --- /dev/null +++ b/src/core/file_utilities/Directory.cpp @@ -0,0 +1,17 @@ +#include "Directory.h" + +std::vector Directory::getFilesWithExtension(const Path& path, const std::string& extension) +{ + std::vector paths; + if (std::filesystem::is_directory(path)) + { + for (const auto& entry : std::filesystem::directory_iterator(path)) + { + if (std::filesystem::is_regular_file(entry) && entry.path().extension() == extension) + { + paths.push_back(entry.path()); + } + } + } + return paths; +} diff --git a/src/core/file_utilities/Directory.h b/src/core/file_utilities/Directory.h new file mode 100644 index 0000000..dcd47a1 --- /dev/null +++ b/src/core/file_utilities/Directory.h @@ -0,0 +1,13 @@ +#pragma once + +#include +#include + +using Path = std::filesystem::path; + +class Directory +{ +public: + + static std::vector getFilesWithExtension(const Path& path, const std::string& extension); +};