From 7d3c9ec7368a5d25235e818c2c147ba7e89f6567 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABl=20Gassmann?= Date: Sun, 27 Feb 2022 14:06:15 +0100 Subject: [+] Added base project --- inc/FileAssembler.h | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 inc/FileAssembler.h (limited to 'inc/FileAssembler.h') diff --git a/inc/FileAssembler.h b/inc/FileAssembler.h new file mode 100644 index 0000000..3eaab35 --- /dev/null +++ b/inc/FileAssembler.h @@ -0,0 +1,61 @@ +#ifndef FA_H +#define FA_H + +#include +#include +#include +#include +#include +#include + +using namespace std; + +class FileAssembler{ + +private: + string path; + map variables; + map templates; + map pages; + map posts; + list cached_res; + + string get_file_content(string path); + void parse_variables(); + map assemble_from_iterator(map::iterator it, map::iterator end, bool is_post); + string parse(string title, string content, bool is_post); + string parse_arg(string arg_name, string to_parse); + +public: + FileAssembler(string path); + + map get_pages(); + map get_posts(); + list get_cached_resources(){ + return cached_res; + } + string get_target(){ + string w = variables["website"]; + static std::regex rgx("\\w+\\.\\w+"); + std::smatch match; + if (std::regex_search(w, match, rgx)) + return match[0]; + cerr << "Error: swg: website attribute is badly configured!" << endl; + exit(7); + } + string get_index(){ + if(variables.find("index") == variables.end()){ + return ""; + } + return variables["index"]; + } + + static string lowercase(string s){ + string low = ""; + for (int i = 0; i < s.length(); i++) { + low += tolower(s[i]); + } + return low; + } +}; +#endif -- cgit v1.2.3