// // std::cout << "Usage: " << argv[0] << " <main tree>" << std::endl;
DocumentTree tree ("");
- tree.document_tree_builder ("/home/hari/Projects/BiaWeb2/Test/In");
+ tree.document_tree_builder ("Test/Reviews");
tree.visualize_tree ();
- tree.create_tree_html ("/home/hari/Projects/BiaWeb2/templates",
+ tree.create_tree_html ("templates",
"Test/Out");
// // }
--- /dev/null
+#ifndef __BIAWEBDOCITEMLIST__
+#define __BIAWEBDOCITEMLIST__
+#include <ctime>
+#include <string>
+#include <fstream>
+#include <iostream>
+#include <list>
+#include "biawebstrings.hpp"
+#include "biawebdocument.hpp"
+
+// to implement a list of items (documents) with creation/modified date/time display
+namespace biaweb {
+ // to implement a single document item
+ class DocListItem {
+ protected:
+ // Just the required fields to build the item
+ std::string title;
+ std::string url;
+ std::time_t ctime;
+ std::time_t mtime;
+ public:
+ DocListItem (std::string title, std::string url,
+ std::time_t ctime, std::time_t mtime ) {
+ this->title = title;
+ this->url = url;
+ this->ctime = ctime;
+ this->mtime = mtime;
+ }
+
+ std::time_t get_mtime() {
+ return this->mtime;
+ }
+ void set_mtime(std::time_t mtime) {
+ this->mtime = mtime;
+ }
+ std::time_t get_ctime() {
+ return this->ctime;
+ }
+ void set_ctime(std::time_t ctime) {
+ this->ctime = ctime;
+ }
+
+ std::string get_url() {
+ return this->url;
+ }
+
+ void set_url(std::string url) {
+ this->url = url;
+ }
+
+ std::string get_title() {
+ return this->title;
+ }
+ void set_title(std::string title) {
+ this->title = title;
+ }
+
+ // output to HTML
+ std::string to_html (std::string templatedir);
+ };
+
+ // output to HTML vide the template
+ std::string DocListItem::to_html (std::string templatedir) {
+ std::ifstream templ (templatedir + "/doclistitem.tpl.html");
+ std::string templstr ((std::istreambuf_iterator<char> (templ)),
+ (std::istreambuf_iterator<char> ()) );
+ templ.close ();
+
+ // Allocate enough size for the output buffer
+ std::unique_ptr<char[]> outputstr (new char [templstr.size() +
+ this->title.size() +
+ this->url.size () +
+ 200]);
+
+ char ctm_str[100];
+ char mtm_str[100];
+ strftime (ctm_str, 100, DATE_FORMAT, std::localtime (&this->ctime));
+ strftime (mtm_str, 100, DATE_FORMAT, std::localtime (&this->mtime));
+
+ sprintf (outputstr.get(), templstr.c_str(),
+ this->url.c_str(),
+ this->title.c_str(),
+ ctm_str, mtm_str);
+
+ std::string outputhtml;
+ outputhtml.append (outputstr.get());
+ return outputhtml;
+ }
+
+ // to implement a document list (or table)
+ class DocList {
+ protected:
+ std::string title;
+ std::list<DocListItem> items;
+ public:
+ void set_title (std::string title) {
+ this->title = title;
+ }
+ // add a document item
+ void add_document_item (DocListItem docitem) {
+ this->items.insert (this->items.cend(), docitem);
+ }
+ // render to HTML from a template
+ std::string to_html (std::string templatedir);
+ };
+
+ std::string DocList::to_html (std::string templatedir) {
+ std::ifstream templ (templatedir + "/doclist.tpl.html");
+ std::string templstr ( (std::istreambuf_iterator<char> (templ) ),
+ (std::istreambuf_iterator<char> ()));
+
+ std::string docitems = "";
+ std::string outputhtml = "";
+ // if the number of elements is non zero
+ if (this->items.size () != 0) {
+ for (DocListItem item : this->items)
+ docitems += item.to_html (templatedir);
+
+ // Allocate space for output buffer
+ std::unique_ptr<char[]> outputstr (new char [
+ templstr.size () +
+ docitems.size () +
+ this->title.size ()
+ ]);
+ sprintf (outputstr.get(), templstr.c_str(),
+ this->title.c_str(),
+ docitems.c_str() );
+
+ outputhtml.append (outputstr.get());
+ }
+ return outputhtml;
+ }
+}
+
+#endif
\ No newline at end of file
#include <ctime>
#include "biawebutil.hpp"
#include "biawebsidebar.hpp"
+#include "biawebstrings.hpp"
// class to represent a biaweb document which can have a file name, title, description,
// keywords, content and sidebar items
void Document::output_to_html (std::string templatedir, std::string path)
{
std::ifstream tpl;
- tpl.open (templatedir + "/main.tpl.html", std::ios_base::openmode::_S_in);
+ tpl.open (templatedir + "/main.tpl.html");
std::string main_tpl ( (std::istreambuf_iterator<char> (tpl)),
(std::istreambuf_iterator<char> ()) );
tpl.close ();
std::time_t creat = this->cdate;
std::time_t modif = this->cdate;
std::strftime (ctm_str, sizeof (ctm_str),
- "%d %b %Y, %H:%M", std::localtime (&creat));
+ DATE_FORMAT, std::localtime (&creat));
std::strftime (mtm_str, sizeof (mtm_str),
- "%d %b %Y, %H:%M", std::localtime (&modif));
+ DATE_FORMAT, std::localtime (&modif));
// Allocate enough space for the output buffer
std::unique_ptr<char[]> final_templ(
200 +
sidebartext.size()]);
std::sprintf (final_templ.get (), main_tpl.c_str(), this->title.c_str(),
+ this->meta_keywords.c_str(), this->meta_desc.c_str (),
ctm_str, mtm_str,
this->content.c_str(), sidebartext.c_str());
#include "biawebdocument.hpp"
#include "biawebstrings.hpp"
#include "biawebutil.hpp"
+#include "biawebdoclist.hpp"
-// to implement a document tree - both with or without subtrees
+// class to implement a document tree - both with or without subtrees
namespace biaweb {
class DocumentTree {
protected:
std::filesystem::create_directories (filepath);
// Create the list of documents in this tree with links
- // Reuse the sidebar class and sidebaritem class which is
- // basically a list of links but instead of adding a sidebar
- // add it to the content portion
- SideBar article_list;
- article_list.set_title (this->title + ": " + ART_LIST);
+ std::unique_ptr<DocList> article_list (new DocList ());
+ article_list.get()->set_title (this->title + ": " + ART_LIST);
// sort the documents as per creation time and then add the document
// links - newest documents should appear above older ones.
sort_documents_creation_time ();
for (Document doc : this->docs) {
- SideBarItem item;
- item.set_sidebar_text (doc.get_title());
- item.set_sidebar_url (urlpath + doc.get_filename() + ".html");
- article_list.add_sidebar_item (item);
+ DocListItem item (doc.get_title(),
+ urlpath + doc.get_filename() + ".html",
+ doc.get_creation_date(), doc.get_modified_date ());
+ article_list.get()->add_document_item (item);
// output the document also, add the side bars
doc.add_side_bar (*bar1.get());
doc.add_side_bar (*bar2.get());
doc.output_to_html (templatedir, filepath);
}
- index.get()->set_content (this->summary + article_list.to_html(templatedir));
+ // index should contain the summary followed by the article list
+ index.get()->set_content (this->summary + article_list.get()->to_html(templatedir));
index.get()->output_to_html (templatedir, filepath);
- // create index for children
+ // recursively create index for children
for (DocumentTree tree : this->children)
tree.create_tree_html (templatedir, destdir);
}
}
void add_sidebar_item (SideBarItem item) {
- items.insert (items.cend(), item);
+ this->items.insert (this->items.cend(), item);
}
// render the sidebar using the template directory specified
sidetpl.close ();
std::string listitem;
// first get the sidebar items and render them to HTML
- for (SideBarItem item : items) {
+ for (SideBarItem item : this->items) {
listitem += item.to_html (templatedir);
}
#define __BIAWEBSTRINGS__
namespace biaweb {
+ // COMMON STRINGS
const char* GO_UP = "Go up";
const char* SUB_CAT = "Sub categories: ";
const char* ART_LIST = "List of Articles";
const char* INDEX = "Index Page";
+ // DATE FORMAT
+ const char* DATE_FORMAT = "%d %b %Y, %H:%M";
}
#endif
--- /dev/null
+<h2>%s</h2>
+<table style="width:100%;" >
+ <thead style="font-weight:bold;">
+ <tr>
+ <td style="width:50%">Document title</td>
+ <td>Created on</td>
+ <td>Last modified</td>
+ </tr>
+ </thead>
+ <tbody>
+ %s
+ </tbody>
+</table>
\ No newline at end of file
--- /dev/null
+<tr>
+ <td><a href="%s">%s</a></td>
+ <td>%s</td>
+ <td>%s</td>
+</tr>
\ No newline at end of file
<html lang="en">
<head>
<title>My Site - %s</title>
+<meta name="keywords" content="%s">
+<meta name="description" content="%s">
<!-- change base href to your site URL -->
<base href="http://my.site">
<style>
color: white;
background-color:#a1a0c0;
height: 50px;
+ float: left;
}
div#modification {
width: 100%;
color: darkslateblue;
font-size: 0.9em;
+ float:left;
}
div#footer {
width: 100%;
text-align: center;
background-color: #a1a0c0;
color: white;
- float:inline-end;
+ float:left;
}
div#sidebar {
- float :inline-end;
+ float :right;
background-color: darkslateblue;
color: white;
- width: 32%;
+ width: 30%;
padding: 1%;
}
div#sidebar a, div#sidebar a:visited {
color: white;
}
- div#main {
- width: 100%;
- float: none;
- color: black;
- }
+
div#content {
width: 63%;
margin-right:1%;
- margin-left: 2%;
- float:inline-start;
+ margin-left: 1%;
+ float: left;
}
</style>
</head>
<body>
-<div id="main">
<div id="header"></div>
<div id="content">
<div id="modification">Created on: %s, last modified: %s</div>
<div id ="footer">
My copyright
</div>
-</div>
</body>
</html>