##// END OF EJS Templates
templatefilters: declare input type as date where appropriate...
Yuya Nishihara -
r37244:9bcf096a default
parent child Browse files
Show More
@@ -333,7 +333,7 b' class templatefilter(_templateregistrarb'
333 333 The first string argument is used also in online help.
334 334
335 335 Optional argument 'intype' defines the type of the input argument,
336 which should be (bytes, int, or None for any.)
336 which should be (bytes, int, templateutil.date, or None for any.)
337 337
338 338 'templatefilter' instance in example above can be used to
339 339 decorate multiple functions.
@@ -55,7 +55,7 b' agescales = [("year", 3600 * 24 * 365, \''
55 55 ("minute", 60, 'm'),
56 56 ("second", 1, 's')]
57 57
58 @templatefilter('age')
58 @templatefilter('age', intype=templateutil.date)
59 59 def age(date, abbrev=False):
60 60 """Date. Returns a human-readable date/time difference between the
61 61 given date/time and the current date/time.
@@ -195,21 +195,21 b' def hexfilter(text):'
195 195 """
196 196 return node.hex(text)
197 197
198 @templatefilter('hgdate')
198 @templatefilter('hgdate', intype=templateutil.date)
199 199 def hgdate(text):
200 200 """Date. Returns the date as a pair of numbers: "1157407993
201 201 25200" (Unix timestamp, timezone offset).
202 202 """
203 203 return "%d %d" % text
204 204
205 @templatefilter('isodate')
205 @templatefilter('isodate', intype=templateutil.date)
206 206 def isodate(text):
207 207 """Date. Returns the date in ISO 8601 format: "2009-08-18 13:00
208 208 +0200".
209 209 """
210 210 return dateutil.datestr(text, '%Y-%m-%d %H:%M %1%2')
211 211
212 @templatefilter('isodatesec')
212 @templatefilter('isodatesec', intype=templateutil.date)
213 213 def isodatesec(text):
214 214 """Date. Returns the date in ISO 8601 format, including
215 215 seconds: "2009-08-18 13:00:13 +0200". See also the rfc3339date
@@ -303,14 +303,14 b' def revescape(text):'
303 303 """
304 304 return urlreq.quote(text, safe='/@').replace('/', '%252F')
305 305
306 @templatefilter('rfc3339date')
306 @templatefilter('rfc3339date', intype=templateutil.date)
307 307 def rfc3339date(text):
308 308 """Date. Returns a date using the Internet date format
309 309 specified in RFC 3339: "2009-08-18T13:00:13+02:00".
310 310 """
311 311 return dateutil.datestr(text, "%Y-%m-%dT%H:%M:%S%1:%2")
312 312
313 @templatefilter('rfc822date')
313 @templatefilter('rfc822date', intype=templateutil.date)
314 314 def rfc822date(text):
315 315 """Date. Returns a date using the same format used in email
316 316 headers: "Tue, 18 Aug 2009 13:00:13 +0200".
@@ -335,7 +335,7 b' def shortbisect(label):'
335 335 return label[0:1].upper()
336 336 return ' '
337 337
338 @templatefilter('shortdate')
338 @templatefilter('shortdate', intype=templateutil.date)
339 339 def shortdate(text):
340 340 """Date. Returns a date like "2006-09-18"."""
341 341 return dateutil.shortdate(text)
@@ -26,6 +26,11 b' class ResourceUnavailable(error.Abort):'
26 26 class TemplateNotFound(error.Abort):
27 27 pass
28 28
29 # stub for representing a date type; may be a real date type that can
30 # provide a readable string value
31 class date(object):
32 pass
33
29 34 class hybrid(object):
30 35 """Wrapper for list or dict to support legacy template
31 36
@@ -361,6 +366,7 b' def evalstringliteral(context, mapping, '
361 366 _unwrapfuncbytype = {
362 367 None: _unwrapvalue,
363 368 bytes: stringify,
369 date: unwrapdate,
364 370 int: unwrapinteger,
365 371 }
366 372
@@ -2806,7 +2806,8 b' Behind the scenes, this would throw Type'
2806 2806 Behind the scenes, this will throw a ValueError
2807 2807
2808 2808 $ hg log -l 3 --template 'line: {desc|shortdate}\n'
2809 abort: template filter 'shortdate' is not compatible with keyword 'desc'
2809 hg: parse error: invalid date: 'Modify, add, remove, rename'
2810 (template filter 'shortdate' is not compatible with keyword 'desc')
2810 2811 [255]
2811 2812
2812 2813 Behind the scenes, this would throw AttributeError without intype=bytes
@@ -2827,11 +2828,13 b' Behind the scenes, this will throw Value'
2827 2828 [255]
2828 2829
2829 2830 $ hg tip -T '{author|email|shortdate}\n'
2830 abort: template filter 'shortdate' is not compatible with keyword 'author'
2831 hg: parse error: invalid date: 'test'
2832 (template filter 'shortdate' is not compatible with keyword 'author')
2831 2833 [255]
2832 2834
2833 2835 $ hg tip -T '{get(extras, "branch")|shortdate}\n'
2834 abort: incompatible use of template filter 'shortdate'
2836 hg: parse error: invalid date: 'default'
2837 (incompatible use of template filter 'shortdate')
2835 2838 [255]
2836 2839
2837 2840 Error in nested template:
General Comments 0
You need to be logged in to leave comments. Login now