source: trunk/lib/Node.cc @ 185

Last change on this file since 185 was 185, checked in by Jari Häkkinen, 16 years ago

Fixes #65 and #60. Added support for svndigest:ignore. Uppdated documentation. Reworked binary file treatment.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 3.7 KB
Line 
1// $Id: Node.cc 185 2006-09-06 02:39:18Z jari $
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 "SVNproperty.h"
27#include "utility.h"
28#include <config.h> // this header file is created by configure
29
30#include <ctime>
31#include <fstream>
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    SVNproperty property(path);
42    binary_=property.binary();
43    svndigest_ignore_=property.svndigest_ignore();
44    output_name_ = output+file_name(path_); 
45  }
46
47
48  bool Node::dir(void) const
49  {
50    return false;
51  }
52
53
54  void Node::path_anchor(std::ostream& os) const
55  {
56    std::vector<std::string> words;
57    words.reserve(level_+1);
58    std::string word;
59    std::stringstream ss(output_name());
60    while(getline(ss,word,'/'))
61      words.push_back(word);
62    for (size_t i=0; i<words.size()-1; ++i){
63      anchor(os,"index.html", words[i], level_-i, "View " + words[i]);
64      os << "<span class=\"sep\">/</span>\n";
65    }
66    anchor(os,href(), words.back(), level_+2-words.size(), 
67           "View " + words.back()); 
68  }
69
70
71  void Node::html_tablerow(std::ostream& os, 
72                           const std::string& css_class) const
73  {
74    os << "<tr class=\"" << css_class << "\">\n"
75       << "<td class=\"" << node_type() << "\">";
76    if (svndigest_ignore())
77      os << name() << " (<i>svndigest:ignore</i>)";
78    else if (binary())
79      os << name() << " (<i>binary</i>)";
80    else
81      anchor(os,href(), name()); 
82    os << "</td>\n" 
83       << "<td>" << stats_.lines() << "</td>\n"
84       << "<td>" << stats_.code() << "</td>\n"
85       << "<td>" << stats_.comments() << "</td>\n"
86       << "<td>" << stats_.last_changed_rev() << "</td>\n"
87       << "<td>" << author() << "</td>\n"
88       << "</tr>\n";
89  }
90
91
92  void Node::print_footer(std::ostream& os) const
93  {
94    time_t rawtime;
95    struct tm * timeinfo;
96    time ( &rawtime );
97    timeinfo =  gmtime ( &rawtime );
98    os << "<p align=center><font size=-2>\nGenerated on "
99       << asctime (timeinfo) << " (UTC) by ";
100    anchor(os, "http://lev.thep.lu.se/trac/svndigest/", PACKAGE_STRING);
101    os << "</font>\n</p>\n</div>\n</body>\n</html>\n";
102  }
103
104
105  void Node::print_header(std::ostream& os) const
106  {
107    os << "<!DOCTYPE html\n"
108       << "PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"\n"
109       << "\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n"
110       << "<html xmlns=\"http://www.w3.org/1999/xhtml\""
111       << " xml:lang=\"en\" lang=\"en\"><head>\n"
112       << "<head>\n"
113       << "<title> svndigest " << name() << "</title>\n"
114       << "</head>\n"
115       << "<link rel=\"stylesheet\" "
116       << "href=\"";
117    for (u_int i=0; i<level_; ++i)
118      os << "../";
119    os << "svndigest.css\" type=\"text/css\" />\n"
120       << "<body>\n"
121       << "<div id=\"menu\">"
122       << "<ul><li></li>"
123       << "<li>";
124    anchor(os, "index.html", "Home", level_, "Main page");
125    os << "</li>"
126       << "</ul></div>"
127       << "<div id=\"main\">\n"
128       << "<h2 class=\"path\">\n";
129    path_anchor(os);
130    os << "\n</h2>\n";
131  }
132
133}} // end of namespace svndigest and namespace theplu
Note: See TracBrowser for help on using the repository browser.