X-Git-Url: https://harishankar.org/repos/?p=biaweb2.git;a=blobdiff_plain;f=biawebsidebar.hpp;h=226f51a52b658f853f1d22edfd1338412088ee60;hp=6f419fa0f55940c9fce3829040bc680c31e7441d;hb=HEAD;hpb=a302a25538bc69491c4844ef065c6b50e098387a diff --git a/biawebsidebar.hpp b/biawebsidebar.hpp index 6f419fa..226f51a 100644 --- a/biawebsidebar.hpp +++ b/biawebsidebar.hpp @@ -6,6 +6,7 @@ #include #include #include "biawebutil.hpp" +#include "biawebtemplate.hpp" // classes to describe the a list of (link) items and sidebar containers which form part of // main document @@ -30,8 +31,8 @@ namespace biaweb { void set_item_url (std::string url) { this->itemurl = escape_html (url); } - // output to HTML using a template directory specified - std::string to_html (std::string templatedir); + // output to HTML using a template specified + std::string to_html (Template *t); GenericLinkItem (std::string text = "", std::string url = "") { this->itemtext = escape_html (text); @@ -39,17 +40,13 @@ namespace biaweb { } }; - std::string GenericLinkItem::to_html (std::string templatedir) { + std::string GenericLinkItem::to_html (Template *t) { std::string html = ""; // if url is not empty it is a link item so load the sidebar link template if (! this->itemurl.empty ()) { if (!this->itemtext.empty ()) { - std::ifstream tpl_linkitem (templatedir + "/genericlinklistitem.tpl.html"); - - std::string tpl_linkitem_str ( (std::istreambuf_iterator (tpl_linkitem)), - (std::istreambuf_iterator ())); - tpl_linkitem.close (); + std::string tpl_linkitem_str = t->get_genericlinklistitem_tpl (); html = fmt::format (tpl_linkitem_str, fmt::arg ("itemurl", this->itemurl), fmt::arg ("itemtext", this->itemtext)); @@ -58,11 +55,7 @@ namespace biaweb { // Non link item. Load the normal sidebar item template. else if (! this->itemtext.empty ()) { - std::ifstream tpl_item (templatedir + "/genericlistitem.tpl.html"); - - std::string tpl_item_str ( (std::istreambuf_iterator (tpl_item)), - (std::istreambuf_iterator ())); - tpl_item.close (); + std::string tpl_item_str = t->get_genericlistitem_tpl (); html = fmt::format (tpl_item_str, fmt::arg ("itemtext", this->itemtext) ); } return html; @@ -84,20 +77,18 @@ namespace biaweb { this->items.insert (this->items.cend(), item); } - // render the sidebar using the template directory specified - std::string to_html (std::string templatedir) ; + // render the sidebar using the template specified + std::string to_html (Template *t) ; }; // render the sidebar to HTML representation from the template. - std::string SideBar::to_html (std::string templatedir) { - std::ifstream sidetpl (templatedir + "/sidebar.tpl.html"); - std::string sidetpl_str ( ( std::istreambuf_iterator (sidetpl)) , - (std::istreambuf_iterator ())); - sidetpl.close (); + std::string SideBar::to_html (Template *t) { + std::string sidetpl_str = t->get_sidebar_tpl (); + std::string listitems; // first get the sidebar items and render them to HTML for (GenericLinkItem item : this->items) { - listitems += item.to_html (templatedir); + listitems += item.to_html (t); } std::string html = "";