Ignore:
Timestamp:
Apr 9, 2007, 2:08:26 PM (14 years ago)
Author:
Peter Johansson
Message:

fixes #87 and #95 and #103 and #104 and #80 and #108, and refs #69

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/html_utility.cc

    r228 r234  
    2323
    2424#include "html_utility.h"
     25
     26#include "HtmlStream.h"
    2527#include "Stats.h"
     28#include "SVNlog.h"
    2629#include "utility.h"
    2730#include <config.h> // this header file is created by configure
    2831
     32#include <algorithm>
    2933#include <fstream>
    3034#include <iostream>
     
    4953  }
    5054
    51 
    5255 
    53   void html(std::istream& is, std::ostream& os, char delim)
    54   {
    55     char c;
    56     while (true){
    57       is.get(c);
    58       if (c==delim || !is.good()){
    59         return;
    60       }
    61       if (c=='"')
    62         os << '\"';
    63       else if (c=='\'')
    64         os << "\'";
    65       else if (c=='\n')
    66         os << "<br/>";
    67       else if (c=='<')
    68         os << "&lt;";
    69       else if (c=='>')
    70         os << "&gt;";
    71       else if (c=='&')
    72         os << "&amp;";
    73       else if (c=='\t')
    74         os << "&nbsp;&nbsp;";
    75       else if (c=='å')
    76         os << "&aring;";
    77       else if (c=='ä')
    78         os << "&auml;";
    79       else if (c=='ö')
    80         os << "&ouml;";
    81       else if (c=='Å')
    82         os << "&Aring;";
    83       else if (c=='Ä')
    84         os << "&Auml;";
    85       else if (c=='Ö')
    86         os << "&Ouml;";
    87       else if (c=='é')
    88         os << "&eacute;";
    89       else
    90         os << c;
    91     }
    92   }
    93  
    94 
    9556  void print_css(const std::string& str)
    9657  {
     
    261222
    262223
    263   void print_main_page(const std::string& dir,
    264                        const std::vector<std::string>& commit_dates,
     224  void print_main_page(const std::string& dir, const SVNlog& log,
    265225                       const Stats& stats)
    266226  {
    267227    std::string filename="index.html";
    268228    std::ofstream os(filename.c_str());
    269     print_header(os, dir, 0, "main", "index.html");
    270     time_t first = str2time(commit_dates[1]);
     229    print_header(os, dir, 0, "all", "main", "index.html");
     230
     231    using namespace std;
     232    map<string, time_t> latest_commit_date;
     233    assert(log.author().size()==log.date().size());
     234    typedef vector<string>::const_iterator iter;
     235    iter d=log.date().begin();
     236    for (iter a=log.author().begin();
     237         a!=log.author().end(); ++a, ++d) {
     238      latest_commit_date[*a]=str2time(*d);
     239    }
     240    // erase invalid authors
     241    latest_commit_date.erase("");
     242    latest_commit_date.erase("no author");
     243
     244    // vector of authors & date sorted with respect to date
     245    typedef vector<pair<string, time_t> > vector;
     246    vector author_date;
     247    author_date.reserve(latest_commit_date.size());
     248    back_insert_iterator<vector> i(author_date);
     249    copy(latest_commit_date.begin(), latest_commit_date.end(), i);
     250    sort(author_date.begin(), author_date.end(),
     251         pair_value_compare<string,time_t>());
     252
     253    print_general_information(os, log, author_date.size());
     254    print_authors(os, author_date, log, stats);
     255    print_recent_logs(os, log);
     256    os << "<hr width=100% />";
     257    print_footer(os);
     258    os.close();
     259
     260  }
     261
     262  void print_general_information(std::ostream& os, const SVNlog& log,
     263                                 size_t nof_authors)
     264  {
     265    time_t first = str2time(log.date()[1]);
    271266    std::string first_date = asctime(gmtime(&first));
    272     time_t last = str2time(commit_dates.back());
     267    time_t last = str2time(log.date().back());
    273268    std::string last_date = asctime(gmtime(&last));
    274269   
     
    310305
    311306    now = time(NULL);
    312     os << "<div class=\"main\">\n"
     307    os << "<div class=\"main\">"
    313308       << "<table class=\"main\"><thead><tr><th colspan=\"2\">"
    314309       << "General Information"
    315        << "</th></tr><thead>\n"
     310       << "</th></tr></thead>\n"
    316311       << "<tr><td>First Revision:</td><td>"
    317312       << first_date << "</td></tr>\n"
     
    340335     
    341336    os << "</td></tr>\n"
    342        << "<tr><td>Number of Authors:</td><td>" << stats.authors().size()
     337       << "<tr><td>Number of Authors:</td><td>" << nof_authors
    343338       << "</td></tr>\n"
    344        << "<tr><td>Revisions:</td><td>" << commit_dates.size()-1
     339       << "<tr><td>Revisions:</td><td>" << log.revision().size()-1
    345340       << "</td></tr>\n"
    346341       << "</table></div>\n";
    347     os << "<hr width=100% />";
    348    
    349        
    350     print_footer(os);
    351     os.close();
    352342  }
    353343
     
    367357
    368358
    369   void print_header(std::ostream& os, const std::string& title, u_int level,
    370                     const std::string& item, const std::string& path)
     359  void print_header(std::ostream& os, std::string title, u_int level,
     360                    std::string user, std::string item, std::string path)
    371361  {
    372362    os << "<!DOCTYPE html\n"
     
    397387    else
    398388      os << "<li>";
    399     anchor(os, "all/total/"+path, "Total", level,
     389    anchor(os, user+"/total/"+path, "Total", level,
    400390           "View statistics of all lines");
    401391    os << "</li>";
     
    405395    else
    406396      os << "<li>";
    407     anchor(os, "all/code/"+path, "Code", level,
     397    anchor(os, user+"/code/"+path, "Code", level,
    408398           "View statistics of code lines");
    409399    os << "</li>";
     
    413403    else
    414404      os << "<li>";
    415     anchor(os, "all/comments/"+path, "Comment", level,
     405    anchor(os, user+"/comments/"+path, "Comment", level,
    416406           "View statistics of comment lines");
    417407    os << "</li>";
     
    422412    else
    423413      os << "<li>";
    424     anchor(os, "all/empty/"+path, "Empty", level,
     414    anchor(os, user+"/empty/"+path, "Empty", level,
    425415           "View statistics of empty lines");
    426416    os << "</li>"
     
    430420
    431421
     422  void print_authors(std::ostream& os,
     423                     const std::vector<std::pair<std::string,time_t> >& ad,
     424                     const SVNlog& log, const Stats& stats)
     425  {
     426    os << "<div class=\"main\">"
     427       << "<table class=\"main\"><thead><tr><th colspan=\"2\">"
     428       << "Authors"
     429       << "</th></tr></thead>\n";
     430
     431    os << "<tr><td>Author</td>"
     432       << "<td>Number of Lines</td>"
     433       << "<td>Code Lines</td>"
     434       << "<td>Comment Lines</td>"
     435       << "<td>Latest Commitment</td>"
     436       <<"</tr>";
     437
     438    using namespace std;
     439    for (vector<pair<string,time_t> >::const_reverse_iterator i=ad.rbegin();
     440         i!=ad.rend(); ++i) {
     441      os << "<tr><td>";
     442      anchor(os, string(i->first+"/total/index.html"),i->first);
     443      os << "</td><td>" << stats.lines(i->first) << " ("
     444         << 100*stats.lines(i->first)/stats.lines() << "%)</td>"
     445         << "<td>" << stats.code(i->first) << " ("
     446         << 100*stats.code(i->first)/stats.code() << "%)</td>"
     447         << "<td>" << stats.comments(i->first) << " ("
     448         << 100*stats.comments(i->first)/stats.comments() << "%)</td>"
     449         << "<td>" << asctime(gmtime(&i->second)) << "</td>"
     450         <<"</tr>";
     451    }
     452
     453    os << "</table></div>\n";
     454   
     455  }
     456
     457
     458  void print_recent_logs(std::ostream& os, const SVNlog& log)
     459  {
     460    os << "<div class=\"main\">\n"
     461       << "<table class=\"main\"><thead><tr><th colspan=\"2\">"
     462       << "Recent Log"
     463       << "</th></tr></thead>\n";
     464
     465    std::vector<std::string>::const_reverse_iterator a=log.author().rbegin();
     466    std::vector<std::string>::const_reverse_iterator d=log.date().rbegin();
     467    std::vector<std::string>::const_reverse_iterator m=log.message().rbegin();
     468    assert(log.author().size()==log.date().size());
     469    assert(log.author().size()==log.message().size());
     470    HtmlStream hs(os);
     471    for (size_t i=0; i<10 && a!=log.author().rend(); ++i) {
     472      os << "<tr><td>" << *a << "</td>";
     473      time_t date = str2time(*d);
     474      os << "<td>" << asctime(gmtime(&date)) << "</td>";
     475      os << "<td>";
     476      hs << *m;
     477      os << "</td></tr>";
     478      ++a;
     479      ++d;
     480      ++m;
     481    }
     482    os << "</table></div>\n";
     483  }
     484
    432485}} // end of namespace svndigest and namespace theplu
Note: See TracChangeset for help on using the changeset viewer.