source: trunk/lib/html_utility.cc @ 620

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

Made version string (in parenthesis) a function that is called from footer and function creating --version output. PP Macro TIME and DATE were moved to subversion_info.cc. For details about why see comment in subversion_info.h

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 5.2 KB
Line 
1// $Id: html_utility.cc 620 2008-04-23 00:43:10Z 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 "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    os << version_string() << "\n";
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(size_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.