Changeset 274 for trunk


Ignore:
Timestamp:
May 2, 2007, 11:05:55 AM (14 years ago)
Author:
Peter Johansson
Message:

support for Trac. Fixes #125. Also added a config file.

Location:
trunk
Files:
2 added
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/Configuration.cc

    r264 r274  
    3131#include <string>
    3232#include <sstream>
     33#include <utility>
    3334
    3435namespace theplu{
     
    7374        copyright_alias_[key] = name;
    7475      }
     76      else if (section == "trac"){
     77        getline(ss, tmp, '=');
     78        std::string key = trim(tmp);
     79        getline(ss, tmp);
     80        std::string value = trim(tmp);
     81        if (key=="trac-ticket")
     82          trac_ticket_=value;
     83        if (key=="trac-revision")
     84          trac_revision_=value;
     85       
     86      }
    7587    }
    7688  }
     
    88100  {
    89101    copyright_alias_.clear();
     102    trac_ticket_ = "";
     103    trac_revision_ = "";
    90104  }
    91105
     
    106120      os << i->first << " = " << i->second << " \n";
    107121    }
     122
     123    os << "\n"
     124       << "### Section for setting trac environment\n"
     125       << "[trac]\n"
     126       << "# If trac-ticket is set, svndigest will create anchors for\n"
     127       << "# ticket to the Trac page.\n"
     128       << "trac-ticket = " << conf.trac_ticket() << "\n";
     129    os << "# If trac-revision is set, svndigest will create anchors for\n"
     130       << "# revisions to the Trac page.\n"
     131       << "trac-revision = " << conf.trac_revision() << "\n";
     132
    108133    return os;
    109134  }
  • trunk/lib/Configuration.h

    r264 r274  
    2828#include <map>
    2929#include <string>
     30#include <utility>
    3031
    3132namespace theplu{
    3233namespace svndigest{
    3334
     35  ///
     36  /// Configuration class takes care of all setting defined in the
     37  /// configuration file.
     38  ///
    3439  class Configuration
    3540  {
     
    5358    copyright_alias(void) const { return copyright_alias_; }
    5459
     60    ///
     61    /// @return root for the trac envrionment, e.g.,
     62    /// http://lev.thep.lu.se/trac/svndigest/ticket/
     63    ///
     64    inline std::string trac_ticket(void) const { return trac_ticket_; }
     65
     66    ///
     67    /// @return root for the trac envrionment, e.g.,
     68    /// http://lev.thep.lu.se/trac/svndigest/ticket/
     69    ///
     70    std::string trac_revision(void) const { return trac_revision_; }
     71
    5572  private:
    5673    ///
     
    6077    ///
    6178    Configuration(void);
     79    // Copy Constructor not implemented
     80    Configuration(const Configuration&);
    6281
    6382    void clear(void);
     
    6988    std::map<std::string, std::string> copyright_alias_;
    7089
     90    std::string trac_ticket_;
     91    std::string trac_revision_;
     92   
    7193  };
    7294
  • trunk/lib/Date.cc

    r235 r274  
    208208          else
    209209            ss << timeinfo->tm_wday;
    210         else if (*i == 'y')
    211           ss << timeinfo->tm_year % 100;
     210        else if (*i == 'y') {
     211          int y(timeinfo->tm_year % 100);
     212          if (y<10)
     213            ss << "0";
     214          ss << y;
     215        }
    212216        else if (*i == 'Y')
    213217          ss << timeinfo->tm_year+1900;
  • trunk/lib/Directory.cc

    r259 r274  
    209209      os << "<td>" << stats_.empty(user) << "</td>\n";
    210210    }
    211     os << "<td>" << stats_.last_changed_rev() << "</td>\n";
     211    os << "<td>" << trac_revision(stats_.last_changed_rev()) << "</td>\n";
    212212    os << "<td>" << author() << "</td>\n";
    213213    os << "</tr>\n";
  • trunk/lib/Node.cc

    r259 r274  
    116116         << "<td>" << stats_.empty(user) << "</td>\n";
    117117    }
    118     os << "<td>" << stats_.last_changed_rev() << "</td>\n"
     118    os << "<td>" << trac_revision(stats_.last_changed_rev()) << "</td>\n"
    119119       << "<td>" << author() << "</td>\n"
    120120       << "</tr>\n";
     
    195195         << "</td><td>" << stats_.empty(*i);
    196196      Commitment lc(log.latest_commit(*i));
    197       os << "</td>" << "<td>" << lc.revision()
     197      os << "</td>" << "<td>" << trac_revision(lc.revision())
    198198         << "</td>" << "<td>" << lc.date()(timefmt)
    199199         << "</td></tr>\n";
     
    214214    os << "<td>" << stats_.empty() << "</td>\n";
    215215    Commitment lc(log.latest_commit());
    216     os << "<td>" << lc.revision() << "</td>\n";
     216    os << "<td>" << trac_revision(lc.revision()) << "</td>\n";
    217217    os << "<td>" << lc.date()(timefmt)<< "</td>\n";
    218218    os << "</tr>\n";
  • trunk/lib/html_utility.cc

    r263 r274  
    2525
    2626#include "Commitment.h"
     27#include "Configuration.h"
    2728#include "Date.h"
    2829#include "HtmlStream.h"
     
    421422    std::string timefmt("%b %d %H:%M:%S %Y");
    422423    const size_t maxlength = 80;
     424    const Configuration* conf = Configuration::instance();
    423425    for (size_t i=0; i<10 && a!=log.author().rend(); ++i) {
    424426      os << "<tr><td>" << anchor(*a+"/total/index.html",*a) << "</td>";
    425427      Date date(*d);
    426428      os << "<td>" << date(timefmt) << "</td>";
    427       os << "<td>" << *r << "</td>";
     429      os << "<td>";
     430      os << trac_revision(*r);
     431      os << "</td>";
    428432      os << "<td>";
    429433      std::string mess = *m;
     
    434438      if (mess.size()>maxlength)
    435439        mess = mess.substr(0,maxlength-3) + "...";
    436       hs << mess;
     440
     441      if (conf->trac_ticket().empty())
     442        hs << mess;
     443      else { // make anchors to trac
     444        char c;
     445        std::stringstream ss(mess);
     446        for (ss.get(c); ss.good(); ss.get(c)) {
     447          if (c=='#') {
     448            std::string str;
     449            ss >> str;
     450            if (is_int(str))
     451              os << anchor(conf->trac_ticket()+str,"#"+str);
     452            else
     453              hs << "#" << str;
     454          }
     455          else
     456            hs << c;
     457        }
     458      }
     459
    437460      os << "</td></tr>";
    438461      ++a;
     
    444467  }
    445468
     469
     470  std::string trac_revision(size_t r)
     471  {
     472    Configuration* conf = Configuration::instance();
     473    std::stringstream ss;
     474    if (conf->trac_revision().empty())
     475      ss << r;
     476    else {
     477      std::stringstream rev;
     478      rev << r;
     479      ss << anchor(conf->trac_revision()+rev.str(), rev.str());
     480    }
     481    return ss.str();
     482  }
     483
    446484}} // end of namespace svndigest and namespace theplu
  • trunk/lib/html_utility.h

    r256 r274  
    8989
    9090
     91  ///
     92  /// @return if trac-revision is set in config file anchor to trac is
     93  /// given otherwise just a string corresponding to passed parameter.
     94  ///
     95  std::string trac_revision(size_t);
     96
    9197}} // end of namespace svndigest end of namespace theplu
    9298
  • trunk/lib/utility.cc

    r226 r274  
    8888
    8989
     90  bool is_int(std::string s)
     91  {
     92    std::stringstream ss(s);
     93    int a;
     94    ss >> a;
     95    if(ss.fail())
     96      return false;
     97    // Check that nothing is left on stream
     98    std::string b;
     99    ss >> b;
     100    return b.empty();
     101  }
     102
     103
    90104  std::string ltrim(std::string str)
    91105  {
  • trunk/lib/utility.h

    r234 r274  
    6868  ///
    6969  std::string htrim(std::string str);
     70
     71  ///
     72  /// @return true if \a str is an integer
     73  ///
     74  bool is_int(std::string str);
    7075
    7176  ///
Note: See TracChangeset for help on using the changeset viewer.