source: trunk/lib/File.cc @ 181

Last change on this file since 181 was 181, checked in by Peter Johansson, 16 years ago

using anchor function

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