Break web generator to own cmake.
This commit is contained in:
parent
bd60a28eef
commit
ebd41bf4ee
14 changed files with 121 additions and 45 deletions
|
@ -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)
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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();
|
||||
|
|
18
apps/website-generator/CMakeLists.txt
Normal file
18
apps/website-generator/CMakeLists.txt
Normal file
|
@ -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)
|
||||
|
0
apps/website-generator/ContentFile.cpp
Normal file
0
apps/website-generator/ContentFile.cpp
Normal file
0
apps/website-generator/ContentFile.h
Normal file
0
apps/website-generator/ContentFile.h
Normal file
0
apps/website-generator/MarkdownContentParser.cpp
Normal file
0
apps/website-generator/MarkdownContentParser.cpp
Normal file
0
apps/website-generator/MarkdownContentParser.h
Normal file
0
apps/website-generator/MarkdownContentParser.h
Normal file
|
@ -1,5 +1,7 @@
|
|||
#include "CommandLineArgs.h"
|
||||
|
||||
#include "Directory.h"
|
||||
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
@ -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<ContentPage> mPages;
|
||||
std::vector<ContentArticle> mArticles;
|
||||
};
|
||||
|
||||
|
|
@ -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);
|
||||
|
|
|
@ -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; idx<mCommandLineArgs->GetNumberOfArgs(); idx++)
|
||||
for(unsigned idx=1; idx<mCommandLineArgs->getNumberOfArgs(); 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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
17
src/core/file_utilities/Directory.cpp
Normal file
17
src/core/file_utilities/Directory.cpp
Normal file
|
@ -0,0 +1,17 @@
|
|||
#include "Directory.h"
|
||||
|
||||
std::vector<Path> Directory::getFilesWithExtension(const Path& path, const std::string& extension)
|
||||
{
|
||||
std::vector<Path> 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;
|
||||
}
|
13
src/core/file_utilities/Directory.h
Normal file
13
src/core/file_utilities/Directory.h
Normal file
|
@ -0,0 +1,13 @@
|
|||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
#include <filesystem>
|
||||
|
||||
using Path = std::filesystem::path;
|
||||
|
||||
class Directory
|
||||
{
|
||||
public:
|
||||
|
||||
static std::vector<Path> getFilesWithExtension(const Path& path, const std::string& extension);
|
||||
};
|
Loading…
Reference in a new issue