source: trunk/lib/html_utility.cc @ 439

Last change on this file since 439 was 439, checked in by Peter Johansson, 14 years ago

Merged patch release 0.6.1 to the trunk. Delta 0.6.1 - 0.6

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 3.7 KB
RevLine 
[177]1// $Id: html_utility.cc 439 2007-07-09 21:04:52Z peter $
2
3/*
[408]4  Copyright (C) 2006 Peter Johansson
5  Copyright (C) 2007 Jari Häkkinen, Peter Johansson
[177]6
[439]7  This file is part of svndigest, http://trac.thep.lu.se/trac/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
[274]27#include "Configuration.h"
[235]28#include "Date.h"
[234]29#include "HtmlStream.h"
[200]30#include <config.h> // this header file is created by configure
[177]31
32#include <sstream>
33#include <string>
34
35namespace theplu{
36namespace svndigest{
37
[376]38  std::string anchor(const std::string& url,
[235]39                     const std::string& name, u_int level, 
40                     const std::string& title)
[177]41  {
[235]42    std::stringstream ss;
43    HtmlStream hs(ss);
44    ss << "<a title=\"";
45    hs << title; 
46    ss << "\" href=\"";
[177]47    for (size_t i=0; i<level; ++i)
[235]48      ss << "../";
[376]49    ss << url; 
[235]50    ss << "\">"; 
51    hs << name; 
52    ss << "</a>";
53    return ss.str();
[177]54  }
55
[178]56 
[200]57  void print_footer(std::ostream& os)
58  {
[235]59    Date date;
[400]60    os << "<p class=\"footer\">\nGenerated on "
[235]61       << date("%a %b %d %H:%M:%S %Y") << " (UTC) by "
[439]62       << anchor("http://trac.thep.lu.se/trac/svndigest/", 
[235]63                 PACKAGE_STRING, 0, "")
[400]64       << "\n</p>\n</div>\n</body>\n</html>\n";
[200]65  }
66
67
[234]68  void print_header(std::ostream& os, std::string title, u_int level,
69                    std::string user, std::string item, std::string path)
[199]70  {
71    os << "<!DOCTYPE html\n"
72       << "PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"\n"
73       << "\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n"
74       << "<html xmlns=\"http://www.w3.org/1999/xhtml\""
[400]75       << " xml:lang=\"en\" lang=\"en\">\n"
[199]76       << "<head>\n"
[201]77       << "<title> " << title << " - svndigest</title>\n"
[199]78       << "<link rel=\"stylesheet\" "
79       << "href=\"";
80    for (u_int i=0; i<level; ++i)
81      os << "../";
82    os << "svndigest.css\" type=\"text/css\" />\n"
[400]83       << "</head>\n"
[199]84       << "<body>\n"
85       << "<div id=\"menu\">"
[212]86       << "<ul><li></li>";
87    if (item=="main")
88      os << "<li class=\"highlight\">";
89    else
90      os << "<li>";
[235]91    os << anchor("index.html", "Main", level, "Main page");
[212]92    os << "</li>";
93
94    if (item=="total")
95      os << "<li class=\"highlight\">";
96    else
97      os << "<li>";
[235]98    os << anchor(user+"/total/"+path, "Total", level, 
[209]99           "View statistics of all lines");
[212]100    os << "</li>";
101
102    if (item=="code")
103      os << "<li class=\"highlight\">";
104    else
105      os << "<li>";
[235]106    os << anchor(user+"/code/"+path, "Code", level, 
107                 "View statistics of code lines");
[212]108    os << "</li>";
109
110    if (item=="comments")
111      os << "<li class=\"highlight\">";
112    else
113      os << "<li>";
[235]114    os << anchor(user+"/comments/"+path, "Comment", level, 
115                 "View statistics of comment lines");
[212]116    os << "</li>";
117
118
119    if (item=="empty")
120      os << "<li class=\"highlight\">";
121    else
122      os << "<li>";
[243]123    os << anchor(user+"/empty/"+path, "Other", level, 
[235]124                 "View statistics of empty lines");
[209]125    os << "</li>"
[199]126       << "</ul></div>"
127       << "<div id=\"main\">\n";
128  }
129
130
[274]131  std::string trac_revision(size_t r)
132  {
[289]133    const Configuration& conf = Configuration::instance();
[274]134    std::stringstream ss;
[289]135    if (conf.trac_root().empty())
[274]136      ss << r; 
137    else {
138      std::stringstream rev;
139      rev << r;
[289]140      ss << anchor(conf.trac_root()+"changeset/"+rev.str(), rev.str());
[274]141    }
142    return ss.str();
143  }
144
[177]145}} // end of namespace svndigest and namespace theplu
Note: See TracBrowser for help on using the repository browser.