source: trunk/lib/Node.cc @ 176

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

fixes #12 binary files are now printed with note without anchor. Binary files and directories all counted as zero lines.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 3.5 KB
Line 
1// $Id: Node.cc 176 2006-09-02 04:17:28Z 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 "utility.h"
26#include <config.h> // this header file is created by configure
27
28#include <ctime>
29#include <fstream>
30#include <iostream>
31#include <sstream>
32
33namespace theplu{
34namespace svndigest{
35
36  Node::Node(const u_int level, const std::string& path, 
37             const std::string& output="")
38    : level_(level), path_(path), stats_(path), svninfo_(path)
39  { 
40    output_name_ = output+file_name(path_); 
41  }
42
43  bool Node::dir(void) const
44  {
45    return false;
46  }
47
48  void Node::path_anchor(std::ostream& os) const
49  {
50    std::vector<std::string> words;
51    words.reserve(level_+1);
52    std::string word;
53    std::stringstream ss(output_name());
54    while(getline(ss,word,'/'))
55      words.push_back(word);
56    for (size_t i=0; i<words.size()-1; ++i){
57      anchor(os,"index.html", words[i], level_-i, "View " + words[i]);
58      os << "<span class=\"sep\">/</span>\n";
59    }
60    anchor(os,href(), words.back(), level_+2-words.size(), 
61           "View " + words.back()); 
62  }
63
64  void Node::html_tablerow(std::ostream& os, 
65                           const std::string& css_class) const
66  {
67    os << "<tr class=\"" << css_class << "\">\n"
68       << "<td>" ;
69    if (binary())
70      os << name() << " (<i>binary</i>)";
71    else
72      anchor(os,href(), name()); 
73    os << "</td>\n" 
74       << "<td>" << stats_.lines() << "</td>\n"
75       << "<td>" << stats_.code() << "</td>\n"
76       << "<td>" << stats_.comments() << "</td>\n"
77       << "<td>" << stats_.last_changed_rev() << "</td>\n"
78       << "<td>" << author() << "</td>\n"
79       << "</tr>\n";
80  }
81
82  void Node::print_footer(std::ostream& os) const
83  {
84    time_t rawtime;
85    struct tm * timeinfo;
86    time ( &rawtime );
87    timeinfo =  gmtime ( &rawtime );
88    os << "<p align=center><font size=-2>\nGenerated on "
89       << asctime (timeinfo) << " (UTC) "
90       << "by <a href=http://lev.thep.lu.se/trac/svndigest/>"
91       << PACKAGE_STRING << "</a>"
92       << "</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><a href=\"";
115    for (u_int i=0; i<level_; ++i)
116      os << "../";
117    os << "index.html\">Home</a></li>"
118       << "</ul></div>"
119       << "<div id=\"main\">\n"
120       << "<h2 class=\"path\">\n";
121    path_anchor(os);
122    os << "\n</h2>\n";
123  }
124
125}} // end of namespace svndigest and namespace theplu
Note: See TracBrowser for help on using the repository browser.