1 #ifndef __BIAWEBDOCITEMLIST__
2 #define __BIAWEBDOCITEMLIST__
9 #include <fmt/format.h>
10 #include <fmt/chrono.h>
11 #include "biawebstrings.hpp"
12 #include "biawebdocument.hpp"
13 #include "biawebtemplate.hpp"
15 // to implement a list of items (documents) with creation/modified date/time display
17 // to implement a single document item
20 // Just the required fields to build the item
27 DocListItem (Document *doc, std::string urlpath) {
28 this->title = doc->get_title ();
29 this->url = urlpath + doc->get_filename() + ".html";
30 this->ctime = doc->get_creation_date ();
31 this->mtime = doc->get_modified_date ();
32 this->desc = doc->get_meta_desc ();
35 std::string get_desc () {
39 std::time_t get_mtime() {
43 std::time_t get_ctime() {
47 std::string get_url() {
51 std::string get_title() {
55 // output to HTML vide the template
56 std::string to_html (Template *t);
59 // output to HTML vide the template
60 std::string DocListItem::to_html (Template *t) {
61 std::string templstr = t->get_doclistitem_tpl ();
63 c = *std::localtime (&this->ctime);
64 m = *std::localtime (&this->mtime);
66 std::string outputhtml = fmt::format (templstr, fmt::arg("url", this->url),
67 fmt::arg("doctitle", this->title),
68 fmt::arg("desc", this->desc),
70 fmt::arg("mdate", m));
75 // to implement a document list (or table)
79 std::list<DocListItem> items;
81 void set_title (std::string title) {
84 // add a document item
85 void add_document_item (DocListItem docitem) {
86 this->items.insert (this->items.cend(), docitem);
88 // render to HTML from a template
89 std::string to_html (Template *t);
92 std::string DocList::to_html (Template *t) {
93 std::string templstr = t->get_doclist_tpl ();
95 std::string outputhtml = "";
96 // if the number of elements is non zero
97 if (this->items.size () != 0) {
98 std::string docitems = "";
99 for (DocListItem item : this->items)
100 docitems += item.to_html (t);
102 outputhtml = fmt::format (templstr,
103 fmt::arg ("title", this->title),
104 fmt::arg ("docitems", docitems));