X-Git-Url: https://harishankar.org/repos/?a=blobdiff_plain;f=biawebdoclist.hpp;h=5922303d15a6a6d325c4a4ad197dde141c1afdce;hb=1d6e80c91ca5a6c4551d89e7a1979490c2505745;hp=7c4efcdc01fed3cc48618d1dab7aa241bbae921b;hpb=fe9a0fef0b31ee3b94b3e73b7e319087a49a3054;p=biaweb2.git diff --git a/biawebdoclist.hpp b/biawebdoclist.hpp index 7c4efcd..5922303 100644 --- a/biawebdoclist.hpp +++ b/biawebdoclist.hpp @@ -10,6 +10,7 @@ #include #include "biawebstrings.hpp" #include "biawebdocument.hpp" +#include "biawebtemplate.hpp" // to implement a list of items (documents) with creation/modified date/time display namespace biaweb { @@ -19,15 +20,25 @@ namespace biaweb { // Just the required fields to build the item std::string title; std::string url; + std::string desc; std::time_t ctime; std::time_t mtime; public: DocListItem (std::string title, std::string url, - std::time_t ctime, std::time_t mtime ) { + std::time_t ctime, std::time_t mtime, std::string desc ) { this->title = escape_html (title); this->url = url; this->ctime = ctime; this->mtime = mtime; + this->desc = desc; + } + + std::string get_desc () { + return this->desc; + } + + void set_desc (std::string desc) { + this->desc = escape_html (desc); } std::time_t get_mtime() { @@ -59,20 +70,21 @@ namespace biaweb { } // output to HTML vide the template - std::string to_html (std::string templatedir); + std::string to_html (Template *t); }; // output to HTML vide the template - std::string DocListItem::to_html (std::string templatedir) { - std::ifstream templ (templatedir + "/doclistitem.tpl.html"); - std::string templstr ((std::istreambuf_iterator (templ)), - (std::istreambuf_iterator ()) ); - templ.close (); + std::string DocListItem::to_html (Template *t) { + std::string templstr = t->get_doclistitem_tpl (); + std::tm c, m; + c = *std::localtime (&this->ctime); + m = *std::localtime (&this->mtime); std::string outputhtml = fmt::format (templstr, fmt::arg("url", this->url), - fmt::arg("doctitle", this->title), - fmt::arg("cdate", *std::localtime (&this->ctime)), - fmt::arg("mdate", *std::localtime (&this->mtime))); + fmt::arg("doctitle", this->title), + fmt::arg("desc", this->desc), + fmt::arg("cdate", c), + fmt::arg("mdate", m)); return outputhtml; } @@ -91,22 +103,18 @@ namespace biaweb { this->items.insert (this->items.cend(), docitem); } // render to HTML from a template - std::string to_html (std::string templatedir); + std::string to_html (Template *t); }; - std::string DocList::to_html (std::string templatedir) { - std::ifstream templ (templatedir + "/doclist.tpl.html"); - std::string templstr ( (std::istreambuf_iterator (templ) ), - (std::istreambuf_iterator ())); - - templ.close (); + std::string DocList::to_html (Template *t) { + std::string templstr = t->get_doclist_tpl (); std::string outputhtml = ""; // if the number of elements is non zero if (this->items.size () != 0) { std::string docitems = ""; for (DocListItem item : this->items) - docitems += item.to_html (templatedir); + docitems += item.to_html (t); outputhtml = fmt::format (templstr, fmt::arg ("title", this->title),