Tree Website generation implemented
[biaweb2.git] / biawebsidebar.hpp
index 75761da..a5ccef6 100644 (file)
@@ -29,7 +29,8 @@ namespace biaweb {
         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;
@@ -37,13 +38,13 @@ namespace biaweb {
         }
     };
 
-    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 ();
@@ -62,7 +63,7 @@ namespace biaweb {
         // 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 ();
@@ -90,20 +91,20 @@ namespace biaweb {
             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() +