mirror of
https://github.com/Relintai/rcpp_framework.git
synced 2025-05-06 17:51:36 +02:00
Implemented StaticPage.
This commit is contained in:
parent
ecf3daf5cb
commit
f7b17933b5
@ -1,17 +1,60 @@
|
|||||||
#include "static_page.h"
|
#include "static_page.h"
|
||||||
|
|
||||||
#include "web/http/request.h"
|
|
||||||
#include "web/file_cache.h"
|
#include "web/file_cache.h"
|
||||||
#include "web/html/html_builder.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);
|
||||||
|
}
|
||||||
|
|
||||||
|
request->body += data;
|
||||||
|
request->compile_and_send_body();
|
||||||
}
|
}
|
||||||
|
|
||||||
void StaticPage::load() {
|
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() :
|
StaticPage::StaticPage() :
|
||||||
WebNode() {
|
WebNode() {
|
||||||
|
|
||||||
|
should_render_menu = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
StaticPage::~StaticPage() {
|
StaticPage::~StaticPage() {
|
||||||
|
@ -5,26 +5,21 @@
|
|||||||
|
|
||||||
#include "web/http/web_node.h"
|
#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 {
|
class StaticPage : public WebNode {
|
||||||
RCPP_OBJECT(StaticPage, WebNode);
|
RCPP_OBJECT(StaticPage, WebNode);
|
||||||
|
|
||||||
public:
|
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();
|
||||||
~StaticPage();
|
~StaticPage();
|
||||||
|
Loading…
Reference in New Issue
Block a user