source: trunk/lib/html_utility.cc @ 589

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

Replace u_int with unsigned int.

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