00001
00002
00003 #pragma once
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include <sstream>
00028
00029 namespace mongoutils {
00030
00031 namespace html {
00032
00033 using namespace std;
00034
00035 inline string _end() { return "</body></html>"; }
00036 inline string _table() { return "</table>\n\n"; }
00037 inline string _tr() { return "</tr>\n"; }
00038
00039 inline string tr() { return "<tr>"; }
00040 inline string tr(string a, string b) {
00041 stringstream ss;
00042 ss << "<tr><td>" << a << "</td><td>" << b << "</td></tr>\n";
00043 return ss.str();
00044 }
00045 template <class T>
00046 inline string td(T x) {
00047 stringstream ss;
00048 ss << "<td>" << x << "</td>";
00049 return ss.str();
00050 }
00051 inline string td(string x) {
00052 return "<td>" + x + "</td>";
00053 }
00054 inline string th(string x) {
00055 return "<th>" + x + "</th>";
00056 }
00057
00058 inline void tablecell( stringstream& ss , bool b ) {
00059 ss << "<td>" << (b ? "<b>X</b>" : "") << "</td>";
00060 }
00061
00062 template< typename T>
00063 inline void tablecell( stringstream& ss , const T& t ) {
00064 ss << "<td>" << t << "</td>";
00065 }
00066
00067 inline string table(const char *headers[] = 0, bool border = true) {
00068 stringstream ss;
00069 ss << "\n<table "
00070 << (border?"border=1 ":"")
00071 << "cellpadding=2 cellspacing=0>\n";
00072 if( headers ) {
00073 ss << "<tr>";
00074 while( *headers ) {
00075 ss << "<th>" << *headers << "</th>";
00076 headers++;
00077 }
00078 ss << "</tr>\n";
00079 }
00080 return ss.str();
00081 }
00082
00083 inline string start(string title) {
00084 stringstream ss;
00085 ss << "<html><head>\n<title>";
00086 ss << title;
00087 ss << "</title>\n";
00088
00089 ss << "<style type=\"text/css\" media=\"screen\">"
00090 "body { font-family: helvetica, arial, san-serif }\n"
00091 "table { border-collapse:collapse; border-color:#999; margin-top:.5em }\n"
00092 "th { background-color:#bbb; color:#000 }\n"
00093 "td,th { padding:.25em }\n"
00094 "</style>\n";
00095
00096 ss << "</head>\n<body>\n";
00097 return ss.str();
00098 }
00099
00100 inline string red(string contentHtml, bool color=true) {
00101 if( !color ) return contentHtml;
00102 stringstream ss;
00103 ss << "<span style=\"color:#A00;\">" << contentHtml << "</span>";
00104 return ss.str();
00105 }
00106 inline string grey(string contentHtml, bool color=true) {
00107 if( !color ) return contentHtml;
00108 stringstream ss;
00109 ss << "<span style=\"color:#888;\">" << contentHtml << "</span>";
00110 return ss.str();
00111 }
00112 inline string blue(string contentHtml, bool color=true) {
00113 if( !color ) return contentHtml;
00114 stringstream ss;
00115 ss << "<span style=\"color:#00A;\">" << contentHtml << "</span>";
00116 return ss.str();
00117 }
00118 inline string yellow(string contentHtml, bool color=true) {
00119 if( !color ) return contentHtml;
00120 stringstream ss;
00121 ss << "<span style=\"color:#A80;\">" << contentHtml << "</span>";
00122 return ss.str();
00123 }
00124 inline string green(string contentHtml, bool color=true) {
00125 if( !color ) return contentHtml;
00126 stringstream ss;
00127 ss << "<span style=\"color:#0A0;\">" << contentHtml << "</span>";
00128 return ss.str();
00129 }
00130
00131 inline string p(string contentHtml) {
00132 stringstream ss;
00133 ss << "<p>" << contentHtml << "</p>\n";
00134 return ss.str();
00135 }
00136
00137 inline string h2(string contentHtml) {
00138 stringstream ss;
00139 ss << "<h2>" << contentHtml << "</h2>\n";
00140 return ss.str();
00141 }
00142
00143
00144 inline string a(string href, string title="", string contentHtml = "") {
00145 stringstream ss;
00146 ss << "<a";
00147 if( !href.empty() ) ss << " href=\"" << href << '"';
00148 if( !title.empty() ) ss << " title=\"" << title << '"';
00149 ss << '>';
00150 if( !contentHtml.empty() ) {
00151 ss << contentHtml << "</a>";
00152 }
00153 return ss.str();
00154 }
00155
00156 }
00157
00158 }