source: tags/0.6.8/lib/html_utility.cc @ 848

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

update copyright statements

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 3.8 KB
Line 
1// $Id: html_utility.cc 731 2008-12-15 19:03:04Z peter $
2
3/*
4  Copyright (C) 2006 Peter Johansson
5  Copyright (C) 2007 Jari Häkkinen, Peter Johansson
6  Copyright (C) 2008 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 2 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 this program; if not, write to the Free Software
22  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
23  02111-1307, USA.
24*/
25
26#include "html_utility.h"
27
28#include "Configuration.h"
29#include "Date.h"
30#include "HtmlStream.h"
31#include <config.h> // this header file is created by configure
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, u_int level, 
41                     const std::string& title)
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    hs << name; 
53    ss << "</a>";
54    return ss.str();
55  }
56
57 
58  void print_footer(std::ostream& os)
59  {
60    Date date;
61    os << "<p class=\"footer\">\nGenerated on "
62       << date("%a %b %d %H:%M:%S %Y") << " (UTC) by "
63       << anchor("http://dev.thep.lu.se/svndigest/", 
64                 PACKAGE_STRING, 0, "")
65       << "\n</p>\n</div>\n</body>\n</html>\n";
66  }
67
68
69  void print_header(std::ostream& os, std::string title, u_int level,
70                    std::string user, std::string item, std::string path)
71  {
72    os << "<!DOCTYPE html\n"
73       << "PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"\n"
74       << "\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n"
75       << "<html xmlns=\"http://www.w3.org/1999/xhtml\""
76       << " xml:lang=\"en\" lang=\"en\">\n"
77       << "<head>\n"
78       << "<title> " << title << " - svndigest</title>\n"
79       << "<link rel=\"stylesheet\" "
80       << "href=\"";
81    for (u_int i=0; i<level; ++i)
82      os << "../";
83    os << "svndigest.css\" type=\"text/css\" />\n"
84       << "</head>\n"
85       << "<body>\n"
86       << "<div id=\"menu\">"
87       << "<ul><li></li>";
88    if (item=="main")
89      os << "<li class=\"highlight\">";
90    else
91      os << "<li>";
92    os << anchor("index.html", "Main", level, "Main page");
93    os << "</li>";
94
95    if (item=="total")
96      os << "<li class=\"highlight\">";
97    else
98      os << "<li>";
99    os << anchor(user+"/total/"+path, "Total", level, 
100           "View statistics of all lines");
101    os << "</li>";
102
103    if (item=="code")
104      os << "<li class=\"highlight\">";
105    else
106      os << "<li>";
107    os << anchor(user+"/code/"+path, "Code", level, 
108                 "View statistics of code lines");
109    os << "</li>";
110
111    if (item=="comments")
112      os << "<li class=\"highlight\">";
113    else
114      os << "<li>";
115    os << anchor(user+"/comments/"+path, "Comment", level, 
116                 "View statistics of comment lines");
117    os << "</li>";
118
119
120    if (item=="empty")
121      os << "<li class=\"highlight\">";
122    else
123      os << "<li>";
124    os << anchor(user+"/empty/"+path, "Other", level, 
125                 "View statistics of other lines");
126    os << "</li>"
127       << "</ul></div>"
128       << "<div id=\"main\">\n";
129  }
130
131
132  std::string trac_revision(size_t r)
133  {
134    const Configuration& conf = Configuration::instance();
135    std::stringstream ss;
136    if (conf.trac_root().empty())
137      ss << r; 
138    else {
139      std::stringstream rev;
140      rev << r;
141      ss << anchor(conf.trac_root()+"changeset/"+rev.str(), rev.str());
142    }
143    return ss.str();
144  }
145
146}} // end of namespace svndigest and namespace theplu
Note: See TracBrowser for help on using the repository browser.