4
* Copyright (C) 2012 10gen Inc.
6
* This program is free software: you can redistribute it and/or modify
7
* it under the terms of the GNU Affero General Public License, version 3,
8
* as published by the Free Software Foundation.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU Affero General Public License for more details.
15
* You should have received a copy of the GNU Affero General Public License
16
* along with this program. If not, see <http://www.gnu.org/licenses/>.
5
21
/* Things in the mongoutils namespace
9
25
(4) are clean and easy to use in any c++ project without pulling in lots of other stuff
12
/* Copyright 2010 10gen Inc.
14
* Licensed under the Apache License, Version 2.0 (the "License");
15
* you may not use this file except in compliance with the License.
16
* You may obtain a copy of the License at
18
* http://www.apache.org/licenses/LICENSE-2.0
20
* Unless required by applicable law or agreed to in writing, software
21
* distributed under the License is distributed on an "AS IS" BASIS,
22
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
23
* See the License for the specific language governing permissions and
24
* limitations under the License.
29
30
namespace mongoutils {
37
38
inline string _tr() { return "</tr>\n"; }
39
40
inline string tr() { return "<tr>"; }
40
inline string tr(string a, string b) {
41
inline string tr(const std::string& a, const std::string& b) {
42
43
ss << "<tr><td>" << a << "</td><td>" << b << "</td></tr>\n";
48
49
ss << "<td>" << x << "</td>";
51
inline string td(string x) {
52
inline string td(const std::string& x) {
52
53
return "<td>" + x + "</td>";
54
inline string th(string x) {
55
inline string th(const std::string& x) {
55
56
return "<th>" + x + "</th>";
100
inline string red(string contentHtml, bool color=true) {
101
inline string red(const std::string& contentHtml, bool color=true) {
101
102
if( !color ) return contentHtml;
103
104
ss << "<span style=\"color:#A00;\">" << contentHtml << "</span>";
106
inline string grey(string contentHtml, bool color=true) {
107
inline string grey(const std::string& contentHtml, bool color=true) {
107
108
if( !color ) return contentHtml;
109
110
ss << "<span style=\"color:#888;\">" << contentHtml << "</span>";
112
inline string blue(string contentHtml, bool color=true) {
113
inline string blue(const std::string& contentHtml, bool color=true) {
113
114
if( !color ) return contentHtml;
115
116
ss << "<span style=\"color:#00A;\">" << contentHtml << "</span>";
118
inline string yellow(string contentHtml, bool color=true) {
119
inline string yellow(const std::string& contentHtml, bool color=true) {
119
120
if( !color ) return contentHtml;
121
122
ss << "<span style=\"color:#A80;\">" << contentHtml << "</span>";
124
inline string green(string contentHtml, bool color=true) {
125
inline string green(const std::string& contentHtml, bool color=true) {
125
126
if( !color ) return contentHtml;
127
128
ss << "<span style=\"color:#0A0;\">" << contentHtml << "</span>";
131
inline string p(string contentHtml) {
132
inline string p(const std::string& contentHtml) {
133
134
ss << "<p>" << contentHtml << "</p>\n";
137
inline string h2(string contentHtml) {
138
inline string h2(const std::string& contentHtml) {
139
140
ss << "<h2>" << contentHtml << "</h2>\n";
143
144
/* does NOT escape the strings. */
144
inline string a(string href, string title="", string contentHtml = "") {
145
inline string a(const std::string& href,
146
const std::string& title="",
147
const std::string& contentHtml = "") {
147
150
if( !href.empty() ) ss << " href=\"" << href << '"';