// $Id: first_page.cc 479 2007-09-11 22:21:18Z jari $ /* Copyright (C) 2006 Peter Johansson Copyright (C) 2007 Jari Häkkinen, Peter Johansson This file is part of svndigest, http://trac.thep.lu.se/trac/svndigest svndigest is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. svndigest is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "first_page.h" #include "Commitment.h" #include "Configuration.h" #include "Date.h" #include "HtmlStream.h" #include "html_utility.h" #include "Stats.h" #include "SVNlog.h" #include "Trac.h" #include "utility.h" #include // this header file is created by configure #include #include #include #include #include #include #include #include #include #include namespace theplu{ namespace svndigest{ void print_main_page(const std::string& dir, const SVNlog& log, const Stats& stats, std::string url) { std::string filename="index.html"; std::ofstream os(filename.c_str()); print_header(os, dir, 0, "all", "main", "index.html"); using namespace std; set authors; authors.insert(log.author().begin(), log.author().end()); // erase invalid authors authors.erase(""); authors.erase("no author"); vector latest_commit; latest_commit.reserve(authors.size()); for (set::const_iterator i(authors.begin()); i!=authors.end(); ++i) latest_commit.push_back(log.latest_commit(*i)); print_summary_plot(os, stats); print_general_information(os, log, authors.size(), url); sort(latest_commit.begin(), latest_commit.end(), GreaterRevision()); print_authors(os, latest_commit, stats); print_recent_logs(os, log); os << "
"; print_footer(os); os.close(); } void print_general_information(std::ostream& os, const SVNlog& log, size_t nof_authors, std::string url) { Date begin(log.date()[0]); Date end(log.date().back()); std::string timefmt("%a, %e %b %Y %H:%M:%S"); os << "
" << "\n" << "\n" << "\n" << "\n" << "\n" << "\n" << "\n" << "\n" << "\n" << "\n" << "\n" << "
" << "General Information" << "
URL:" << url << "
First Revision Date:" << begin(timefmt) << "
Latest Revision Date:" << end(timefmt) << "
Age:"; os << end.difftime(begin); os << "
Smallest Revision:" << log.revision()[0] << "
Largest Revision:" << log.revision().back() << "
Revision Count:" << log.revision().size() << "
Number of Authors:" << nof_authors << "
\n"; } void print_authors(std::ostream& os, const std::vector& lc, const Stats& stats) { os << "
" << "\n"; os << "" << "" << "" << "" << "" <<""; std::string timefmt("%b %d %H:%M:%S %Y"); using namespace std; for (vector::const_iterator i=lc.begin(); i!=lc.end(); ++i) { os << "" <<""; } os << ""; os << "" << "" << "" <<""; os << "
" << "Authors" << "
AuthorNumber of LinesCode LinesComment LinesLatest Commitment
"; if (!stats.lines(i->author())) os << i->author(); else os << anchor(string(i->author()+"/total/index.html"),i->author()); os << "" << stats.lines(i->author()) << " (" << 100*stats.lines(i->author())/(stats.lines()?stats.lines():1) << "%)" << stats.code(i->author()) << " (" << 100*stats.code(i->author())/(stats.code()?stats.code():1) << "%)" << stats.comments(i->author()) << " (" << 100*stats.comments(i->author())/(stats.comments()?stats.comments():1) << "%)" << i->date()(timefmt) << "
Total" << stats.lines() << "" << stats.code() << "" << stats.comments() << "
\n"; } void print_recent_logs(std::ostream& os, const SVNlog& log) { os << "
\n" << "\n"; std::vector::const_reverse_iterator a=log.author().rbegin(); std::vector::const_reverse_iterator d=log.date().rbegin(); std::vector::const_reverse_iterator m=log.message().rbegin(); std::vector::const_reverse_iterator r=log.revision().rbegin(); assert(log.author().size()==log.date().size()); assert(log.author().size()==log.message().size()); assert(log.author().size()==log.revision().size()); os << "\n"; HtmlStream hs(os); std::string timefmt("%b %d %H:%M:%S %Y"); const size_t maxlength = 80; const Configuration& conf = Configuration::instance(); for (size_t i=0; i<10 && a!=log.author().rend(); ++i) { os << ""; Date date(*d); os << ""; os << ""; os << "\n"; ++a; ++d; ++m; ++r; } os << "
" << "Recent Log" << "
AuthorDateRevMessage
" << anchor(*a+"/total/index.html",*a) << "" << date(timefmt) << ""; os << trac_revision(*r); os << ""; std::string mess = *m; // replace newlines with space std::replace(mess.begin(), mess.end(), '\n', ' '); mess = htrim(mess); if (conf.trac_root().empty()) { // truncate message if too long if (mess.size()>maxlength) mess = mess.substr(0,maxlength-3) + "..."; hs << mess; } else {// make anchors to trac Trac trac(hs); trac.print(mess, maxlength); } os << "
\n"; } void print_summary_plot(std::ostream& os, const Stats& stats) { std::string name("summary_plot.png"); stats.plot_summary(name); os << "
\n"; os << "[plot]"; os << "
"; } }} // end of namespace svndigest and namespace theplu