Made the default classes in ListPage customizable, and added docs about the generated html.

This commit is contained in:
Relintai 2022-02-04 16:49:02 +01:00
parent bf82dac4d3
commit e240034626
2 changed files with 39 additions and 6 deletions

View File

@ -124,21 +124,26 @@ void ListPage::render_entries(const Vector<String> &list_entries) {
}
String ListPage::render_page(const int page_index, const int page_count, const Vector<String> &list_entries, const int efrom, const int eto) {
String r = "";
HTMLBuilder b;
b.div(main_div_class);
for (int i = efrom; i < eto; ++i) {
r += render_entry(list_entries[i]);
b.w(render_entry(list_entries[i]));
}
r += Utils::get_pagination(get_full_uri(), page_count, page_index, max_visible_navigation_links);
b.w(Utils::get_pagination(get_full_uri(), page_count, page_index, max_visible_navigation_links));
b.cdiv();
return r;
return b.result;
}
String ListPage::render_entry(const String &list_entry) {
HTMLBuilder b;
b.div("list_entry")->w(list_entry)->cdiv();
b.div(main_div_class);
b.div(empty_div_class)->w(list_entry)->cdiv();
b.cdiv();
return b.result;
}
@ -146,7 +151,7 @@ String ListPage::render_entry(const String &list_entry) {
void ListPage::render_no_entries_response() {
HTMLBuilder b;
b.div("list_entry")->w("No conteny yet!")->cdiv();
b.div(empty_div_class)->w(placeholder_text)->cdiv();
_no_entries_response = b.result;
}
@ -169,6 +174,10 @@ ListPage::ListPage() :
max_visible_navigation_links = 6;
entry_per_page = 4;
main_div_class = "list_page";
entry_div_class = "list_entry";
empty_div_class = "list_entry_empty";
placeholder_text = "No content yet!";
}
ListPage::~ListPage() {

View File

@ -8,6 +8,25 @@
#include "core/http/request.h"
// This class will load and generate pages from a folder of md files. It supports pagination,
// it will put entry_per_page md files per page. It generates html on enter tree, and caches everything.
// Each md file gets rendered into a div with a class of "list_entry"
// HTML (If there are entries):
// render_menu()
// <div class="list_page"> // Set the class via the main_div_class property
// <div class="list_entry">md file 1</div> // Set the class via the entry_div_class property
// <div class="list_entry">md file 2</div>
// ...
// <pagination>
// </div>
// HTML (If there are no entries):
// render_menu()
// <div class="list_page"> // Set the class via the main_div_class property
// <div class="list_entry_empty">No content yet!</div> // Set the class via the empty_div_class property, text via placeholder_text property
// </div>
class ListPage : public WebNode {
RCPP_OBJECT(ListPage, WebNode);
@ -31,6 +50,11 @@ public:
int entry_per_page;
String folder;
String main_div_class;
String entry_div_class;
String empty_div_class;
String placeholder_text;
protected:
Vector<String> _pages;
String _no_entries_response;