source: trunk/lib/Node.cc @ 234

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

fixes #87 and #95 and #103 and #104 and #80 and #108, and refs #69

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 4.6 KB
Line 
1// $Id: Node.cc 234 2007-04-09 12:08:26Z peter $
2
3/*
4  Copyright (C) 2005, 2006 Jari Häkkinen, Peter Johansson
5  Copyright (C) 2007 Peter Johansson
6
7  This file is part of svndigest, http://lev.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 "Node.h"
26#include "html_utility.h"
27#include "SVNproperty.h"
28#include "utility.h"
29
30#include <cassert>
31#include <ctime>
32#include <fstream>
33#include <sstream>
34
35namespace theplu{
36namespace svndigest{
37
38  std::string Node::project_=std::string();
39
40  Node::Node(const u_int level, const std::string& path, 
41             const std::string& local_path)
42    : level_(level), path_(path), stats_(path), 
43      svninfo_(path)
44  { 
45    SVNproperty property(path);
46    binary_=property.binary();
47    svndigest_ignore_=property.svndigest_ignore();
48    if (Node::project_==std::string()) // no root directory in local path
49      Node::project_ = file_name(path);
50    else if (local_path.empty())
51      local_path_ = file_name(path);
52    else
53      local_path_ = local_path + "/" + file_name(path);
54  }
55
56
57  bool Node::dir(void) const
58  {
59    return false;
60  }
61
62
63  void Node::path_anchor(std::ostream& os) const
64  {
65
66    os << "<h2 class=\"path\">\n";
67    std::vector<std::string> words;
68    words.reserve(level_+1);
69    std::string word;
70    words.push_back(Node::project_);
71    std::stringstream ss(local_path());
72    while(getline(ss,word,'/'))
73      if (!word.empty()) // ignore double slash in path
74        words.push_back(word);
75    if (words.size()==1)
76      anchor(os, "index.html", Node::project_,0, "View " + Node::project_);
77    else {
78      for (size_t i=0; i<words.size()-1; ++i){
79        anchor(os,"index.html", words[i], level_-i, "View " + words[i]);
80        os << "<span class=\"sep\">/</span>\n";
81      }
82      anchor(os,href(), words.back(), level_+2-words.size(), 
83             "View " + words.back()); 
84    }
85    os << "\n</h2>\n";
86  }
87
88
89  void Node::html_tablerow(std::ostream& os, 
90                           const std::string& css_class,
91                           const std::string& user) const
92  {
93    os << "<tr class=\"" << css_class << "\">\n"
94       << "<td class=\"" << node_type() << "\">";
95    if (svndigest_ignore())
96      os << name() << " (<i>svndigest:ignore</i>)";
97    else if (binary())
98      os << name() << " (<i>binary</i>)";
99    // there is no output for nodes when user has zero contribution
100    else if (user!="all" && !stats_.lines(user))
101      os << name();
102    else
103      anchor(os,href(), name()); 
104    os << "</td>\n"; 
105    if (user=="all") {
106      os << "<td>" << stats_.lines() << "</td>\n"
107         << "<td>" << stats_.code() << "</td>\n"
108         << "<td>" << stats_.comments() << "</td>\n"
109         << "<td>" << stats_.empty() << "</td>\n";
110    }
111    else {
112      os << "<td>" << stats_.lines(user) << "</td>\n"
113         << "<td>" << stats_.code(user) << "</td>\n"
114         << "<td>" << stats_.comments(user) << "</td>\n"
115         << "<td>" << stats_.empty(user) << "</td>\n";
116    }
117    os << "<td>" << stats_.last_changed_rev() << "</td>\n"
118       << "<td>" << author() << "</td>\n"
119       << "</tr>\n";
120  }
121
122
123  void Node::print_author_summary(std::ostream& os) const
124  { 
125    os << "<table class=\"listings\">\n";
126    os << "<thead>";
127    os << "<tr>\n";
128    os << "<th>Author</th>\n";
129    os << "<th>Lines</th>\n";
130    os << "<th>Code</th>\n";
131    os << "<th>Comments</th>\n";
132    os << "</tr>\n</thead>\n";
133    os << "<tbody>";
134
135    os << "<tr class=\"light\">\n";
136    os << "<td class=\"directory\" colspan=\"5\">";
137    anchor(os, "index.html", "../");
138    os << "</td>\n</tr>\n";
139       
140    // print authors
141    std::string color("dark");
142    for (std::set<std::string>::const_iterator i=stats_.authors().begin();
143         i!=stats_.authors().end(); ++i){
144      os << "<tr class=\"" << color << "\"><td>" << *i
145         << "</td><td>" << stats_.lines(*i)
146         << "</td><td>" << stats_.code(*i)
147         << "</td><td>" << stats_.comments(*i)
148         << "</td></tr>\n";
149      if (color=="dark")
150        color="light";
151      else
152        color="dark";
153    }
154
155    os << "<tr class=\"" << color << "\">\n";
156    os << "<td>Total</td>\n";
157    os << "<td>" << stats_.lines() << "</td>\n";
158    os << "<td>" << stats_.code() << "</td>\n";
159    os << "<td>" << stats_.comments() << "</td>\n";
160    os << "</tr>\n";
161    os << "</table>\n";
162
163  }
164
165}} // end of namespace svndigest and namespace theplu
Note: See TracBrowser for help on using the repository browser.