source: trunk/lib/Node.cc @ 258

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

moving some printing code to base class

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 6.2 KB
Line 
1// $Id: Node.cc 258 2007-04-30 12:08:25Z 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 "SVNlog.h"
28#include "SVNproperty.h"
29#include "utility.h"
30
31#include <cassert>
32#include <ctime>
33#include <fstream>
34#include <sstream>
35
36namespace theplu{
37namespace svndigest{
38
39  std::string Node::project_=std::string();
40
41  Node::Node(const u_int level, const std::string& path, 
42             const std::string& local_path)
43    : level_(level), path_(path), stats_(path), 
44      svninfo_(path)
45  { 
46    SVNproperty property(path);
47    binary_=property.binary();
48    svndigest_ignore_=property.svndigest_ignore();
49    if (Node::project_==std::string()) // no root directory in local path
50      Node::project_ = file_name(path);
51    else if (local_path.empty())
52      local_path_ = file_name(path);
53    else
54      local_path_ = local_path + "/" + file_name(path);
55  }
56
57
58  bool Node::dir(void) const
59  {
60    return false;
61  }
62
63
64  void Node::path_anchor(std::ostream& os) const
65  {
66
67    os << "<h2 class=\"path\">\n";
68    std::vector<std::string> words;
69    words.reserve(level_+1);
70    std::string word;
71    words.push_back(Node::project_);
72    std::stringstream ss(local_path());
73    while(getline(ss,word,'/'))
74      if (!word.empty()) // ignore double slash in path
75        words.push_back(word);
76    if (words.size()==1)
77      os << anchor("index.html", Node::project_,0, "View " + Node::project_);
78    else {
79      for (size_t i=0; i<words.size()-1; ++i){
80        os << anchor("index.html", words[i], level_-i, "View " + words[i]);
81        os << "<span class=\"sep\">/</span>\n";
82      }
83      os << anchor(href(), words.back(), level_+2-words.size(), 
84             "View " + words.back()); 
85    }
86    os << "\n</h2>\n";
87  }
88
89
90  void Node::html_tablerow(std::ostream& os, 
91                           const std::string& css_class,
92                           const std::string& user) const
93  {
94    os << "<tr class=\"" << css_class << "\">\n"
95       << "<td class=\"" << node_type() << "\">";
96    if (svndigest_ignore())
97      os << name() << " (<i>svndigest:ignore</i>)";
98    else if (binary())
99      os << name() << " (<i>binary</i>)";
100    // there is no output for nodes when user has zero contribution
101    else if (user!="all" && !stats_.lines(user))
102      os << name();
103    else
104      os << anchor(href(), name()); 
105    os << "</td>\n"; 
106    if (user=="all") {
107      os << "<td>" << stats_.lines() << "</td>\n"
108         << "<td>" << stats_.code() << "</td>\n"
109         << "<td>" << stats_.comments() << "</td>\n"
110         << "<td>" << stats_.empty() << "</td>\n";
111    }
112    else {
113      os << "<td>" << stats_.lines(user) << "</td>\n"
114         << "<td>" << stats_.code(user) << "</td>\n"
115         << "<td>" << stats_.comments(user) << "</td>\n"
116         << "<td>" << stats_.empty(user) << "</td>\n";
117    }
118    os << "<td>" << stats_.last_changed_rev() << "</td>\n"
119       << "<td>" << author() << "</td>\n"
120       << "</tr>\n";
121  }
122
123
124  void Node::print(const bool verbose) const
125  {
126    if (ignore())
127      return;
128    if (verbose)
129      std::cout << "Printing output for " << path_ << std::endl;
130    SVNlog log(path_);
131    print_core("all", "total", log);
132    print_core("all", "code", log);
133    print_core("all", "comments", log);
134    print_core("all", "empty", log);
135
136    for (std::set<std::string>::const_iterator i = stats_.authors().begin();
137         i!=stats_.authors().end(); ++i) {
138      print_core(*i, "total", log);
139      print_core(*i, "code", log);
140      print_core(*i, "comments", log);
141      print_core(*i, "empty", log);
142    }
143   
144    print_core(verbose);
145  }
146
147
148  void Node::print_author_summary(std::ostream& os, std::string line_type,
149                                  const SVNlog& log) const
150  { 
151    os << "<table class=\"listings\">\n";
152    os << "<thead>";
153    os << "<tr>\n";
154    os << "<th>Author</th>\n";
155    os << "<th>Lines</th>\n";
156    os << "<th>Code</th>\n";
157    os << "<th>Comments</th>\n";
158    os << "<th>Other</th>\n";
159    os << "<th>Revision</th>\n";
160    os << "<th>Date</th>\n";
161    os << "</tr>\n</thead>\n";
162    os << "<tbody>";
163
164    os << "<tr class=\"light\">\n";
165    os << "<td class=\"directory\" colspan=\"5\">";
166    if (!dir())
167      os << anchor("index.html", "../");
168    os << "</td>\n</tr>\n";
169       
170    // print authors
171    std::string color("dark");
172    for (std::set<std::string>::const_iterator i=stats_.authors().begin();
173         i!=stats_.authors().end(); ++i){
174      os << "<tr class=\"" << color << "\"><td>"; 
175      if (dir())
176        if (local_path().empty())
177          os << anchor(*i+"/"+line_type+"/index.html"
178                       ,*i, level_+2, "View statistics for "+*i); 
179        else
180          os << anchor(*i+"/"+line_type+"/"+local_path()+"/index.html"
181                       ,*i, level_+2, "View statistics for "+*i); 
182      else
183        os << anchor(*i+"/"+line_type+"/"+local_path()+".html"
184                     ,*i, level_+2, "View statistics for "+*i); 
185      os << "</td><td>" << stats_.lines(*i)
186         << "</td><td>" << stats_.code(*i)
187         << "</td><td>" << stats_.comments(*i)
188         << "</td><td>" << stats_.empty(*i)
189         << "</td><td>" 
190         << "</td><td>" 
191         << "</td></tr>\n";
192      if (color=="dark")
193        color="light";
194      else
195        color="dark";
196    }
197
198    os << "<tr class=\"" << color << "\">\n";
199    os << "<td>"; 
200    if (dir())
201      os << anchor("all/"+line_type+"/"+local_path()+"/index.html"
202                   ,"Total", level_+2, "View statistics for all"); 
203    else
204      os << anchor("all/"+line_type+"/"+local_path()+".html"
205                   ,"Total", level_+2, "View statistics for all"); 
206    os << "</td>\n";
207    os << "<td>" << stats_.lines() << "</td>\n";
208    os << "<td>" << stats_.code() << "</td>\n";
209    os << "<td>" << stats_.comments() << "</td>\n";
210    os << "<td>" << stats_.empty() << "</td>\n";
211    os << "<td>" << "" << "</td>\n";
212    os << "<td>" << "" << "</td>\n";
213    os << "</tr>\n";
214    os << "</table>\n";
215
216  }
217
218}} // end of namespace svndigest and namespace theplu
Note: See TracBrowser for help on using the repository browser.