Refactored template loading to its own class for performance
[biaweb2.git] / biawebnavigationbit.hpp
index 6be5b40..08a2cc5 100644 (file)
@@ -6,6 +6,7 @@
 #include <fmt/format.h>
 #include "biawebutil.hpp"
 #include "biawebsidebar.hpp"
+#include "biawebtemplate.hpp"
 
 namespace biaweb {
     // class to represent a navigation bit like this in html
@@ -21,20 +22,17 @@ namespace biaweb {
         }
 
         // render using the given template directory
-        std::string to_html (std::string templatedir) ;
+        std::string to_html (Template *t) ;
     };
 
     // render using the given template 
-    std::string NavigationBit::to_html (std::string templatedir) {
-        std::ifstream templ (templatedir + "/navigationbit.tpl.html");
-        std::string templ_str ((std::istreambuf_iterator<char> (templ)),
-                               (std::istreambuf_iterator<char> ()));
-        
+    std::string NavigationBit::to_html (Template *t) {
+        std::string templ_str = t->get_navigationbit_tpl ();
 
         std::string output_html = "";
         std::string items_str = "";
         for (GenericLinkItem item : this->items)
-            items_str += item.to_html (templatedir);
+            items_str += item.to_html (t);
 
         if (this->items.size () > 0)
             output_html = fmt::format (templ_str, fmt::arg ("items", items_str));