source: trunk/lib/html_utility.cc @ 643

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

fixes #290 - using svn_revnum_t for revisions

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