source: trunk/lib/html_utility.cc @ 546

Last change on this file since 546 was 546, checked in by Peter Johansson, 15 years ago

fixes #286 - links to different StatsType

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 5.0 KB
Line 
1// $Id: html_utility.cc 546 2008-01-04 03:46:48Z 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://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 "Configuration.h"
28#include "Date.h"
29#include "HtmlStream.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, u_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://trac.thep.lu.se/svndigest/", 
68                 PACKAGE_STRING, 0, "")
69       << "\n</p>\n</div>\n</body>\n</html>\n";
70  }
71
72
73  void print_header(std::ostream& os, std::string title, u_int level,
74                    std::string user, std::string item, std::string path,
75                    const std::string& stats)
76  {
77    os << "<!DOCTYPE html\n"
78       << "PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"\n"
79       << "\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n"
80       << "<html xmlns=\"http://www.w3.org/1999/xhtml\""
81       << " xml:lang=\"en\" lang=\"en\">\n"
82       << "<head>\n"
83       << "<title> " << title << " - svndigest</title>\n"
84       << "<link rel=\"stylesheet\" "
85       << "href=\"";
86    for (u_int i=0; i<level; ++i)
87      os << "../";
88    os << "svndigest.css\" type=\"text/css\" />\n"
89       << "</head>\n"
90       << "<body>\n"
91       << "<div id=\"menu\">"
92       << "<ul>\n<li></li>\n";
93    if (item=="main")
94      os << "<li class=\"highlight\">";
95    else
96      os << "<li>";
97    os << anchor("index.html", "Main", level, "Main page");
98    os << "</li>\n";
99
100    std::string stats_local(stats);
101    if (stats_local=="none")
102      stats_local = "classic";
103
104    if (item=="total")
105      os << "<li class=\"highlight\">";
106    else
107      os << "<li>\n";
108    os << anchor(stats_local+"/"+user+"/total/"+path, "Total", level, 
109           "View statistics of all lines");
110    os << "</li>\n";
111
112    if (item=="code")
113      os << "<li class=\"highlight\">";
114    else
115      os << "<li>";
116    os << anchor(stats_local+"/"+user+"/code/"+path, "Code", level, 
117                 "View statistics of code lines");
118    os << "</li>\n";
119
120    if (item=="comments")
121      os << "<li class=\"highlight\">";
122    else
123      os << "<li>";
124    os << anchor(stats_local+"/"+user+"/comments/"+path, "Comment", level, 
125                 "View statistics of comment lines");
126    os << "</li>\n";
127
128
129    if (item=="empty")
130      os << "<li class=\"highlight\">";
131    else
132      os << "<li>";
133    os << anchor(stats_local+"/"+user+"/empty/"+path, "Other", level, 
134                 "View statistics of other lines");
135    os << "</li>\n";
136    os << "<li>";
137    // Peter, this is ugly! But how to add space?
138    for (size_t i=0; i<50; ++i)
139      os << "&nbsp;";
140    os << "</li>\n";
141
142    std::string item_local(item);
143    if (item_local=="none")
144      item_local = "total";
145
146    if (stats=="classic")
147      os << "<li class=\"highlight\">";
148    else
149      os << "<li>";
150    os << anchor("classic/"+user+"/"+item_local+"/"+path, "Classic", level, 
151                 "View classic statistics");
152    os << "</li>\n";
153
154    if (stats=="blame")
155      os << "<li class=\"highlight\">";
156    else
157      os << "<li>";
158    os << anchor("blame/"+user+"/"+item_local+"/"+path, "Blame", level, 
159                 "View blame statistics");
160    os << "</li>\n";
161
162    if (stats=="add")
163      os << "<li class=\"highlight\">";
164    else
165      os << "<li>";
166    os << anchor("add/"+user+"/"+item_local+"/"+path, "Add", level, 
167                 "View add statistics");
168    os << "</li>\n";
169
170
171    os << "</li>\n"
172       << "</ul></div>\n"
173       << "<div id=\"main\">\n";
174  }
175
176
177  std::string trac_revision(size_t r, std::string color)
178  {
179    const Configuration& conf = Configuration::instance();
180    std::stringstream ss;
181    if (conf.trac_root().empty())
182      ss << r; 
183    else {
184      std::stringstream rev;
185      rev << r;
186      ss << anchor(conf.trac_root()+"changeset/"+rev.str(), rev.str(),
187                   0, "View ChangeSet "+rev.str(), color);
188    }
189    return ss.str();
190  }
191
192}} // end of namespace svndigest and namespace theplu
Note: See TracBrowser for help on using the repository browser.