rcpp_framework/web_modules/static_pages/static_page.cpp

74 lines
1.3 KiB
C++
Raw Normal View History

#include "static_page.h"
#include "core/os/directory.h"
2022-02-05 16:55:07 +01:00
#include "web/file_cache.h"
#include "web/html/html_builder.h"
2022-02-06 13:44:30 +01:00
#include "web/html/utils.h"
#include "web/http/request.h"
2022-02-06 13:44:30 +01:00
void StaticPage::_handle_request_main(Request *request) {
if (should_render_menu) {
render_menu(request);
}
render(request);
2022-02-06 13:44:30 +01:00
request->compile_and_send_body();
}
void StaticPage::render(Request *request) {
request->body += data;
}
void StaticPage::render_preview(Request *request) {
request->body += preview_data;
}
2022-02-06 13:44:30 +01:00
void StaticPage::load_file(const String &path) {
Ref<Directory> d;
d.instance();
2022-02-06 13:44:30 +01:00
d->read_file_into(path, &data);
}
2022-02-06 13:44:30 +01:00
void StaticPage::load_and_process_file(const String &path) {
Ref<Directory> d;
d.instance();
2022-02-06 13:44:30 +01:00
d->read_file_into(path, &data);
if (path.file_get_extension() == "md") {
Utils::markdown_to_html(&data);
}
}
2022-02-06 13:44:30 +01:00
void StaticPage::load_md_file(const String &path) {
Ref<Directory> d;
d.instance();
2022-02-06 13:44:30 +01:00
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);
}
2022-02-06 13:44:30 +01:00
void StaticPage::set_data(const String &d) {
data = d;
}
void StaticPage::set_preview_data(const String &d) {
preview_data = d;
}
StaticPage::StaticPage() :
WebNode() {
2022-02-06 13:44:30 +01:00
should_render_menu = true;
}
StaticPage::~StaticPage() {
}