source: trunk/lib/html_utility.cc @ 716

Last change on this file since 716 was 716, checked in by Peter Johansson, 13 years ago

refs #304 - revert Changeset [714]

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 5.1 KB
Line 
1// $Id: html_utility.cc 716 2008-11-30 15:43:14Z peter $
2
3/*
4  Copyright (C) 2006 Peter Johansson
5  Copyright (C) 2007 Jari Häkkinen, Peter Johansson
6
7  This file is part of svndigest, http://dev.thep.lu.se/svndigest
8
9  svndigest is free software; you can redistribute it and/or modify it
10  under the terms of the GNU General Public License as published by
11  the Free Software Foundation; either version 3 of the License, or
12  (at your option) any later version.
13
14  svndigest is distributed in the hope that it will be useful, but
15  WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  General Public License for more details.
18
19  You should have received a copy of the GNU General Public License
20  along with svndigest. If not, see <http://www.gnu.org/licenses/>.
21*/
22
23#include "html_utility.h"
24
25#include "config.h"
26#include "Configuration.h"
27#include "Date.h"
28#include "HtmlStream.h"
29#include "subversion_info.h"
30#include <config.h> // this header file is created by configure
31
32#include <sstream>
33#include <string>
34
35namespace theplu{
36namespace svndigest{
37
38  std::string anchor(const std::string& url,
39                     const std::string& name, unsigned int level, 
40                     const std::string& title,
41                     const std::string& color)
42  {
43    std::stringstream ss;
44    HtmlStream hs(ss);
45    ss << "<a title=\"";
46    hs << title; 
47    ss << "\" href=\"";
48    for (size_t i=0; i<level; ++i)
49      ss << "../";
50    ss << url; 
51    ss << "\">"; 
52    if (color.size())
53      ss << "<font color=\"" << color << "\">";
54    hs << name; 
55    if (color.size())
56      ss << "</font>";
57    ss << "</a>";
58    return ss.str();
59  }
60
61 
62  void print_footer(std::ostream& os)
63  {
64    Date date;
65    os << "<p class=\"footer\">\nGenerated on "
66       << date("%a %b %d %H:%M:%S %Y") << " (UTC) by "
67       << anchor("http://dev.thep.lu.se/svndigest/", 
68                 PACKAGE_STRING, 0, "");
69    if (DEV_BUILD)
70      os << " (dev build r" << svn_revision() << ")";
71    os << "\n</p>\n</div>\n</body>\n</html>\n";
72  }
73
74
75  void print_header(std::ostream& os, std::string title, unsigned int level,
76                    std::string user, std::string item, std::string path,
77                    const std::string& stats)
78  {
79    os << "<!-- Generated by " << PACKAGE_STRING << "-->\n";
80    os << "<!DOCTYPE html\n"
81       << "PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"\n"
82       << "\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n"
83       << "<html xmlns=\"http://www.w3.org/1999/xhtml\""
84       << " xml:lang=\"en\" lang=\"en\">\n"
85       << "<head>\n"
86       << "<title> " << title << " - svndigest</title>\n"
87       << "<link rel=\"stylesheet\" "
88       << "href=\"";
89    for (unsigned int i=0; i<level; ++i)
90      os << "../";
91    os << "svndigest.css\" type=\"text/css\" />\n"
92       << "</head>\n"
93       << "<body>\n"
94       << "<div id=\"menu\">"
95       << "<ul>\n<li></li>\n";
96    if (item=="main")
97      os << "<li class=\"highlight\">";
98    else
99      os << "<li>";
100    os << anchor("index.html", "Main", level, "Main page");
101    os << "</li>\n";
102
103    std::string stats_local(stats);
104    if (stats_local=="none")
105      stats_local = "classic";
106
107    if (item=="total")
108      os << "<li class=\"highlight\">";
109    else
110      os << "<li>\n";
111    os << anchor(stats_local+"/"+user+"/total/"+path, "Total", level, 
112           "View statistics of all lines");
113    os << "</li>\n";
114
115    if (item=="code")
116      os << "<li class=\"highlight\">";
117    else
118      os << "<li>";
119    os << anchor(stats_local+"/"+user+"/code/"+path, "Code", level, 
120                 "View statistics of code lines");
121    os << "</li>\n";
122
123    if (item=="comments")
124      os << "<li class=\"highlight\">";
125    else
126      os << "<li>";
127    os << anchor(stats_local+"/"+user+"/comments/"+path, "Comment", level, 
128                 "View statistics of comment lines");
129    os << "</li>\n";
130
131
132    if (item=="empty")
133      os << "<li class=\"highlight\">";
134    else
135      os << "<li>";
136    os << anchor(stats_local+"/"+user+"/empty/"+path, "Other", level, 
137                 "View statistics of other lines");
138    os << "</li>\n";
139    os << "<li>";
140    // Peter, this is ugly! But how to add space?
141    for (size_t i=0; i<50; ++i)
142      os << "&nbsp;";
143    os << "</li>\n";
144
145    std::string item_local(item);
146    if (item_local=="none")
147      item_local = "total";
148    if (item_local=="main")
149      item_local = "total";
150
151    if (stats=="classic")
152      os << "<li class=\"highlight\">";
153    else
154      os << "<li>";
155    os << anchor("classic/"+user+"/"+item_local+"/"+path, "Classic", level, 
156                 "View classic statistics");
157    os << "</li>\n";
158
159    if (stats=="blame")
160      os << "<li class=\"highlight\">";
161    else
162      os << "<li>";
163    os << anchor("blame/"+user+"/"+item_local+"/"+path, "Blame", level, 
164                 "View blame statistics");
165    os << "</li>\n";
166
167    if (stats=="add")
168      os << "<li class=\"highlight\">";
169    else
170      os << "<li>";
171    os << anchor("add/"+user+"/"+item_local+"/"+path, "Add", level, 
172                 "View add statistics");
173    os << "</li>\n";
174
175
176    os << "</li>\n"
177       << "</ul></div>\n"
178       << "<div id=\"main\">\n";
179  }
180
181
182  std::string trac_revision(svn_revnum_t r, std::string color)
183  {
184    const Configuration& conf = Configuration::instance();
185    std::stringstream ss;
186    if (conf.trac_root().empty())
187      ss << r; 
188    else {
189      std::stringstream rev;
190      rev << r;
191      ss << anchor(conf.trac_root()+"changeset/"+rev.str(), rev.str(),
192                   0, "View ChangeSet "+rev.str(), color);
193    }
194    return ss.str();
195  }
196
197}} // end of namespace svndigest and namespace theplu
Note: See TracBrowser for help on using the repository browser.