1 | // $Id: html_utility.cc 289 2007-05-08 12:48:07Z peter $ |
---|
2 | |
---|
3 | /* |
---|
4 | Copyright (C) 2006, 2007 Peter Johansson |
---|
5 | |
---|
6 | This file is part of svndigest, http://lev.thep.lu.se/trac/svndigest |
---|
7 | |
---|
8 | svndigest is free software; you can redistribute it and/or modify it |
---|
9 | under the terms of the GNU General Public License as published by |
---|
10 | the Free Software Foundation; either version 2 of the License, or |
---|
11 | (at your option) any later version. |
---|
12 | |
---|
13 | svndigest is distributed in the hope that it will be useful, but |
---|
14 | WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
16 | General Public License for more details. |
---|
17 | |
---|
18 | You should have received a copy of the GNU General Public License |
---|
19 | along with this program; if not, write to the Free Software |
---|
20 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA |
---|
21 | 02111-1307, USA. |
---|
22 | */ |
---|
23 | |
---|
24 | #include "html_utility.h" |
---|
25 | |
---|
26 | #include "Configuration.h" |
---|
27 | #include "Date.h" |
---|
28 | #include "HtmlStream.h" |
---|
29 | #include <config.h> // this header file is created by configure |
---|
30 | |
---|
31 | #include <sstream> |
---|
32 | #include <string> |
---|
33 | |
---|
34 | namespace theplu{ |
---|
35 | namespace svndigest{ |
---|
36 | |
---|
37 | std::string anchor(const std::string& href, |
---|
38 | const std::string& name, u_int level, |
---|
39 | const std::string& title) |
---|
40 | { |
---|
41 | std::stringstream ss; |
---|
42 | HtmlStream hs(ss); |
---|
43 | ss << "<a title=\""; |
---|
44 | hs << title; |
---|
45 | ss << "\" href=\""; |
---|
46 | for (size_t i=0; i<level; ++i) |
---|
47 | ss << "../"; |
---|
48 | hs << href; |
---|
49 | ss << "\">"; |
---|
50 | hs << name; |
---|
51 | ss << "</a>"; |
---|
52 | return ss.str(); |
---|
53 | } |
---|
54 | |
---|
55 | |
---|
56 | void print_footer(std::ostream& os) |
---|
57 | { |
---|
58 | Date date; |
---|
59 | os << "<p align=center><font size=-2>\nGenerated on " |
---|
60 | << date("%a %b %d %H:%M:%S %Y") << " (UTC) by " |
---|
61 | << anchor("http://lev.thep.lu.se/trac/svndigest/", |
---|
62 | PACKAGE_STRING, 0, "") |
---|
63 | << "</font>\n</p>\n</div>\n</body>\n</html>\n"; |
---|
64 | } |
---|
65 | |
---|
66 | |
---|
67 | void print_header(std::ostream& os, std::string title, u_int level, |
---|
68 | std::string user, std::string item, std::string path) |
---|
69 | { |
---|
70 | os << "<!DOCTYPE html\n" |
---|
71 | << "PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"\n" |
---|
72 | << "\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n" |
---|
73 | << "<html xmlns=\"http://www.w3.org/1999/xhtml\"" |
---|
74 | << " xml:lang=\"en\" lang=\"en\"><head>\n" |
---|
75 | << "<head>\n" |
---|
76 | << "<title> " << title << " - svndigest</title>\n" |
---|
77 | << "</head>\n" |
---|
78 | << "<link rel=\"stylesheet\" " |
---|
79 | << "href=\""; |
---|
80 | for (u_int i=0; i<level; ++i) |
---|
81 | os << "../"; |
---|
82 | os << "svndigest.css\" type=\"text/css\" />\n" |
---|
83 | << "<body>\n" |
---|
84 | << "<div id=\"menu\">" |
---|
85 | << "<ul><li></li>"; |
---|
86 | if (item=="main") |
---|
87 | os << "<li class=\"highlight\">"; |
---|
88 | else |
---|
89 | os << "<li>"; |
---|
90 | os << anchor("index.html", "Main", level, "Main page"); |
---|
91 | os << "</li>"; |
---|
92 | |
---|
93 | if (item=="total") |
---|
94 | os << "<li class=\"highlight\">"; |
---|
95 | else |
---|
96 | os << "<li>"; |
---|
97 | os << anchor(user+"/total/"+path, "Total", level, |
---|
98 | "View statistics of all lines"); |
---|
99 | os << "</li>"; |
---|
100 | |
---|
101 | if (item=="code") |
---|
102 | os << "<li class=\"highlight\">"; |
---|
103 | else |
---|
104 | os << "<li>"; |
---|
105 | os << anchor(user+"/code/"+path, "Code", level, |
---|
106 | "View statistics of code lines"); |
---|
107 | os << "</li>"; |
---|
108 | |
---|
109 | if (item=="comments") |
---|
110 | os << "<li class=\"highlight\">"; |
---|
111 | else |
---|
112 | os << "<li>"; |
---|
113 | os << anchor(user+"/comments/"+path, "Comment", level, |
---|
114 | "View statistics of comment lines"); |
---|
115 | os << "</li>"; |
---|
116 | |
---|
117 | |
---|
118 | if (item=="empty") |
---|
119 | os << "<li class=\"highlight\">"; |
---|
120 | else |
---|
121 | os << "<li>"; |
---|
122 | os << anchor(user+"/empty/"+path, "Other", level, |
---|
123 | "View statistics of empty lines"); |
---|
124 | os << "</li>" |
---|
125 | << "</ul></div>" |
---|
126 | << "<div id=\"main\">\n"; |
---|
127 | } |
---|
128 | |
---|
129 | |
---|
130 | std::string trac_revision(size_t r) |
---|
131 | { |
---|
132 | const Configuration& conf = Configuration::instance(); |
---|
133 | std::stringstream ss; |
---|
134 | if (conf.trac_root().empty()) |
---|
135 | ss << r; |
---|
136 | else { |
---|
137 | std::stringstream rev; |
---|
138 | rev << r; |
---|
139 | ss << anchor(conf.trac_root()+"changeset/"+rev.str(), rev.str()); |
---|
140 | } |
---|
141 | return ss.str(); |
---|
142 | } |
---|
143 | |
---|
144 | }} // end of namespace svndigest and namespace theplu |
---|