Replaced cmake with scons
[biaweb2.git] / biawebtemplate.hpp
1 #ifndef __BIAWEBTEMPLATE__
2 #define __BIAWEBTEMPLATE__
3
4 #include <array>
5 #include <fstream>
6 #include "biawebutil.hpp"
7
8 namespace biaweb {
9 // class to load template from a directory for use with classes requiring to output
10 // via templates
11 class Template {
12 protected:
13 // all the template bits stored as strings
14 std::string main_tpl;
15 std::string doclist_tpl;
16 std::string doclistitem_tpl;
17 std::string genericlinklistitem_tpl;
18 std::string genericlistitem_tpl;
19 std::string navigationbit_tpl;
20 std::string sidebar_tpl;
21 std::string style_tpl;
22 std::array<std::string, 6> stringbits;
23 public:
24 // constructor: generate the template bits from a template directory
25 Template (std::string templatedir) ;
26
27 // getters;
28 std::string get_main_tpl () { return this->main_tpl; }
29 std::string get_doclist_tpl () { return this->doclist_tpl; }
30 std::string get_doclistitem_tpl () { return this->doclistitem_tpl; }
31 std::string get_genericlistitem_tpl () { return this->genericlistitem_tpl; }
32 std::string get_genericlinklistitem_tpl () { return this->genericlinklistitem_tpl; }
33 std::string get_navigationbit_tpl () { return this->navigationbit_tpl; }
34 std::string get_sidebar_tpl () { return this->sidebar_tpl; }
35 std::string get_style_tpl () { return this->style_tpl; }
36 std::string get_stringbit (unsigned int id) { return this->stringbits[id]; }
37 };
38
39 // construct a template from a source directory
40 Template::Template (std::string templatedir) {
41 // read the templates
42 this->main_tpl = load_from_file (templatedir + "/main.tpl.html");
43 this->doclist_tpl = load_from_file (templatedir + "/doclist.tpl.html");
44 this->doclistitem_tpl = load_from_file (templatedir + "/doclistitem.tpl.html");
45 this->genericlinklistitem_tpl = load_from_file
46 (templatedir + "/genericlinklistitem.tpl.html");
47 this->genericlistitem_tpl = load_from_file (templatedir + "/genericlistitem.tpl.html");
48 this->navigationbit_tpl = load_from_file (templatedir + "/navigationbit.tpl.html");
49 this->sidebar_tpl = load_from_file (templatedir + "/sidebar.tpl.html");
50 this->style_tpl = load_from_file (templatedir + "/style.tpl.css");
51
52
53 // read the stringbits into the array
54 std::ifstream f (templatedir + "/stringbits.txt");
55 unsigned int i = 0;
56 std::string line;
57 while (! f.eof () && i < this->stringbits.size ()) {
58 std::getline (f, line);
59 this->stringbits[i] = line;
60 i ++;
61 }
62 f.close ();
63 }
64
65 }
66
67 #endif