177 |
02 Sep 06 |
peter |
// $Id$ |
177 |
02 Sep 06 |
peter |
2 |
|
177 |
02 Sep 06 |
peter |
3 |
/* |
408 |
29 Jun 07 |
jari |
Copyright (C) 2006 Peter Johansson |
978 |
12 Dec 09 |
peter |
Copyright (C) 2007, 2008 Jari Häkkinen, Peter Johansson |
1515 |
26 Sep 12 |
peter |
Copyright (C) 2009, 2010, 2011, 2012 Peter Johansson |
177 |
02 Sep 06 |
peter |
7 |
|
687 |
04 Aug 08 |
peter |
This file is part of svndigest, http://dev.thep.lu.se/svndigest |
177 |
02 Sep 06 |
peter |
9 |
|
177 |
02 Sep 06 |
peter |
svndigest is free software; you can redistribute it and/or modify it |
177 |
02 Sep 06 |
peter |
under the terms of the GNU General Public License as published by |
693 |
11 Sep 08 |
jari |
the Free Software Foundation; either version 3 of the License, or |
177 |
02 Sep 06 |
peter |
(at your option) any later version. |
177 |
02 Sep 06 |
peter |
14 |
|
177 |
02 Sep 06 |
peter |
svndigest is distributed in the hope that it will be useful, but |
177 |
02 Sep 06 |
peter |
WITHOUT ANY WARRANTY; without even the implied warranty of |
177 |
02 Sep 06 |
peter |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
177 |
02 Sep 06 |
peter |
General Public License for more details. |
177 |
02 Sep 06 |
peter |
19 |
|
177 |
02 Sep 06 |
peter |
You should have received a copy of the GNU General Public License |
693 |
11 Sep 08 |
jari |
along with svndigest. If not, see <http://www.gnu.org/licenses/>. |
177 |
02 Sep 06 |
peter |
22 |
*/ |
177 |
02 Sep 06 |
peter |
23 |
|
750 |
12 Jan 09 |
peter |
24 |
#include <config.h> |
750 |
12 Jan 09 |
peter |
25 |
|
201 |
09 Sep 06 |
peter |
26 |
#include "html_utility.h" |
234 |
09 Apr 07 |
peter |
27 |
|
274 |
02 May 07 |
peter |
28 |
#include "Configuration.h" |
235 |
21 Apr 07 |
peter |
29 |
#include "Date.h" |
234 |
09 Apr 07 |
peter |
30 |
#include "HtmlStream.h" |
1337 |
12 Feb 11 |
peter |
31 |
#include "subversion_revision.h" |
177 |
02 Sep 06 |
peter |
32 |
|
1006 |
03 Jan 10 |
peter |
33 |
#include <cassert> |
177 |
02 Sep 06 |
peter |
34 |
#include <sstream> |
177 |
02 Sep 06 |
peter |
35 |
#include <string> |
177 |
02 Sep 06 |
peter |
36 |
|
177 |
02 Sep 06 |
peter |
37 |
namespace theplu{ |
177 |
02 Sep 06 |
peter |
38 |
namespace svndigest{ |
177 |
02 Sep 06 |
peter |
39 |
|
376 |
20 Jun 07 |
jari |
40 |
std::string anchor(const std::string& url, |
1513 |
23 Sep 12 |
peter |
41 |
const std::string& name, unsigned int level, |
498 |
14 Oct 07 |
peter |
42 |
const std::string& title, |
498 |
14 Oct 07 |
peter |
43 |
const std::string& color) |
177 |
02 Sep 06 |
peter |
44 |
{ |
235 |
21 Apr 07 |
peter |
45 |
std::stringstream ss; |
235 |
21 Apr 07 |
peter |
46 |
HtmlStream hs(ss); |
235 |
21 Apr 07 |
peter |
47 |
ss << "<a title=\""; |
1513 |
23 Sep 12 |
peter |
48 |
hs << title; |
235 |
21 Apr 07 |
peter |
49 |
ss << "\" href=\""; |
177 |
02 Sep 06 |
peter |
50 |
for (size_t i=0; i<level; ++i) |
235 |
21 Apr 07 |
peter |
51 |
ss << "../"; |
1513 |
23 Sep 12 |
peter |
52 |
ss << url; |
1513 |
23 Sep 12 |
peter |
53 |
ss << "\">"; |
498 |
14 Oct 07 |
peter |
54 |
if (color.size()) |
498 |
14 Oct 07 |
peter |
55 |
ss << "<font color=\"" << color << "\">"; |
1513 |
23 Sep 12 |
peter |
56 |
hs << name; |
498 |
14 Oct 07 |
peter |
57 |
if (color.size()) |
498 |
14 Oct 07 |
peter |
58 |
ss << "</font>"; |
235 |
21 Apr 07 |
peter |
59 |
ss << "</a>"; |
235 |
21 Apr 07 |
peter |
60 |
return ss.str(); |
177 |
02 Sep 06 |
peter |
61 |
} |
177 |
02 Sep 06 |
peter |
62 |
|
1513 |
23 Sep 12 |
peter |
63 |
|
1024 |
10 Jan 10 |
peter |
64 |
std::string image(const std::string& name) |
1005 |
03 Jan 10 |
peter |
65 |
{ |
1005 |
03 Jan 10 |
peter |
66 |
std::ostringstream os; |
1024 |
10 Jan 10 |
peter |
67 |
const std::string& format = Configuration::instance().image_format(); |
1513 |
23 Sep 12 |
peter |
68 |
const std::string& anchor_format = |
1025 |
11 Jan 10 |
peter |
69 |
Configuration::instance().image_anchor_format(); |
1099 |
13 Jun 10 |
peter |
70 |
if (format=="svg") { |
1007 |
03 Jan 10 |
peter |
71 |
os << "<object data='" << name << ".svg' type='image/svg+xml'" |
1007 |
03 Jan 10 |
peter |
72 |
<< " width='600'>\n" |
1007 |
03 Jan 10 |
peter |
73 |
<< "<embed src='" << name << ".svg' type='image/svg+xml'" |
1007 |
03 Jan 10 |
peter |
74 |
<< " width='600' />\n" |
1005 |
03 Jan 10 |
peter |
75 |
<< "</object>\n"; |
1099 |
13 Jun 10 |
peter |
76 |
if (anchor_format != "svg") |
1099 |
13 Jun 10 |
peter |
77 |
std::cerr << "svndigest: anchor_format: " << anchor_format |
1099 |
13 Jun 10 |
peter |
78 |
<< " not supported with format " << format << "\n"; |
1099 |
13 Jun 10 |
peter |
79 |
} |
1025 |
11 Jan 10 |
peter |
80 |
else if (format=="png") { |
1025 |
11 Jan 10 |
peter |
81 |
if (anchor_format=="none") |
1025 |
11 Jan 10 |
peter |
82 |
os << "<img src='" << name << ".png' alt='[plot]'/>"; |
1025 |
11 Jan 10 |
peter |
83 |
else |
1513 |
23 Sep 12 |
peter |
84 |
os << "<a href=\"" << name << "." << anchor_format << "\">" |
1025 |
11 Jan 10 |
peter |
85 |
<< "<img src='" << name << ".png' alt='[plot]'/>" |
1025 |
11 Jan 10 |
peter |
86 |
<< "</a>"; |
1025 |
11 Jan 10 |
peter |
87 |
} |
1008 |
03 Jan 10 |
peter |
88 |
else if (format=="none") |
1008 |
03 Jan 10 |
peter |
89 |
os << "<!-- no images -->"; |
1005 |
03 Jan 10 |
peter |
90 |
else { |
1005 |
03 Jan 10 |
peter |
91 |
assert(false); |
1005 |
03 Jan 10 |
peter |
92 |
throw std::runtime_error("unknown image format: " + format); |
1005 |
03 Jan 10 |
peter |
93 |
} |
1005 |
03 Jan 10 |
peter |
94 |
return os.str(); |
1005 |
03 Jan 10 |
peter |
95 |
} |
1005 |
03 Jan 10 |
peter |
96 |
|
1005 |
03 Jan 10 |
peter |
97 |
|
200 |
09 Sep 06 |
peter |
98 |
void print_footer(std::ostream& os) |
200 |
09 Sep 06 |
peter |
99 |
{ |
235 |
21 Apr 07 |
peter |
100 |
Date date; |
751 |
14 Jan 09 |
peter |
101 |
HtmlStream hs(os); |
751 |
14 Jan 09 |
peter |
102 |
os << "<p class=\"footer\">\nGenerated on "; |
751 |
14 Jan 09 |
peter |
103 |
hs << date("%a %b %e %H:%M:%S %Y") << " (UTC) by "; |
892 |
26 Nov 09 |
peter |
104 |
os << anchor(PACKAGE_URL, PACKAGE_STRING, 0, ""); |
630 |
25 Apr 08 |
peter |
105 |
if (DEV_BUILD) |
733 |
15 Dec 08 |
peter |
106 |
os << " (dev build " << svn_revision() << ")"; |
550 |
07 Jan 08 |
peter |
107 |
os << "\n</p>\n</div>\n</body>\n</html>\n"; |
200 |
09 Sep 06 |
peter |
108 |
} |
200 |
09 Sep 06 |
peter |
109 |
|
200 |
09 Sep 06 |
peter |
110 |
|
589 |
12 Apr 08 |
jari |
111 |
void print_header(std::ostream& os, std::string title, unsigned int level, |
546 |
04 Jan 08 |
peter |
112 |
std::string user, std::string item, std::string path, |
1537 |
07 Oct 12 |
peter |
113 |
const std::string& stats, svn_revnum_t rev) |
199 |
09 Sep 06 |
peter |
114 |
{ |
1537 |
07 Oct 12 |
peter |
115 |
print_html_start(os, title, level, rev); |
750 |
12 Jan 09 |
peter |
116 |
os << "<div id=\"menu\">" |
546 |
04 Jan 08 |
peter |
117 |
<< "<ul>\n<li></li>\n"; |
212 |
15 Sep 06 |
peter |
118 |
if (item=="main") |
212 |
15 Sep 06 |
peter |
119 |
os << "<li class=\"highlight\">"; |
212 |
15 Sep 06 |
peter |
120 |
else |
212 |
15 Sep 06 |
peter |
121 |
os << "<li>"; |
235 |
21 Apr 07 |
peter |
122 |
os << anchor("index.html", "Main", level, "Main page"); |
546 |
04 Jan 08 |
peter |
123 |
os << "</li>\n"; |
212 |
15 Sep 06 |
peter |
124 |
|
546 |
04 Jan 08 |
peter |
125 |
std::string stats_local(stats); |
546 |
04 Jan 08 |
peter |
126 |
if (stats_local=="none") |
546 |
04 Jan 08 |
peter |
127 |
stats_local = "classic"; |
546 |
04 Jan 08 |
peter |
128 |
|
212 |
15 Sep 06 |
peter |
129 |
if (item=="total") |
212 |
15 Sep 06 |
peter |
130 |
os << "<li class=\"highlight\">"; |
212 |
15 Sep 06 |
peter |
131 |
else |
546 |
04 Jan 08 |
peter |
132 |
os << "<li>\n"; |
1513 |
23 Sep 12 |
peter |
133 |
os << anchor(stats_local+"/"+user+"/total/"+path, "Total", level, |
209 |
12 Sep 06 |
peter |
134 |
"View statistics of all lines"); |
546 |
04 Jan 08 |
peter |
135 |
os << "</li>\n"; |
212 |
15 Sep 06 |
peter |
136 |
|
212 |
15 Sep 06 |
peter |
137 |
if (item=="code") |
212 |
15 Sep 06 |
peter |
138 |
os << "<li class=\"highlight\">"; |
212 |
15 Sep 06 |
peter |
139 |
else |
212 |
15 Sep 06 |
peter |
140 |
os << "<li>"; |
1513 |
23 Sep 12 |
peter |
141 |
os << anchor(stats_local+"/"+user+"/code/"+path, "Code", level, |
235 |
21 Apr 07 |
peter |
142 |
"View statistics of code lines"); |
546 |
04 Jan 08 |
peter |
143 |
os << "</li>\n"; |
212 |
15 Sep 06 |
peter |
144 |
|
212 |
15 Sep 06 |
peter |
145 |
if (item=="comments") |
212 |
15 Sep 06 |
peter |
146 |
os << "<li class=\"highlight\">"; |
212 |
15 Sep 06 |
peter |
147 |
else |
212 |
15 Sep 06 |
peter |
148 |
os << "<li>"; |
1513 |
23 Sep 12 |
peter |
149 |
os << anchor(stats_local+"/"+user+"/comments/"+path, "Comment", level, |
235 |
21 Apr 07 |
peter |
150 |
"View statistics of comment lines"); |
546 |
04 Jan 08 |
peter |
151 |
os << "</li>\n"; |
212 |
15 Sep 06 |
peter |
152 |
|
212 |
15 Sep 06 |
peter |
153 |
|
212 |
15 Sep 06 |
peter |
154 |
if (item=="empty") |
212 |
15 Sep 06 |
peter |
155 |
os << "<li class=\"highlight\">"; |
212 |
15 Sep 06 |
peter |
156 |
else |
212 |
15 Sep 06 |
peter |
157 |
os << "<li>"; |
1513 |
23 Sep 12 |
peter |
158 |
os << anchor(stats_local+"/"+user+"/empty/"+path, "Other", level, |
462 |
21 Aug 07 |
jari |
159 |
"View statistics of other lines"); |
546 |
04 Jan 08 |
peter |
160 |
os << "</li>\n"; |
546 |
04 Jan 08 |
peter |
161 |
os << "<li>"; |
546 |
04 Jan 08 |
peter |
// Peter, this is ugly! But how to add space? |
546 |
04 Jan 08 |
peter |
163 |
for (size_t i=0; i<50; ++i) |
546 |
04 Jan 08 |
peter |
164 |
os << " "; |
546 |
04 Jan 08 |
peter |
165 |
os << "</li>\n"; |
546 |
04 Jan 08 |
peter |
166 |
|
546 |
04 Jan 08 |
peter |
167 |
std::string item_local(item); |
546 |
04 Jan 08 |
peter |
168 |
if (item_local=="none") |
546 |
04 Jan 08 |
peter |
169 |
item_local = "total"; |
556 |
16 Jan 08 |
peter |
170 |
if (item_local=="main") |
556 |
16 Jan 08 |
peter |
171 |
item_local = "total"; |
546 |
04 Jan 08 |
peter |
172 |
|
546 |
04 Jan 08 |
peter |
173 |
if (stats=="classic") |
546 |
04 Jan 08 |
peter |
174 |
os << "<li class=\"highlight\">"; |
546 |
04 Jan 08 |
peter |
175 |
else |
546 |
04 Jan 08 |
peter |
176 |
os << "<li>"; |
1513 |
23 Sep 12 |
peter |
177 |
os << anchor("classic/"+user+"/"+item_local+"/"+path, "Classic", level, |
546 |
04 Jan 08 |
peter |
178 |
"View classic statistics"); |
546 |
04 Jan 08 |
peter |
179 |
os << "</li>\n"; |
546 |
04 Jan 08 |
peter |
180 |
|
546 |
04 Jan 08 |
peter |
181 |
if (stats=="blame") |
546 |
04 Jan 08 |
peter |
182 |
os << "<li class=\"highlight\">"; |
546 |
04 Jan 08 |
peter |
183 |
else |
546 |
04 Jan 08 |
peter |
184 |
os << "<li>"; |
1513 |
23 Sep 12 |
peter |
185 |
os << anchor("blame/"+user+"/"+item_local+"/"+path, "Blame", level, |
546 |
04 Jan 08 |
peter |
186 |
"View blame statistics"); |
546 |
04 Jan 08 |
peter |
187 |
os << "</li>\n"; |
546 |
04 Jan 08 |
peter |
188 |
|
546 |
04 Jan 08 |
peter |
189 |
if (stats=="add") |
546 |
04 Jan 08 |
peter |
190 |
os << "<li class=\"highlight\">"; |
546 |
04 Jan 08 |
peter |
191 |
else |
546 |
04 Jan 08 |
peter |
192 |
os << "<li>"; |
1513 |
23 Sep 12 |
peter |
193 |
os << anchor("add/"+user+"/"+item_local+"/"+path, "Add", level, |
546 |
04 Jan 08 |
peter |
194 |
"View add statistics"); |
546 |
04 Jan 08 |
peter |
195 |
os << "</li>\n"; |
546 |
04 Jan 08 |
peter |
196 |
|
546 |
04 Jan 08 |
peter |
197 |
|
546 |
04 Jan 08 |
peter |
198 |
os << "</li>\n" |
546 |
04 Jan 08 |
peter |
199 |
<< "</ul></div>\n" |
199 |
09 Sep 06 |
peter |
200 |
<< "<div id=\"main\">\n"; |
199 |
09 Sep 06 |
peter |
201 |
} |
199 |
09 Sep 06 |
peter |
202 |
|
199 |
09 Sep 06 |
peter |
203 |
|
1513 |
23 Sep 12 |
peter |
204 |
void print_html_start(std::ostream& os, const std::string& title, |
1537 |
07 Oct 12 |
peter |
205 |
unsigned int level, svn_revnum_t rev) |
750 |
12 Jan 09 |
peter |
206 |
{ |
750 |
12 Jan 09 |
peter |
207 |
os << "<!-- Generated by " << PACKAGE_STRING << "-->\n"; |
1537 |
07 Oct 12 |
peter |
208 |
if (rev) |
1537 |
07 Oct 12 |
peter |
209 |
os << "<!-- revision: " << rev << " -->\n"; |
750 |
12 Jan 09 |
peter |
210 |
os << "<!DOCTYPE html\n" |
750 |
12 Jan 09 |
peter |
211 |
<< "PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"\n" |
750 |
12 Jan 09 |
peter |
212 |
<< "\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n" |
750 |
12 Jan 09 |
peter |
213 |
<< "<html xmlns=\"http://www.w3.org/1999/xhtml\"" |
750 |
12 Jan 09 |
peter |
214 |
<< " xml:lang=\"en\" lang=\"en\">\n" |
750 |
12 Jan 09 |
peter |
215 |
<< "<head>\n" |
750 |
12 Jan 09 |
peter |
216 |
<< "<title> " << title << " - svndigest</title>\n" |
991 |
16 Dec 09 |
peter |
217 |
<< "<meta http-equiv=\"Content-type\" content=\"text/html; " |
1513 |
23 Sep 12 |
peter |
218 |
<< "charset=UTF-8\" />\n" |
750 |
12 Jan 09 |
peter |
219 |
<< "<link rel=\"stylesheet\" " |
750 |
12 Jan 09 |
peter |
220 |
<< "href=\""; |
750 |
12 Jan 09 |
peter |
221 |
for (unsigned int i=0; i<level; ++i) |
750 |
12 Jan 09 |
peter |
222 |
os << "../"; |
750 |
12 Jan 09 |
peter |
223 |
os << "svndigest.css\" type=\"text/css\" />\n" |
750 |
12 Jan 09 |
peter |
224 |
<< "</head>\n" |
750 |
12 Jan 09 |
peter |
225 |
<< "<body>\n"; |
750 |
12 Jan 09 |
peter |
226 |
} |
750 |
12 Jan 09 |
peter |
227 |
|
716 |
30 Nov 08 |
peter |
228 |
std::string trac_revision(svn_revnum_t r, std::string color) |
274 |
02 May 07 |
peter |
229 |
{ |
289 |
08 May 07 |
peter |
230 |
const Configuration& conf = Configuration::instance(); |
274 |
02 May 07 |
peter |
231 |
std::stringstream ss; |
289 |
08 May 07 |
peter |
232 |
if (conf.trac_root().empty()) |
1513 |
23 Sep 12 |
peter |
233 |
ss << r; |
274 |
02 May 07 |
peter |
234 |
else { |
274 |
02 May 07 |
peter |
235 |
std::stringstream rev; |
274 |
02 May 07 |
peter |
236 |
rev << r; |
498 |
14 Oct 07 |
peter |
237 |
ss << anchor(conf.trac_root()+"changeset/"+rev.str(), rev.str(), |
716 |
30 Nov 08 |
peter |
238 |
0, "View ChangeSet "+rev.str(), color); |
274 |
02 May 07 |
peter |
239 |
} |
274 |
02 May 07 |
peter |
240 |
return ss.str(); |
274 |
02 May 07 |
peter |
241 |
} |
274 |
02 May 07 |
peter |
242 |
|
177 |
02 Sep 06 |
peter |
243 |
}} // end of namespace svndigest and namespace theplu |