Added Navigation bit to the top of documents for the categories
[biaweb2.git] / biawebnavigationbit.hpp
diff --git a/biawebnavigationbit.hpp b/biawebnavigationbit.hpp
new file mode 100644 (file)
index 0000000..6be5b40
--- /dev/null
@@ -0,0 +1,46 @@
+#ifndef __BIAWEBNAVIGATIONBIT__
+#define __BIAWEBNAVIGATIONBIT__
+
+#include <list>
+#include <fstream>
+#include <fmt/format.h>
+#include "biawebutil.hpp"
+#include "biawebsidebar.hpp"
+
+namespace biaweb {
+    // class to represent a navigation bit like this in html
+    // > Parent > Child > Subchild
+    // etc.
+    class NavigationBit {
+      protected:
+      std::list<GenericLinkItem> items;
+      public:
+        // add a generic link item - this should add to beginning of the list
+        void add_link_item (GenericLinkItem item) {
+            items.insert (items.cbegin(), item);
+        }
+
+        // render using the given template directory
+        std::string to_html (std::string templatedir) ;
+    };
+
+    // 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 output_html = "";
+        std::string items_str = "";
+        for (GenericLinkItem item : this->items)
+            items_str += item.to_html (templatedir);
+
+        if (this->items.size () > 0)
+            output_html = fmt::format (templ_str, fmt::arg ("items", items_str));
+
+        return output_html;
+    }
+}
+
+#endif
\ No newline at end of file