source: trunk/lib/File.cc @ 182

Last change on this file since 182 was 182, checked in by Peter Johansson, 17 years ago

fixes #52 in table output directories are bold whereas files are normal.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 3.1 KB
Line 
1// $Id: File.cc 182 2006-09-03 08:46:34Z 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 "File.h"
25#include "html_utility.h"
26#include "Stats.h"
27
28#include <fstream>
29#include <iostream>
30#include <string>
31
32namespace theplu{
33namespace svndigest{
34
35  bool File::binary(void) const
36  {
37    return binary_;
38  }
39
40
41  std::string File::href(void) const
42  { 
43    return name()+".html"; 
44  }
45
46
47  const std::string File::node_type(void) const
48  {
49    return std::string("file");
50  }
51
52
53  const Stats& File::parse(const bool verbose)
54  {
55    if (verbose)
56      std::cout << "Parsing " << path_ << std::endl; 
57    stats_.reset();
58    binary_ = stats_.parse(path_);
59    return stats_;
60  }
61
62  void File::print(const bool verbose) const 
63  {
64    // no output page for binary files
65    if (binary_)
66      return;
67    std::string output(output_name() + ".html");
68    if (verbose)
69      std::cout << "Printing output for " << path_ << std::endl;
70    std::ofstream os(output.c_str());
71    print_header(os);
72    os << "<p align=center>\n<img src='" 
73       << file_name(stats_.plot(output_name()+".png",output_name()))
74       << "' alt='[plot]' border=0>\n</p>";
75
76    os << "<table class=\"listings\">\n";
77    os << "<thead>";
78    os << "<tr>\n";
79    os << "<th>Author</th>\n";
80    os << "<th>Lines</th>\n";
81    os << "<th>Code</th>\n";
82    os << "<th>Comments</th>\n";
83    os << "</tr>\n</thead>\n";
84    os << "<tbody>";
85
86    bool dark=false;
87    os << "<tr class=\"light\">\n";
88    os << "<td class=\"directory\" colspan=\"5\">";
89    anchor(os, "index.html", "../");
90    os << "</td>\n</tr>\n";
91    dark=!dark;
92   
93
94    // print authors
95    for (std::set<std::string>::const_iterator i=stats_.authors().begin();
96         i!=stats_.authors().end(); ++i){
97      if (dark)
98        os << "<tr class=\"dark\"><td>" << *i
99           << "</td><td>" << stats_.lines(*i)
100           << "</td><td>" << stats_.code(*i)
101           << "</td><td>" << stats_.comments(*i)
102           << "</td></tr>\n";
103      else
104        os << "<tr class=\"light\"><td>" << *i
105           << "</td><td>" << stats_.lines(*i)
106           << "</td><td>" << stats_.code(*i)
107           << "</td><td>" << stats_.comments(*i)
108           << "</td></tr>\n";
109      dark=!dark;
110    }
111    if (dark)
112      os << "<tr class=\"dark\">\n";
113    else
114      os << "<tr class=\"light\">\n";
115    os << "<td>Total</td>\n";
116    os << "<td>" << stats_.lines() << "</td>\n";
117    os << "<td>" << stats_.code() << "</td>\n";
118    os << "<td>" << stats_.comments() << "</td>\n";
119    os << "</tr>\n";
120    os << "</table>\n";
121    os << "</p>\n";
122
123    print_footer(os);
124    os.close(); 
125  }
126
127}} // end of namespace svndigest and namespace theplu
Note: See TracBrowser for help on using the repository browser.