Separated the strings used for document tree generation from code
[biaweb2.git] / biawebnavigationbit.hpp
1 #ifndef __BIAWEBNAVIGATIONBIT__
2 #define __BIAWEBNAVIGATIONBIT__
3
4 #include <list>
5 #include <fstream>
6 #include <fmt/format.h>
7 #include "biawebutil.hpp"
8 #include "biawebsidebar.hpp"
9
10 namespace biaweb {
11 // class to represent a navigation bit like this in html
12 // > Parent > Child > Subchild
13 // etc.
14 class NavigationBit {
15 protected:
16 std::list<GenericLinkItem> items;
17 public:
18 // add a generic link item - this should add to beginning of the list
19 void add_link_item (GenericLinkItem item) {
20 items.insert (items.cbegin(), item);
21 }
22
23 // render using the given template directory
24 std::string to_html (std::string templatedir) ;
25 };
26
27 // render using the given template
28 std::string NavigationBit::to_html (std::string templatedir) {
29 std::ifstream templ (templatedir + "/navigationbit.tpl.html");
30 std::string templ_str ((std::istreambuf_iterator<char> (templ)),
31 (std::istreambuf_iterator<char> ()));
32
33
34 std::string output_html = "";
35 std::string items_str = "";
36 for (GenericLinkItem item : this->items)
37 items_str += item.to_html (templatedir);
38
39 if (this->items.size () > 0)
40 output_html = fmt::format (templ_str, fmt::arg ("items", items_str));
41
42 return output_html;
43 }
44 }
45
46 #endif