Ignore:
Timestamp:
May 6, 2007, 9:03:28 PM (14 years ago)
Author:
Peter Johansson
Message:

moving first page generation to separate file.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/html_utility.cc

    r284 r285  
    2424#include "html_utility.h"
    2525
    26 #include "Commitment.h"
    2726#include "Configuration.h"
    2827#include "Date.h"
    2928#include "HtmlStream.h"
    30 #include "Stats.h"
    31 #include "SVNlog.h"
    32 #include "utility.h"
    3329#include <config.h> // this header file is created by configure
    3430
    35 #include <algorithm>
    36 #include <cassert>
    37 #include <fstream>
    38 #include <iostream>
    3931#include <sstream>
    40 #include <stdexcept>
    4132#include <string>
    42 #include <sys/param.h>
    43 #include <unistd.h>
    44 #include <vector>
    4533
    4634namespace theplu{
     
    6654
    6755 
    68   void print_main_page(const std::string& dir, const SVNlog& log,
    69                        const Stats& stats)
    70   {
    71     std::string filename="index.html";
    72     std::ofstream os(filename.c_str());
    73     print_header(os, dir, 0, "all", "main", "index.html");
    74 
    75     using namespace std;
    76     set<string> authors;
    77     authors.insert(log.author().begin(), log.author().end());
    78     // erase invalid authors
    79     authors.erase("");
    80     authors.erase("no author");
    81 
    82     vector<Commitment> latest_commit;
    83     latest_commit.reserve(authors.size());
    84     for (set<string>::const_iterator i(authors.begin()); i!=authors.end(); ++i)
    85       latest_commit.push_back(log.latest_commit(*i));
    86 
    87     print_general_information(os, log, authors.size());
    88     sort(latest_commit.begin(), latest_commit.end(), GreaterRevision());
    89     print_authors(os, latest_commit, stats);
    90     print_recent_logs(os, log);
    91     os << "<hr width=100% />";
    92     print_footer(os);
    93     os.close();
    94 
    95   }
    96 
    97   void print_general_information(std::ostream& os, const SVNlog& log,
    98                                  size_t nof_authors)
    99   {
    100     Date begin(log.date()[0]);
    101     if (log.date().size()>1)
    102       begin = std::min(begin, Date(log.date()[1]));
    103     Date end(log.date().back());
    104     Date now;
    105     std::string timefmt("%a, %e %b %Y");
    106 
    107     os << "<div class=\"main\">"
    108        << "<table class=\"main\"><thead><tr><th colspan=\"2\">"
    109        << "General Information"
    110        << "</th></tr></thead>\n"
    111        << "<tr><td>First Revision:</td><td>"
    112        << begin(timefmt) << "</td></tr>\n"
    113        << "<tr><td>Latest Revision:</td><td>"
    114        << end(timefmt) << "</td></tr>\n"
    115        << "<tr><td>Report Generated:</td><td>"
    116        << now(timefmt) << "</td></tr>\n"
    117        << "<tr><td>Repository Age:</td><td>";
    118     os << now.difftime(begin);
    119     os << "</td></tr>\n"
    120        << "<tr><td>Number of Authors:</td><td>" << nof_authors
    121        << "</td></tr>\n"
    122        << "<tr><td>Revisions:</td><td>" << log.revision().size()
    123        << "</td></tr>\n"
    124        << "</table></div>\n";
    125   }
    126 
    127 
    12856  void print_footer(std::ostream& os)
    12957  {
     
    200128
    201129
    202   void print_authors(std::ostream& os,
    203                      const std::vector<Commitment>& lc,
    204                      const Stats& stats)
    205   {
    206     os << "<div class=\"main\">"
    207        << "<table class=\"main\"><thead><tr><th colspan=\"2\">"
    208        << "Authors"
    209        << "</th></tr></thead>\n";
    210 
    211     os << "<tr><td>Author</td>"
    212        << "<td>Number of Lines</td>"
    213        << "<td>Code Lines</td>"
    214        << "<td>Comment Lines</td>"
    215        << "<td>Latest Commitment</td>"
    216        <<"</tr>";
    217 
    218     std::string timefmt("%b %d %H:%M:%S %Y");
    219     using namespace std;
    220     for (vector<Commitment>::const_iterator i=lc.begin(); i!=lc.end(); ++i) {
    221       os << "<tr><td>"
    222          << anchor(string(i->author()+"/total/index.html"),i->author())
    223          << "</td><td>" << stats.lines(i->author()) << " ("
    224          << 100*stats.lines(i->author())/stats.lines() << "%)</td>"
    225          << "<td>" << stats.code(i->author()) << " ("
    226          << 100*stats.code(i->author())/stats.code() << "%)</td>"
    227          << "<td>" << stats.comments(i->author()) << " ("
    228          << 100*stats.comments(i->author())/stats.comments() << "%)</td>"
    229          << "<td>" << i->date()(timefmt) << "</td>"
    230          <<"</tr>";
    231     }
    232 
    233     os << "</table></div>\n";
    234    
    235   }
    236 
    237 
    238   void print_recent_logs(std::ostream& os, const SVNlog& log)
    239   {
    240     os << "<div class=\"main\">\n"
    241        << "<table class=\"main\"><thead><tr><th colspan=\"2\">"
    242        << "Recent Log"
    243        << "</th></tr></thead>\n";
    244 
    245     std::vector<std::string>::const_reverse_iterator a=log.author().rbegin();
    246     std::vector<std::string>::const_reverse_iterator d=log.date().rbegin();
    247     std::vector<std::string>::const_reverse_iterator m=log.message().rbegin();
    248     std::vector<size_t>::const_reverse_iterator r=log.revision().rbegin();
    249     assert(log.author().size()==log.date().size());
    250     assert(log.author().size()==log.message().size());
    251     assert(log.author().size()==log.revision().size());
    252     os << "<tr><td>Author</td><td>Date</td><td>Rev</td><td>Message</td></tr>\n";
    253     HtmlStream hs(os);
    254     std::string timefmt("%b %d %H:%M:%S %Y");
    255     const size_t maxlength = 80;
    256     const Configuration* conf = Configuration::instance();
    257     for (size_t i=0; i<10 && a!=log.author().rend(); ++i) {
    258       os << "<tr><td>" << anchor(*a+"/total/index.html",*a) << "</td>";
    259       Date date(*d);
    260       os << "<td>" << date(timefmt) << "</td>";
    261       os << "<td>";
    262       os << trac_revision(*r);
    263       os << "</td>";
    264       os << "<td>";
    265       std::string mess = *m;
    266       // replace newlines with space
    267       std::replace(mess.begin(), mess.end(), '\n', ' ');
    268       mess = htrim(mess);
    269       // truncate message if too long
    270       if (mess.size()>maxlength)
    271         mess = mess.substr(0,maxlength-3) + "...";
    272 
    273       if (conf->trac_ticket().empty())
    274         hs << mess;
    275       else { // make anchors to trac
    276         char c;
    277         std::stringstream ss(mess);
    278         for (ss.get(c); ss.good(); ss.get(c)) {
    279           if (c=='#') {
    280             int ticket=0;
    281             ss >> ticket;
    282             if (!ss.fail()){
    283               std::stringstream s;
    284               s << ticket;
    285               os << anchor(conf->trac_ticket()+s.str(),"#"+s.str());
    286             }
    287             else {
    288               ss.clear(std::ios::goodbit);
    289               hs << c;
    290             }
    291           }
    292           else
    293             hs << c;
    294         }
    295       }
    296 
    297       os << "</td></tr>";
    298       ++a;
    299       ++d;
    300       ++m;
    301       ++r;
    302     }
    303     os << "</table></div>\n";
    304   }
    305 
    306 
    307130  std::string trac_revision(size_t r)
    308131  {
Note: See TracChangeset for help on using the changeset viewer.