S David
e0d46c18a8
- Change vim-integrated build directory. - Add WIP CgiServerApp class. - Fix IOCore repository URL
79 lines
2.1 KiB
C++
79 lines
2.1 KiB
C++
/* MarkdownRouteHandler.hpp
|
|
* Copyright © 2023 Saul D. Beniquez
|
|
* License: Mozilla Public License v. 2.0
|
|
*
|
|
* This Source Code Form is subject to the terms of the Mozilla Public License,
|
|
* v.2.0. If a copy of the MPL was not distributed with this file, You can
|
|
* obtain one at https://mozilla.org/MPL/2.0/.
|
|
*/
|
|
#pragma once
|
|
|
|
#include "types/containers.hpp"
|
|
|
|
#include "IRouteHandler.hpp"
|
|
#include "types.hpp"
|
|
|
|
#include <filesystem>
|
|
#include <map>
|
|
#include <string>
|
|
|
|
namespace mdml {
|
|
|
|
namespace {
|
|
namespace fs = std::filesystem;
|
|
using IOCore::Dictionary;
|
|
}
|
|
|
|
class MarkdownRouteHandler : public IRouteHandler {
|
|
public:
|
|
explicit MarkdownRouteHandler(fs::path working_dir = ".");
|
|
~MarkdownRouteHandler() override {}
|
|
|
|
// @{ Copy and move constructors
|
|
MarkdownRouteHandler(const MarkdownRouteHandler& other) = default;
|
|
MarkdownRouteHandler(MarkdownRouteHandler&&) = default;
|
|
|
|
auto operator=(const MarkdownRouteHandler&)
|
|
-> MarkdownRouteHandler& = default;
|
|
auto operator=(MarkdownRouteHandler&) -> MarkdownRouteHandler& = default;
|
|
// @}
|
|
|
|
void loadTemplate(const fs::path& template_name);
|
|
void loadMarkdown(const fs::path& markdown_page_name);
|
|
|
|
auto process(const std::string& name, const std::string& request_uri)
|
|
-> Result<std::string> override;
|
|
|
|
auto getHtmlData() -> std::string& { return html_data; }
|
|
auto getMarkdownData() -> std::string& { return markdown_data; }
|
|
|
|
// NOLINTNEXTLINE(readability-identifier-naming)
|
|
static auto GenerateRoutes(
|
|
std::shared_ptr<MarkdownRouteHandler> ref,
|
|
std::filesystem::path content_dir,
|
|
std::filesystem::path main_template
|
|
) -> Dictionary<std::shared_ptr<IRouteHandler>>;
|
|
|
|
std::reference_wrapper<std::ostream> OutputStream;
|
|
|
|
auto getWorkingDir() -> const fs::path& { return this->work_dir; }
|
|
|
|
protected:
|
|
auto render_document(
|
|
const std::string& title, const std::string& request_uri
|
|
) -> std::string;
|
|
|
|
static void load_document(
|
|
const fs::path& document_path, std::string& out_document
|
|
);
|
|
|
|
fs::path work_dir;
|
|
std::string html_data;
|
|
std::string markdown_data;
|
|
};
|
|
|
|
}
|
|
|
|
// clang-format off
|
|
// vim: set foldmethod=marker foldmarker=@{,@} textwidth=80 ts=8 sts=0 sw=8 noexpandtab ft=cpp.doxygen :
|