X-Git-Url: https://harishankar.org/repos/?p=biaweb2.git;a=blobdiff_plain;f=biawebdocument.hpp;h=39721076dbe33eca14b68e7bf67e3b13e51788d5;hp=221bc4f09b1273e2042f45317cbe958e5f5111dc;hb=HEAD;hpb=26b38b4a38c24955293a7144f1e1d74676601caf diff --git a/biawebdocument.hpp b/biawebdocument.hpp index 221bc4f..3972107 100644 --- a/biawebdocument.hpp +++ b/biawebdocument.hpp @@ -8,10 +8,11 @@ #include #include #include -#include #include "biawebutil.hpp" #include "biawebsidebar.hpp" #include "biawebstrings.hpp" +#include "biawebnavigationbit.hpp" +#include "biawebtemplate.hpp" // class to represent a biaweb document which can have a file name, title, description, // keywords, content and sidebar items @@ -24,7 +25,8 @@ namespace biaweb { std::string meta_desc; std::string meta_keywords; std::string content; - std::list sidebars; + std::list sidebars; + NavigationBit navbit; std::time_t cdate; std::time_t mdate; bool is_index; @@ -57,6 +59,11 @@ namespace biaweb { // fourth line onwards: Markdown contents Document (std::istream &file) ; + // set the navigation bit + void set_navigation_bit (NavigationBit navbit) { + this->navbit = navbit; + } + // set whether this is the index document void set_index (bool index = true) { this->is_index = index; @@ -94,8 +101,8 @@ namespace biaweb { return this->cdate; } - // output the document to HTML using the templates in templatedir - void output_to_html (std::string templatedir, std::string path); + // output the document to HTML using the template specified + void output_to_html (Template *t, std::string path); // set the content portion of document as raw HTML content void set_content (std::string content) { @@ -175,10 +182,9 @@ namespace biaweb { this->mdate = this->cdate; // read the rest of contents std::string line; - std::getline (infile, line); while (! infile.eof ()) { - contents.append (line + "\n"); std::getline (infile, line); + contents.append (line + "\n"); } this->set_markdown_content (contents); } @@ -188,24 +194,21 @@ namespace biaweb { } // output the document using the provided template - void Document::output_to_html (std::string templatedir, std::string path) + void Document::output_to_html (Template *t, std::string path) { - // read the main template file - std::ifstream tpl (templatedir + "/main.tpl.html"); - std::string templstr ( (std::istreambuf_iterator (tpl)), - (std::istreambuf_iterator ()) ); - tpl.close (); + std::string templstr = t->get_main_tpl (); + // read the style template file - std::ifstream style (templatedir + "/style.tpl.css"); - std::string stylesheet ( (std::istreambuf_iterator (style)), - (std::istreambuf_iterator ())); - style.close (); + std::string stylesheet = t->get_style_tpl (); // first render the sidebars std::string sidebartext; for (SideBar bar : sidebars) { - sidebartext += bar.to_html (templatedir); + sidebartext += bar.to_html (t); } + // render the navigation bit + std::string navbit_str = this->navbit.to_html (t); + // time of creation and modification struct std::tm c, m; c = *std::localtime (&this->cdate); @@ -219,6 +222,7 @@ namespace biaweb { fmt::arg ("description", this->meta_desc), fmt::arg ("cdate", c), fmt::arg ("mdate", m), + fmt::arg ("navbit", navbit_str), fmt::arg ("contents", this->content), fmt::arg ("sidebar", sidebartext) );