From 809de8a01cc23f3170eb4be9a490a4c97061b5af Mon Sep 17 00:00:00 2001 From: Relintai Date: Mon, 14 Feb 2022 23:14:33 +0100 Subject: [PATCH] Add the new virtuals to the static pages. --- web_modules/static_pages/static_page.cpp | 26 +++++++++++++++++------- web_modules/static_pages/static_page.h | 7 ++++++- 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/web_modules/static_pages/static_page.cpp b/web_modules/static_pages/static_page.cpp index 60c0d4e..d9ba9c1 100644 --- a/web_modules/static_pages/static_page.cpp +++ b/web_modules/static_pages/static_page.cpp @@ -1,31 +1,39 @@ #include "static_page.h" +#include "core/os/directory.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" +#include "web/http/request.h" void StaticPage::_handle_request_main(Request *request) { if (should_render_menu) { render_menu(request); } - request->body += data; + render(request); request->compile_and_send_body(); } +void StaticPage::render(Request *request) { + request->body += data; +} + +void StaticPage::render_preview(Request *request) { + request->body += preview_data; +} + void StaticPage::load_file(const String &path) { Ref d; d.instance(); - + d->read_file_into(path, &data); } void StaticPage::load_and_process_file(const String &path) { Ref d; d.instance(); - + d->read_file_into(path, &data); if (path.file_get_extension() == "md") { @@ -36,21 +44,25 @@ void StaticPage::load_and_process_file(const String &path) { void StaticPage::load_md_file(const String &path) { Ref 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; } +void StaticPage::set_preview_data(const String &d) { + preview_data = d; +} + StaticPage::StaticPage() : WebNode() { diff --git a/web_modules/static_pages/static_page.h b/web_modules/static_pages/static_page.h index f5ce513..9c9b1b3 100644 --- a/web_modules/static_pages/static_page.h +++ b/web_modules/static_pages/static_page.h @@ -11,14 +11,19 @@ class StaticPage : public WebNode { public: void _handle_request_main(Request *request); + void render(Request *request); + void render_preview(Request *request); + 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); + void set_preview_data(const String &d); String data; + String preview_data; bool should_render_menu; StaticPage();