comparison mercurial/templateutil.py @ 38298:851fc9d42d6d

templater: make date wrapper support dot/map operations No idea if it will be useful, but it just works.
author Yuya Nishihara <yuya@tcha.org>
date Sat, 24 Mar 2018 17:59:19 +0900
parents 8d6109b49b31
children f9c426385853
comparison
equal deleted inserted replaced
38297:8d6109b49b31 38298:851fc9d42d6d
170 return pycompat.bytestr(self._value) 170 return pycompat.bytestr(self._value)
171 171
172 def tovalue(self, context, mapping): 172 def tovalue(self, context, mapping):
173 return self._value 173 return self._value
174 174
175 class date(wrapped): 175 class date(mappable, wrapped):
176 """Wrapper for date tuple""" 176 """Wrapper for date tuple"""
177 177
178 def __init__(self, value): 178 def __init__(self, value):
179 # value may be (float, int), but public interface shouldn't support 179 # value may be (float, int), but public interface shouldn't support
180 # floating-point timestamp 180 # floating-point timestamp
190 raise error.ParseError(_('date is not iterable')) 190 raise error.ParseError(_('date is not iterable'))
191 191
192 def getmax(self, context, mapping): 192 def getmax(self, context, mapping):
193 raise error.ParseError(_('date is not iterable')) 193 raise error.ParseError(_('date is not iterable'))
194 194
195 def itermaps(self, context):
196 raise error.ParseError(_("date is not iterable"))
197
198 def join(self, context, mapping, sep): 195 def join(self, context, mapping, sep):
199 raise error.ParseError(_("date is not iterable")) 196 raise error.ParseError(_("date is not iterable"))
200 197
201 def show(self, context, mapping): 198 def show(self, context, mapping):
202 return '%d %d' % (self._unixtime, self._tzoffset) 199 return '%d %d' % (self._unixtime, self._tzoffset)
200
201 def tomap(self, context):
202 return {'unixtime': self._unixtime, 'tzoffset': self._tzoffset}
203 203
204 def tovalue(self, context, mapping): 204 def tovalue(self, context, mapping):
205 return (self._unixtime, self._tzoffset) 205 return (self._unixtime, self._tzoffset)
206 206
207 class hybrid(wrapped): 207 class hybrid(wrapped):