Implemented StaticPage.

This commit is contained in:
Relintai 2022-02-06 13:44:30 +01:00
parent ecf3daf5cb
commit f7b17933b5
2 changed files with 56 additions and 18 deletions

View File

@ -1,17 +1,60 @@
#include "static_page.h"
#include "web/http/request.h"
#include "web/file_cache.h"
#include "web/html/html_builder.h"
#include "web/http/request.h"
#include "web/html/utils.h"
#include "core/os/directory.h"
void StaticPage::handle_request_main(Request *request) {
void StaticPage::_handle_request_main(Request *request) {
if (should_render_menu) {
render_menu(request);
}
void StaticPage::load() {
request->body += data;
request->compile_and_send_body();
}
void StaticPage::load_file(const String &path) {
Ref<Directory> d;
d.instance();
d->read_file_into(path, &data);
}
void StaticPage::load_and_process_file(const String &path) {
Ref<Directory> d;
d.instance();
d->read_file_into(path, &data);
if (path.file_get_extension() == "md") {
Utils::markdown_to_html(&data);
}
}
void StaticPage::load_md_file(const String &path) {
Ref<Directory> d;
d.instance();
d->read_file_into(path, &data);
Utils::markdown_to_html(&data);
}
void StaticPage::set_data_md(const String &d) {
data.clear();
Utils::markdown_to_html(&data);
}
void StaticPage::set_data(const String &d) {
data = d;
}
StaticPage::StaticPage() :
WebNode() {
should_render_menu = true;
}
StaticPage::~StaticPage() {

View File

@ -5,26 +5,21 @@
#include "web/http/web_node.h"
/*
StaticPage -> string data (serve it)
load_md(path) + parse_md(data)
load_bbcode(path) + ...
load_html(path)
load_file(path)
bool add menu -> handle
*/
class StaticPage : public WebNode {
RCPP_OBJECT(StaticPage, WebNode);
public:
void handle_request_main(Request *request);
void _handle_request_main(Request *request);
void load();
void load_file(const String &path);
void load_and_process_file(const String &path);
void load_md_file(const String &path);
void set_data_md(const String &d);
void set_data(const String &d);
String data;
bool should_render_menu;
StaticPage();
~StaticPage();