source: trunk/lib/html_utility.cc @ 497

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

preparing for more statistics by adding StatsType layer in structure on top of previous structure, i.e., NewStructure? = StatsType/OldStructure?

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 3.8 KB
Line 
1// $Id: html_utility.cc 497 2007-10-14 04:58:06Z 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/trac/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 <config.h> // this header file is created by configure
31
32#include <sstream>
33#include <string>
34
35namespace theplu{
36namespace svndigest{
37
38  std::string anchor(const std::string& url,
39                     const std::string& name, u_int level, 
40                     const std::string& title)
41  {
42    std::stringstream ss;
43    HtmlStream hs(ss);
44    ss << "<a title=\"";
45    hs << title; 
46    ss << "\" href=\"";
47    for (size_t i=0; i<level; ++i)
48      ss << "../";
49    ss << url; 
50    ss << "\">"; 
51    hs << name; 
52    ss << "</a>";
53    return ss.str();
54  }
55
56 
57  void print_footer(std::ostream& os)
58  {
59    Date date;
60    os << "<p class=\"footer\">\nGenerated on "
61       << date("%a %b %d %H:%M:%S %Y") << " (UTC) by "
62       << anchor("http://trac.thep.lu.se/trac/svndigest/", 
63                 PACKAGE_STRING, 0, "")
64       << "\n</p>\n</div>\n</body>\n</html>\n";
65  }
66
67
68  void print_header(std::ostream& os, std::string title, u_int level,
69                    std::string user, std::string item, std::string path)
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\""
75       << " xml:lang=\"en\" lang=\"en\">\n"
76       << "<head>\n"
77       << "<title> " << title << " - svndigest</title>\n"
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"
83       << "</head>\n"
84       << "<body>\n"
85       << "<div id=\"menu\">"
86       << "<ul><li></li>";
87    if (item=="main")
88      os << "<li class=\"highlight\">";
89    else
90      os << "<li>";
91    os << anchor("index.html", "Main", level, "Main page");
92    os << "</li>";
93
94    if (item=="total")
95      os << "<li class=\"highlight\">";
96    else
97      os << "<li>";
98    os << anchor("classic/"+user+"/total/"+path, "Total", level, 
99           "View statistics of all lines");
100    os << "</li>";
101
102    if (item=="code")
103      os << "<li class=\"highlight\">";
104    else
105      os << "<li>";
106    os << anchor("classic/"+user+"/code/"+path, "Code", level, 
107                 "View statistics of code lines");
108    os << "</li>";
109
110    if (item=="comments")
111      os << "<li class=\"highlight\">";
112    else
113      os << "<li>";
114    os << anchor("classic/"+user+"/comments/"+path, "Comment", level, 
115                 "View statistics of comment lines");
116    os << "</li>";
117
118
119    if (item=="empty")
120      os << "<li class=\"highlight\">";
121    else
122      os << "<li>";
123    os << anchor("classic/"+user+"/empty/"+path, "Other", level, 
124                 "View statistics of other lines");
125    os << "</li>"
126       << "</ul></div>"
127       << "<div id=\"main\">\n";
128  }
129
130
131  std::string trac_revision(size_t r)
132  {
133    const Configuration& conf = Configuration::instance();
134    std::stringstream ss;
135    if (conf.trac_root().empty())
136      ss << r; 
137    else {
138      std::stringstream rev;
139      rev << r;
140      ss << anchor(conf.trac_root()+"changeset/"+rev.str(), rev.str());
141    }
142    return ss.str();
143  }
144
145}} // end of namespace svndigest and namespace theplu
Note: See TracBrowser for help on using the repository browser.