source: branches/replacing_gnuplot/lib/html_utility.cc @ 646

Last change on this file since 646 was 646, checked in by Jari Häkkinen, 13 years ago

Merged trunk changes r608:645 to replacing_gnuplot branch.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 5.2 KB
Line 
1// $Id: html_utility.cc 646 2008-06-03 22:05:22Z jari $
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://trac.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 2 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 this program; if not, write to the Free Software
21  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
22  02111-1307, USA.
23*/
24
25#include "html_utility.h"
26
27#include "config.h"
28#include "Configuration.h"
29#include "Date.h"
30#include "HtmlStream.h"
31#include "subversion_info.h"
32#include <config.h> // this header file is created by configure
33
34#include <sstream>
35#include <string>
36
37namespace theplu{
38namespace svndigest{
39
40  std::string anchor(const std::string& url,
41                     const std::string& name, unsigned int level, 
42                     const std::string& title,
43                     const std::string& color)
44  {
45    std::stringstream ss;
46    HtmlStream hs(ss);
47    ss << "<a title=\"";
48    hs << title; 
49    ss << "\" href=\"";
50    for (size_t i=0; i<level; ++i)
51      ss << "../";
52    ss << url; 
53    ss << "\">"; 
54    if (color.size())
55      ss << "<font color=\"" << color << "\">";
56    hs << name; 
57    if (color.size())
58      ss << "</font>";
59    ss << "</a>";
60    return ss.str();
61  }
62
63 
64  void print_footer(std::ostream& os)
65  {
66    Date date;
67    os << "<p class=\"footer\">\nGenerated on "
68       << date("%a %b %d %H:%M:%S %Y") << " (UTC) by "
69       << anchor("http://trac.thep.lu.se/svndigest/", 
70                 PACKAGE_STRING, 0, "");
71    if (DEV_BUILD)
72      os << " (dev build r" << svn_revision() << ")";
73    os << "\n</p>\n</div>\n</body>\n</html>\n";
74  }
75
76
77  void print_header(std::ostream& os, std::string title, unsigned int level,
78                    std::string user, std::string item, std::string path,
79                    const std::string& stats)
80  {
81    os << "<!-- Generated by " << PACKAGE_STRING << "-->\n";
82    os << "<!DOCTYPE html\n"
83       << "PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"\n"
84       << "\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n"
85       << "<html xmlns=\"http://www.w3.org/1999/xhtml\""
86       << " xml:lang=\"en\" lang=\"en\">\n"
87       << "<head>\n"
88       << "<title> " << title << " - svndigest</title>\n"
89       << "<link rel=\"stylesheet\" "
90       << "href=\"";
91    for (unsigned int i=0; i<level; ++i)
92      os << "../";
93    os << "svndigest.css\" type=\"text/css\" />\n"
94       << "</head>\n"
95       << "<body>\n"
96       << "<div id=\"menu\">"
97       << "<ul>\n<li></li>\n";
98    if (item=="main")
99      os << "<li class=\"highlight\">";
100    else
101      os << "<li>";
102    os << anchor("index.html", "Main", level, "Main page");
103    os << "</li>\n";
104
105    std::string stats_local(stats);
106    if (stats_local=="none")
107      stats_local = "classic";
108
109    if (item=="total")
110      os << "<li class=\"highlight\">";
111    else
112      os << "<li>\n";
113    os << anchor(stats_local+"/"+user+"/total/"+path, "Total", level, 
114           "View statistics of all lines");
115    os << "</li>\n";
116
117    if (item=="code")
118      os << "<li class=\"highlight\">";
119    else
120      os << "<li>";
121    os << anchor(stats_local+"/"+user+"/code/"+path, "Code", level, 
122                 "View statistics of code lines");
123    os << "</li>\n";
124
125    if (item=="comments")
126      os << "<li class=\"highlight\">";
127    else
128      os << "<li>";
129    os << anchor(stats_local+"/"+user+"/comments/"+path, "Comment", level, 
130                 "View statistics of comment lines");
131    os << "</li>\n";
132
133
134    if (item=="empty")
135      os << "<li class=\"highlight\">";
136    else
137      os << "<li>";
138    os << anchor(stats_local+"/"+user+"/empty/"+path, "Other", level, 
139                 "View statistics of other lines");
140    os << "</li>\n";
141    os << "<li>";
142    // Peter, this is ugly! But how to add space?
143    for (size_t i=0; i<50; ++i)
144      os << "&nbsp;";
145    os << "</li>\n";
146
147    std::string item_local(item);
148    if (item_local=="none")
149      item_local = "total";
150    if (item_local=="main")
151      item_local = "total";
152
153    if (stats=="classic")
154      os << "<li class=\"highlight\">";
155    else
156      os << "<li>";
157    os << anchor("classic/"+user+"/"+item_local+"/"+path, "Classic", level, 
158                 "View classic statistics");
159    os << "</li>\n";
160
161    if (stats=="blame")
162      os << "<li class=\"highlight\">";
163    else
164      os << "<li>";
165    os << anchor("blame/"+user+"/"+item_local+"/"+path, "Blame", level, 
166                 "View blame statistics");
167    os << "</li>\n";
168
169    if (stats=="add")
170      os << "<li class=\"highlight\">";
171    else
172      os << "<li>";
173    os << anchor("add/"+user+"/"+item_local+"/"+path, "Add", level, 
174                 "View add statistics");
175    os << "</li>\n";
176
177
178    os << "</li>\n"
179       << "</ul></div>\n"
180       << "<div id=\"main\">\n";
181  }
182
183
184  std::string trac_revision(svn_revnum_t r, std::string color)
185  {
186    const Configuration& conf = Configuration::instance();
187    std::stringstream ss;
188    if (conf.trac_root().empty())
189      ss << r; 
190    else {
191      std::stringstream rev;
192      rev << r;
193      ss << anchor(conf.trac_root()+"changeset/"+rev.str(), rev.str(),
194                   0, "View ChangeSet "+rev.str(), color);
195    }
196    return ss.str();
197  }
198
199}} // end of namespace svndigest and namespace theplu
Note: See TracBrowser for help on using the repository browser.