source: trunk/lib/html_utility.cc @ 498

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

fixes #223

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 4.0 KB
Line 
1// $Id: html_utility.cc 498 2007-10-14 06:09:34Z 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                     const std::string& color)
42  {
43    std::stringstream ss;
44    HtmlStream hs(ss);
45    ss << "<a title=\"";
46    hs << title; 
47    ss << "\" href=\"";
48    for (size_t i=0; i<level; ++i)
49      ss << "../";
50    ss << url; 
51    ss << "\">"; 
52    if (color.size())
53      ss << "<font color=\"" << color << "\">";
54    hs << name; 
55    if (color.size())
56      ss << "</font>";
57    ss << "</a>";
58    return ss.str();
59  }
60
61 
62  void print_footer(std::ostream& os)
63  {
64    Date date;
65    os << "<p class=\"footer\">\nGenerated on "
66       << date("%a %b %d %H:%M:%S %Y") << " (UTC) by "
67       << anchor("http://trac.thep.lu.se/trac/svndigest/", 
68                 PACKAGE_STRING, 0, "")
69       << "\n</p>\n</div>\n</body>\n</html>\n";
70  }
71
72
73  void print_header(std::ostream& os, std::string title, u_int level,
74                    std::string user, std::string item, std::string path)
75  {
76    os << "<!DOCTYPE html\n"
77       << "PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"\n"
78       << "\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n"
79       << "<html xmlns=\"http://www.w3.org/1999/xhtml\""
80       << " xml:lang=\"en\" lang=\"en\">\n"
81       << "<head>\n"
82       << "<title> " << title << " - svndigest</title>\n"
83       << "<link rel=\"stylesheet\" "
84       << "href=\"";
85    for (u_int i=0; i<level; ++i)
86      os << "../";
87    os << "svndigest.css\" type=\"text/css\" />\n"
88       << "</head>\n"
89       << "<body>\n"
90       << "<div id=\"menu\">"
91       << "<ul><li></li>";
92    if (item=="main")
93      os << "<li class=\"highlight\">";
94    else
95      os << "<li>";
96    os << anchor("index.html", "Main", level, "Main page");
97    os << "</li>";
98
99    if (item=="total")
100      os << "<li class=\"highlight\">";
101    else
102      os << "<li>";
103    os << anchor("classic/"+user+"/total/"+path, "Total", level, 
104           "View statistics of all lines");
105    os << "</li>";
106
107    if (item=="code")
108      os << "<li class=\"highlight\">";
109    else
110      os << "<li>";
111    os << anchor("classic/"+user+"/code/"+path, "Code", level, 
112                 "View statistics of code lines");
113    os << "</li>";
114
115    if (item=="comments")
116      os << "<li class=\"highlight\">";
117    else
118      os << "<li>";
119    os << anchor("classic/"+user+"/comments/"+path, "Comment", level, 
120                 "View statistics of comment lines");
121    os << "</li>";
122
123
124    if (item=="empty")
125      os << "<li class=\"highlight\">";
126    else
127      os << "<li>";
128    os << anchor("classic/"+user+"/empty/"+path, "Other", level, 
129                 "View statistics of other lines");
130    os << "</li>"
131       << "</ul></div>"
132       << "<div id=\"main\">\n";
133  }
134
135
136  std::string trac_revision(size_t r, std::string color)
137  {
138    const Configuration& conf = Configuration::instance();
139    std::stringstream ss;
140    if (conf.trac_root().empty())
141      ss << r; 
142    else {
143      std::stringstream rev;
144      rev << r;
145      ss << anchor(conf.trac_root()+"changeset/"+rev.str(), rev.str(),
146                   0, "View ChangeSet "+rev.str(), color);
147    }
148    return ss.str();
149  }
150
151}} // end of namespace svndigest and namespace theplu
Note: See TracBrowser for help on using the repository browser.