source: trunk/lib/html_utility.cc @ 892

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

define PACKAGE_URL in configure.ac also for autoconf 2.63 and older. Use PACKAGE_URL in footer rather than hard-coded value.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 5.3 KB
Line 
1// $Id: html_utility.cc 892 2009-11-26 05:56:47Z peter $
2
3/*
4  Copyright (C) 2006 Peter Johansson
5  Copyright (C) 2007, 2008 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(PACKAGE_URL, PACKAGE_STRING, 0, "");
70    if (DEV_BUILD)
71      os << " (dev build " << 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    print_html_start(os, title, level);
81    os << "<div id=\"menu\">"
82       << "<ul>\n<li></li>\n";
83    if (item=="main")
84      os << "<li class=\"highlight\">";
85    else
86      os << "<li>";
87    os << anchor("index.html", "Main", level, "Main page");
88    os << "</li>\n";
89
90    std::string stats_local(stats);
91    if (stats_local=="none")
92      stats_local = "classic";
93
94    if (item=="total")
95      os << "<li class=\"highlight\">";
96    else
97      os << "<li>\n";
98    os << anchor(stats_local+"/"+user+"/total/"+path, "Total", level, 
99           "View statistics of all lines");
100    os << "</li>\n";
101
102    if (item=="code")
103      os << "<li class=\"highlight\">";
104    else
105      os << "<li>";
106    os << anchor(stats_local+"/"+user+"/code/"+path, "Code", level, 
107                 "View statistics of code lines");
108    os << "</li>\n";
109
110    if (item=="comments")
111      os << "<li class=\"highlight\">";
112    else
113      os << "<li>";
114    os << anchor(stats_local+"/"+user+"/comments/"+path, "Comment", level, 
115                 "View statistics of comment lines");
116    os << "</li>\n";
117
118
119    if (item=="empty")
120      os << "<li class=\"highlight\">";
121    else
122      os << "<li>";
123    os << anchor(stats_local+"/"+user+"/empty/"+path, "Other", level, 
124                 "View statistics of other lines");
125    os << "</li>\n";
126    os << "<li>";
127    // Peter, this is ugly! But how to add space?
128    for (size_t i=0; i<50; ++i)
129      os << "&nbsp;";
130    os << "</li>\n";
131
132    std::string item_local(item);
133    if (item_local=="none")
134      item_local = "total";
135    if (item_local=="main")
136      item_local = "total";
137
138    if (stats=="classic")
139      os << "<li class=\"highlight\">";
140    else
141      os << "<li>";
142    os << anchor("classic/"+user+"/"+item_local+"/"+path, "Classic", level, 
143                 "View classic statistics");
144    os << "</li>\n";
145
146    if (stats=="blame")
147      os << "<li class=\"highlight\">";
148    else
149      os << "<li>";
150    os << anchor("blame/"+user+"/"+item_local+"/"+path, "Blame", level, 
151                 "View blame statistics");
152    os << "</li>\n";
153
154    if (stats=="add")
155      os << "<li class=\"highlight\">";
156    else
157      os << "<li>";
158    os << anchor("add/"+user+"/"+item_local+"/"+path, "Add", level, 
159                 "View add statistics");
160    os << "</li>\n";
161
162
163    os << "</li>\n"
164       << "</ul></div>\n"
165       << "<div id=\"main\">\n";
166  }
167
168
169  void print_html_start(std::ostream& os, const std::string& title, 
170                        unsigned int level)
171  {
172    os << "<!-- Generated by " << PACKAGE_STRING << "-->\n";
173    os << "<!DOCTYPE html\n"
174       << "PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"\n"
175       << "\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n"
176       << "<html xmlns=\"http://www.w3.org/1999/xhtml\""
177       << " xml:lang=\"en\" lang=\"en\">\n"
178       << "<head>\n"
179       << "<title> " << title << " - svndigest</title>\n"
180       << "<link rel=\"stylesheet\" "
181       << "href=\"";
182    for (unsigned int i=0; i<level; ++i)
183      os << "../";
184    os << "svndigest.css\" type=\"text/css\" />\n"
185       << "</head>\n"
186       << "<body>\n";
187  }
188
189  std::string trac_revision(svn_revnum_t r, std::string color)
190  {
191    const Configuration& conf = Configuration::instance();
192    std::stringstream ss;
193    if (conf.trac_root().empty())
194      ss << r; 
195    else {
196      std::stringstream rev;
197      rev << r;
198      ss << anchor(conf.trac_root()+"changeset/"+rev.str(), rev.str(),
199                   0, "View ChangeSet "+rev.str(), color);
200    }
201    return ss.str();
202  }
203
204}} // end of namespace svndigest and namespace theplu
Note: See TracBrowser for help on using the repository browser.