// $Id: html_utility.cc 1099 2010-06-13 17:15:47Z peter $ /* Copyright (C) 2006 Peter Johansson Copyright (C) 2007, 2008 Jari Häkkinen, Peter Johansson Copyright (C) 2009, 2010 Peter Johansson This file is part of svndigest, http://dev.thep.lu.se/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 3 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 svndigest. If not, see . */ #include #include "html_utility.h" #include "Configuration.h" #include "Date.h" #include "HtmlStream.h" #include "subversion_info.h" #include #include #include namespace theplu{ namespace svndigest{ std::string anchor(const std::string& url, const std::string& name, unsigned int level, const std::string& title, const std::string& color) { std::stringstream ss; HtmlStream hs(ss); ss << ""; if (color.size()) ss << ""; hs << name; if (color.size()) ss << ""; ss << ""; return ss.str(); } std::string image(const std::string& name) { std::ostringstream os; const std::string& format = Configuration::instance().image_format(); const std::string& anchor_format = Configuration::instance().image_anchor_format(); if (format=="svg") { os << "\n" << "\n" << "\n"; if (anchor_format != "svg") std::cerr << "svndigest: anchor_format: " << anchor_format << " not supported with format " << format << "\n"; } else if (format=="png") { if (anchor_format=="none") os << "[plot]"; else os << "" << "[plot]" << ""; } else if (format=="none") os << ""; else { assert(false); throw std::runtime_error("unknown image format: " + format); } return os.str(); } void print_footer(std::ostream& os) { Date date; HtmlStream hs(os); os << "

\nGenerated on "; hs << date("%a %b %e %H:%M:%S %Y") << " (UTC) by "; os << anchor(PACKAGE_URL, PACKAGE_STRING, 0, ""); if (DEV_BUILD) os << " (dev build " << svn_revision() << ")"; os << "\n

\n\n\n\n"; } void print_header(std::ostream& os, std::string title, unsigned int level, std::string user, std::string item, std::string path, const std::string& stats) { print_html_start(os, title, level); os << "
" << "
    \n
  • \n"; if (item=="main") os << "
  • "; else os << "
  • "; os << anchor("index.html", "Main", level, "Main page"); os << "
  • \n"; std::string stats_local(stats); if (stats_local=="none") stats_local = "classic"; if (item=="total") os << "
  • "; else os << "
  • \n"; os << anchor(stats_local+"/"+user+"/total/"+path, "Total", level, "View statistics of all lines"); os << "
  • \n"; if (item=="code") os << "
  • "; else os << "
  • "; os << anchor(stats_local+"/"+user+"/code/"+path, "Code", level, "View statistics of code lines"); os << "
  • \n"; if (item=="comments") os << "
  • "; else os << "
  • "; os << anchor(stats_local+"/"+user+"/comments/"+path, "Comment", level, "View statistics of comment lines"); os << "
  • \n"; if (item=="empty") os << "
  • "; else os << "
  • "; os << anchor(stats_local+"/"+user+"/empty/"+path, "Other", level, "View statistics of other lines"); os << "
  • \n"; os << "
  • "; // Peter, this is ugly! But how to add space? for (size_t i=0; i<50; ++i) os << " "; os << "
  • \n"; std::string item_local(item); if (item_local=="none") item_local = "total"; if (item_local=="main") item_local = "total"; if (stats=="classic") os << "
  • "; else os << "
  • "; os << anchor("classic/"+user+"/"+item_local+"/"+path, "Classic", level, "View classic statistics"); os << "
  • \n"; if (stats=="blame") os << "
  • "; else os << "
  • "; os << anchor("blame/"+user+"/"+item_local+"/"+path, "Blame", level, "View blame statistics"); os << "
  • \n"; if (stats=="add") os << "
  • "; else os << "
  • "; os << anchor("add/"+user+"/"+item_local+"/"+path, "Add", level, "View add statistics"); os << "
  • \n"; os << "\n" << "
\n" << "
\n"; } void print_html_start(std::ostream& os, const std::string& title, unsigned int level) { os << "\n"; os << "\n" << "\n" << "\n" << " " << title << " - svndigest\n" << "\n" << "\n" << "\n" << "\n"; } std::string trac_revision(svn_revnum_t r, std::string color) { const Configuration& conf = Configuration::instance(); std::stringstream ss; if (conf.trac_root().empty()) ss << r; else { std::stringstream rev; rev << r; ss << anchor(conf.trac_root()+"changeset/"+rev.str(), rev.str(), 0, "View ChangeSet "+rev.str(), color); } return ss.str(); } }} // end of namespace svndigest and namespace theplu