Minor change - fixed program args string
[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::string rss_tpl;
23 std::string rss_item_tpl;
24 std::array<std::string, 8> stringbits;
25 public:
26 // constructor: generate the template bits from a template directory
27 Template (std::string templatedir) ;
28
29 // getters;
30 std::string get_main_tpl () { return this->main_tpl; }
31 std::string get_doclist_tpl () { return this->doclist_tpl; }
32 std::string get_doclistitem_tpl () { return this->doclistitem_tpl; }
33 std::string get_genericlistitem_tpl () { return this->genericlistitem_tpl; }
34 std::string get_genericlinklistitem_tpl () { return this->genericlinklistitem_tpl; }
35 std::string get_navigationbit_tpl () { return this->navigationbit_tpl; }
36 std::string get_sidebar_tpl () { return this->sidebar_tpl; }
37 std::string get_style_tpl () { return this->style_tpl; }
38 std::string get_stringbit (unsigned int id) { return this->stringbits[id]; }
39 std::string get_rss_tpl () { return this->rss_tpl; }
40 std::string get_rss_item_tpl () { return this->rss_item_tpl; }
41 };
42
43 // construct a template from a source directory
44 Template::Template (std::string templatedir) {
45 // read the templates
46 this->main_tpl = load_from_file (templatedir + "/main.tpl.html");
47 this->doclist_tpl = load_from_file (templatedir + "/doclist.tpl.html");
48 this->doclistitem_tpl = load_from_file (templatedir + "/doclistitem.tpl.html");
49 this->genericlinklistitem_tpl = load_from_file
50 (templatedir + "/genericlinklistitem.tpl.html");
51 this->genericlistitem_tpl = load_from_file (templatedir + "/genericlistitem.tpl.html");
52 this->navigationbit_tpl = load_from_file (templatedir + "/navigationbit.tpl.html");
53 this->sidebar_tpl = load_from_file (templatedir + "/sidebar.tpl.html");
54 this->style_tpl = load_from_file (templatedir + "/style.tpl.css");
55 this->rss_tpl = load_from_file (templatedir + "/rss.tpl.xml");
56 this->rss_item_tpl = load_from_file (templatedir + "/rssitem.tpl.xml");
57
58 // read the stringbits into the array
59 std::ifstream f (templatedir + "/stringbits.txt");
60 unsigned int i = 0;
61 std::string line;
62 while (! f.eof () && i < this->stringbits.size ()) {
63 std::getline (f, line);
64 this->stringbits[i] = line;
65 i ++;
66 }
67 f.close ();
68 }
69
70 }
71
72 #endif