source: trunk/lib/Node.cc @ 235

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

added Date class
changed date format on first page
fixed plotting only once (fixes #113)
changed interface to anchor class
more anchors to users
removed anchor to '../' in author summary in dirs
anchors are filtered through HtmlStream?
log messages are truncated and newlines are replaced with spaces

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 5.2 KB
Line 
1// $Id: Node.cc 235 2007-04-21 13:39:50Z 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      os << anchor("index.html", Node::project_,0, "View " + Node::project_);
77    else {
78      for (size_t i=0; i<words.size()-1; ++i){
79        os << anchor("index.html", words[i], level_-i, "View " + words[i]);
80        os << "<span class=\"sep\">/</span>\n";
81      }
82      os << anchor(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      os << anchor(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, std::string line_type) 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    if (!dir())
138      os << anchor("index.html", "../");
139    os << "</td>\n</tr>\n";
140       
141    // print authors
142    std::string color("dark");
143    for (std::set<std::string>::const_iterator i=stats_.authors().begin();
144         i!=stats_.authors().end(); ++i){
145      os << "<tr class=\"" << color << "\"><td>"; 
146      if (dir())
147        os << anchor(*i+"/"+line_type+"/"+local_path()+"/index.html"
148                     ,*i, level_+2, "View statistics for "+*i); 
149      else
150        os << anchor(*i+"/"+line_type+"/"+local_path()+".html"
151                     ,*i, level_+2, "View statistics for "+*i); 
152      os << "</td><td>" << stats_.lines(*i)
153         << "</td><td>" << stats_.code(*i)
154         << "</td><td>" << stats_.comments(*i)
155         << "</td></tr>\n";
156      if (color=="dark")
157        color="light";
158      else
159        color="dark";
160    }
161
162    os << "<tr class=\"" << color << "\">\n";
163    os << "<td>"; 
164    if (dir())
165      os << anchor("all/"+line_type+"/"+local_path()+"/index.html"
166                   ,"Total", level_+2, "View statistics for all"); 
167    else
168      os << anchor("all/"+line_type+"/"+local_path()+".html"
169                   ,"Total", level_+2, "View statistics for all"); 
170    os << "</td>\n";
171    os << "<td>" << stats_.lines() << "</td>\n";
172    os << "<td>" << stats_.code() << "</td>\n";
173    os << "<td>" << stats_.comments() << "</td>\n";
174    os << "</tr>\n";
175    os << "</table>\n";
176
177  }
178
179}} // end of namespace svndigest and namespace theplu
Note: See TracBrowser for help on using the repository browser.