void set_sidebar_url (std::string url) {
this->sidebar_url = url;
}
- std::string to_html ();
+ // output to HTML using a template directory specified
+ std::string to_html (std::string templatedir);
SideBarItem (std::string text = "", std::string url = "") {
this->sidebar_text = text;
}
};
- std::string SideBarItem::to_html () {
+ std::string SideBarItem::to_html (std::string templatedir) {
std::string html;
// if url is not empty it is a link item so load the sidebar link template
if (! this->sidebar_url.empty ()) {
if (!this->sidebar_text.empty ())
{
- std::ifstream tpl_linkitem ("templates/sidebarlinkitem.tpl.html");
+ std::ifstream tpl_linkitem (templatedir + "/sidebarlinkitem.tpl.html");
std::string tpl_linkitem_str ( (std::istreambuf_iterator<char> (tpl_linkitem)),
(std::istreambuf_iterator<char> ()));
tpl_linkitem.close ();
// Non link item. Load the normal sidebar item template.
else
{
- std::ifstream tpl_item ("templates/sidebaritem.tpl.html");
+ std::ifstream tpl_item (templatedir + "/sidebaritem.tpl.html");
std::string tpl_item_str ( (std::istreambuf_iterator<char> (tpl_item)),
(std::istreambuf_iterator<char> ()));
tpl_item.close ();
items.insert (items.cend(), item);
}
- // render the sidebar
- std::string to_html () ;
+ // render the sidebar using the template directory specified
+ std::string to_html (std::string templatedir) ;
};
// render the sidebar to HTML representation from the template.
- std::string SideBar::to_html () {
- std::ifstream sidetpl ("templates/sidebar.tpl.html");
+ 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 listitem;
// first get the sidebar items and render them to HTML
for (SideBarItem item : items) {
- listitem += item.to_html ();
+ listitem += item.to_html (templatedir);
}
std::unique_ptr<char[]> tpl_final (new char[sidetpl_str.size() +