source: trunk/lib/html_utility.cc @ 751

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

closes #308

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