Part of #6: show changed files + line counts in updated feed
authorChristian Weiske <cweiske@cweiske.de>
Fri, 26 Oct 2012 05:59:17 +0000 (07:59 +0200)
committerChristian Weiske <cweiske@cweiske.de>
Fri, 26 Oct 2012 05:59:17 +0000 (07:59 +0200)
data/templates/feed-updated.htm
www/www-header.php

index 699dabd..ff1d609 100644 (file)
   <id>{{repo.getLink('display', null, true)}}</id>
   <title>{{repo.getTitle}}</title>
   <published>{{repo.crdate|date('c')}}</published>
-  <updated>{{repo.modate|date('c')}}</updated>
+  {% set commit = repo.getHistory().0 %}
+  <updated>{{commit.committerTime|date('c')}}</updated>
   <link rel="alternate" type="text/html" href="{{repo.getLink('display', null, true)}}" />
   <author>
-   {% set owner=repo.getOwner() %}
-   <name>{{owner.name}}</name>
-   <email>{{owner.email}}</email>
+   <name>{{commit.committerName}}</name>
+   <email>{{commit.committerEmail}}</email>
   </author>
+  <summary>{% spaceless %}
+   {% if commit.filesChanged %}
+     {{ntext(commit.filesChanged, "%d file", "%d files")}} changed{% if commit.linesAdded %},{% endif %}
+   {% endif %}
+   {% if commit.linesAdded %}
+     {{ntext(commit.linesAdded, "%d line", "%d lines")}} added{% if commit.linesDeleted %},{% endif %}
+   {% endif %}
+   {% if commit.linesDeleted %}
+     {{ntext(commit.linesDeleted, "%d line", "%d lines")}} deleted
+   {% endif %}
+  {% endspaceless %}</summary>
  </entry>
 {% endfor %}
 </feed>
\ No newline at end of file
index 9aa8732..41b5e47 100644 (file)
@@ -68,6 +68,14 @@ $twig = new \Twig_Environment(
         'debug' => true
     )
 );
+$twig->addFunction('ntext', new \Twig_Function_Function('\phorkie\ntext'));
+function ntext($value, $singular, $plural)
+{
+    if (abs($value) == 1) {
+        return sprintf($singular, $value);
+    }
+    return sprintf($plural, $value);
+}
 //$twig->addExtension(new \Twig_Extension_Debug());
 
 if (!isset($noSecurityCheck) || $noSecurityCheck !== true) {