changeset 28694:9a6fa1d93bc8

keyword: use templatefilter to mark a function as template filter This patch also adds test for filter 'svnisodate' and 'svnutcdate' for safety, because there is no test using them, yet.
author FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
date Wed, 30 Mar 2016 02:10:44 +0900
parents 11f623b5668f
children cc103bd0dbf9
files hgext/keyword.py tests/test-keyword.t
diffstat 2 files changed, 34 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/keyword.py	Wed Mar 30 02:10:44 2016 +0900
+++ b/hgext/keyword.py	Wed Mar 30 02:10:44 2016 +0900
@@ -104,6 +104,7 @@
     match,
     patch,
     pathutil,
+    registrar,
     scmutil,
     templatefilters,
     util,
@@ -137,28 +138,29 @@
     'kwfiles.ignoredunknown': 'none'
 }
 
+templatefilter = registrar.templatefilter()
+
 # date like in cvs' $Date
+@templatefilter('utcdate')
 def utcdate(text):
-    ''':utcdate: Date. Returns a UTC-date in this format: "2009/08/18 11:00:13".
+    '''Date. Returns a UTC-date in this format: "2009/08/18 11:00:13".
     '''
     return util.datestr((util.parsedate(text)[0], 0), '%Y/%m/%d %H:%M:%S')
 # date like in svn's $Date
+@templatefilter('svnisodate')
 def svnisodate(text):
-    ''':svnisodate: Date. Returns a date in this format: "2009-08-18 13:00:13
+    '''Date. Returns a date in this format: "2009-08-18 13:00:13
     +0200 (Tue, 18 Aug 2009)".
     '''
     return util.datestr(text, '%Y-%m-%d %H:%M:%S %1%2 (%a, %d %b %Y)')
 # date like in svn's $Id
+@templatefilter('svnutcdate')
 def svnutcdate(text):
-    ''':svnutcdate: Date. Returns a UTC-date in this format: "2009-08-18
+    '''Date. Returns a UTC-date in this format: "2009-08-18
     11:00:13Z".
     '''
     return util.datestr((util.parsedate(text)[0], 0), '%Y-%m-%d %H:%M:%SZ')
 
-templatefilters.filters.update({'utcdate': utcdate,
-                                'svnisodate': svnisodate,
-                                'svnutcdate': svnutcdate})
-
 # make keyword tools accessible
 kwtools = {'templater': None, 'hgcmd': ''}
 
--- a/tests/test-keyword.t	Wed Mar 30 02:10:44 2016 +0900
+++ b/tests/test-keyword.t	Wed Mar 30 02:10:44 2016 +0900
@@ -51,6 +51,31 @@
   Branch = {branches}
   $Branch: demobranch $
 
+(test template filter svnisodate and svnutcdate)
+
+  $ hg --quiet kwdemo --config keywordset.svn=True
+  [extensions]
+  keyword =
+  [keyword]
+  demo.txt = 
+  [keywordset]
+  svn = True
+  [keywordmaps]
+  Author = {author|user}
+  Date = {date|svnisodate}
+  Id = {file|basename},v {node|short} {date|svnutcdate} {author|user}
+  LastChangedBy = {author|user}
+  LastChangedDate = {date|svnisodate}
+  LastChangedRevision = {node|short}
+  Revision = {node|short}
+  $Author: test $
+  $Date: ????-??-?? ??:??:?? ????? (???, ?? ??? ????) $ (glob)
+  $Id: demo.txt,v ???????????? ????-??-?? ??:??:??Z test $ (glob)
+  $LastChangedBy: test $
+  $LastChangedDate: ????-??-?? ??:??:?? ????? (???, ?? ??? ????) $ (glob)
+  $LastChangedRevision: ???????????? $ (glob)
+  $Revision: ???????????? $ (glob)
+
   $ cat <<EOF >> $HGRCPATH
   > [keyword]
   > ** =