source: trunk/lib/Node.cc @ 182

Last change on this file since 182 was 182, checked in by Peter Johansson, 16 years ago

fixes #52 in table output directories are bold whereas files are normal.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 3.5 KB
Line 
1// $Id: Node.cc 182 2006-09-03 08:46:34Z peter $
2
3/*
4  Copyright (C) 2005, 2006 Jari Häkkinen, Peter Johansson
5
6  This file is part of svndigest, http://lev.thep.lu.se/trac/svndigest
7
8  svndigest is free software; you can redistribute it and/or modify it
9  under the terms of the GNU General Public License as published by
10  the Free Software Foundation; either version 2 of the License, or
11  (at your option) any later version.
12
13  svndigest is distributed in the hope that it will be useful, but
14  WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  General Public License for more details.
17
18  You should have received a copy of the GNU General Public License
19  along with this program; if not, write to the Free Software
20  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
21  02111-1307, USA.
22*/
23
24#include "Node.h"
25#include "html_utility.h"
26#include "utility.h"
27#include <config.h> // this header file is created by configure
28
29#include <ctime>
30#include <fstream>
31#include <iostream>
32#include <sstream>
33
34namespace theplu{
35namespace svndigest{
36
37  Node::Node(const u_int level, const std::string& path, 
38             const std::string& output="")
39    : level_(level), path_(path), stats_(path), svninfo_(path)
40  { 
41    output_name_ = output+file_name(path_); 
42  }
43
44  bool Node::dir(void) const
45  {
46    return false;
47  }
48
49  void Node::path_anchor(std::ostream& os) const
50  {
51    std::vector<std::string> words;
52    words.reserve(level_+1);
53    std::string word;
54    std::stringstream ss(output_name());
55    while(getline(ss,word,'/'))
56      words.push_back(word);
57    for (size_t i=0; i<words.size()-1; ++i){
58      anchor(os,"index.html", words[i], level_-i, "View " + words[i]);
59      os << "<span class=\"sep\">/</span>\n";
60    }
61    anchor(os,href(), words.back(), level_+2-words.size(), 
62           "View " + words.back()); 
63  }
64
65  void Node::html_tablerow(std::ostream& os, 
66                           const std::string& css_class) const
67  {
68    os << "<tr class=\"" << css_class << "\">\n"
69       << "<td class=\"" << node_type() << "\">";
70    if (binary())
71      os << name() << " (<i>binary</i>)";
72    else
73      anchor(os,href(), name()); 
74    os << "</td>\n" 
75       << "<td>" << stats_.lines() << "</td>\n"
76       << "<td>" << stats_.code() << "</td>\n"
77       << "<td>" << stats_.comments() << "</td>\n"
78       << "<td>" << stats_.last_changed_rev() << "</td>\n"
79       << "<td>" << author() << "</td>\n"
80       << "</tr>\n";
81  }
82
83  void Node::print_footer(std::ostream& os) const
84  {
85    time_t rawtime;
86    struct tm * timeinfo;
87    time ( &rawtime );
88    timeinfo =  gmtime ( &rawtime );
89    os << "<p align=center><font size=-2>\nGenerated on "
90       << asctime (timeinfo) << " (UTC) by ";
91    anchor(os, "http://lev.thep.lu.se/trac/svndigest/", PACKAGE_STRING);
92    os << "</font>\n</p>\n</div>\n</body>\n</html>\n";
93  }
94
95
96  void Node::print_header(std::ostream& os) const
97  {
98    os << "<!DOCTYPE html\n"
99       << "PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"\n"
100       << "\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n"
101       << "<html xmlns=\"http://www.w3.org/1999/xhtml\""
102       << " xml:lang=\"en\" lang=\"en\"><head>\n"
103       << "<head>\n"
104       << "<title> svndigest " << name() << "</title>\n"
105       << "</head>\n"
106       << "<link rel=\"stylesheet\" "
107       << "href=\"";
108    for (u_int i=0; i<level_; ++i)
109      os << "../";
110    os << "svndigest.css\" type=\"text/css\" />\n"
111       << "<body>\n"
112       << "<div id=\"menu\">"
113       << "<ul><li></li>"
114       << "<li>";
115    anchor(os, "index.html", "Home", level_, "Main page");
116    os << "</li>"
117       << "</ul></div>"
118       << "<div id=\"main\">\n"
119       << "<h2 class=\"path\">\n";
120    path_anchor(os);
121    os << "\n</h2>\n";
122  }
123
124}} // end of namespace svndigest and namespace theplu
Note: See TracBrowser for help on using the repository browser.