#include <fstream>
#include <fmt/format.h>
#include "biawebutil.hpp"
+#include "biawebtemplate.hpp"
// classes to describe the a list of (link) items and sidebar containers which form part of
// main document
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);
}
};
- 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<char> (tpl_linkitem)),
- (std::istreambuf_iterator<char> ()));
- 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));
// 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<char> (tpl_item)),
- (std::istreambuf_iterator<char> ()));
- 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;
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<char> (sidetpl)) ,
- (std::istreambuf_iterator<char> ()));
- 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 = "";