COOPY » Guide
version 0.6.5
|
00001 #ifndef COOPY_HTMLDIFFRENDER 00002 #define COOPY_HTMLDIFFRENDER 00003 00004 #include <coopy/DiffRender.h> 00005 00006 namespace coopy { 00007 namespace light { 00008 class HtmlDiffRender; 00009 } 00010 } 00011 00012 class coopy::light::HtmlDiffRender : public DiffRender { 00013 public: 00014 HtmlDiffRender() { 00015 open = false; 00016 } 00017 00018 virtual bool begin_table() { 00019 insert("<table class='csv_sheet'>\n"); 00020 return true; 00021 } 00022 00023 virtual bool begin_row(const std::string& mode) { 00024 td_open = "<td"; 00025 td_close = "</td>"; 00026 row_color = ""; 00027 open = false; 00028 if (mode=="@@") { 00029 td_open = "<th"; 00030 td_close = "</th>"; 00031 } else if (mode=="!") { 00032 row_color = "#aaaaaa"; 00033 } else if (mode=="+++") { 00034 row_color = "#7fff7f"; 00035 } else if (mode=="---") { 00036 row_color = "#ff7f7f"; 00037 } else { 00038 open = true; 00039 } 00040 std::string tr = "<tr>"; 00041 std::string row_decorate = ""; 00042 if (row_color!="") { 00043 row_decorate = " bgcolor=\"" + row_color + "\" style=\"background-color: " + row_color + ";\""; 00044 tr = "<tr" + row_decorate + ">"; 00045 } 00046 insert(tr); 00047 return true; 00048 } 00049 00050 00051 virtual bool insert_cell(const Cell& cell, 00052 const std::string& mode, 00053 const std::string& separator) { 00054 std::string cell_decorate = ""; 00055 if (mode=="+++") { 00056 cell_decorate += " bgcolor=\"#7fff7f\" style=\"background-color: #7fff7f;\""; 00057 } else if (mode=="---") { 00058 cell_decorate += " bgcolor=\"#ff7f7f\" style=\"background-color: #ff7f7f;\""; 00059 } else if (mode=="->") { 00060 cell_decorate += " bgcolor=\"#7f7fff\" style=\"background-color: #7f7fff;\""; 00061 } 00062 insert(td_open+cell_decorate+">"); 00063 insert(cell.is_null?"":cell.txt); 00064 insert(td_close); 00065 return true; 00066 } 00067 00068 virtual bool end_row() { 00069 insert("</tr>\n"); 00070 return true; 00071 } 00072 00073 virtual bool end_table() { 00074 insert("</table>\n"); 00075 return true; 00076 } 00077 00078 std::string html() const { 00079 return accum; 00080 } 00081 00082 virtual std::string to_string() const { 00083 return html(); 00084 } 00085 00086 private: 00087 00088 void insert(const std::string& txt) { 00089 accum += txt; 00090 } 00091 00092 std::string accum; 00093 std::string td_open, td_close, row_color; 00094 bool open; 00095 }; 00096 00097 #endif 00098