1 #ifndef __BIAWEBDOCITEMLIST__
2 #define __BIAWEBDOCITEMLIST__
9 #include <fmt/format.h>
10 #include <fmt/chrono.h>
11 #include "biawebstrings.hpp"
12 #include "biawebdocument.hpp"
14 // to implement a list of items (documents) with creation/modified date/time display
16 // to implement a single document item
19 // Just the required fields to build the item
25 DocListItem (std::string title, std::string url,
26 std::time_t ctime, std::time_t mtime ) {
27 this->title = escape_html (title);
33 std::time_t get_mtime() {
36 void set_mtime(std::time_t mtime) {
39 std::time_t get_ctime() {
42 void set_ctime(std::time_t ctime) {
46 std::string get_url() {
50 void set_url(std::string url) {
54 std::string get_title() {
57 void set_title(std::string title) {
58 this->title = escape_html (title);
61 // output to HTML vide the template
62 std::string to_html (std::string templatedir);
65 // output to HTML vide the template
66 std::string DocListItem::to_html (std::string templatedir) {
67 std::ifstream templ (templatedir + "/doclistitem.tpl.html");
68 std::string templstr ((std::istreambuf_iterator<char> (templ)),
69 (std::istreambuf_iterator<char> ()) );
73 c = *std::localtime (&this->ctime);
74 m = *std::localtime (&this->mtime);
76 std::string outputhtml = fmt::format (templstr, fmt::arg("url", this->url),
77 fmt::arg("doctitle", this->title),
79 fmt::arg("mdate", m));
84 // to implement a document list (or table)
88 std::list<DocListItem> items;
90 void set_title (std::string title) {
91 this->title = escape_html (title);
93 // add a document item
94 void add_document_item (DocListItem docitem) {
95 this->items.insert (this->items.cend(), docitem);
97 // render to HTML from a template
98 std::string to_html (std::string templatedir);
101 std::string DocList::to_html (std::string templatedir) {
102 std::ifstream templ (templatedir + "/doclist.tpl.html");
103 std::string templstr ( (std::istreambuf_iterator<char> (templ) ),
104 (std::istreambuf_iterator<char> ()));
108 std::string outputhtml = "";
109 // if the number of elements is non zero
110 if (this->items.size () != 0) {
111 std::string docitems = "";
112 for (DocListItem item : this->items)
113 docitems += item.to_html (templatedir);
115 outputhtml = fmt::format (templstr,
116 fmt::arg ("title", this->title),
117 fmt::arg ("docitems", docitems));