comparison mercurial/templater.py @ 2559:bf67d0f6531c

templater.firstline should handle empty strings
author Brendan Cully <brendan@kublai.com>
date Tue, 04 Jul 2006 15:36:05 -0700
parents 8a8d9ada4528
children 3b53fa20dda8
comparison
equal deleted inserted replaced
2558:1120302009d7 2559:bf67d0f6531c
219 for para, rest in findparas(): 219 for para, rest in findparas():
220 fp.write(space_re.sub(' ', textwrap.fill(para, width))) 220 fp.write(space_re.sub(' ', textwrap.fill(para, width)))
221 fp.write(rest) 221 fp.write(rest)
222 return fp.getvalue() 222 return fp.getvalue()
223 223
224 def firstline(text):
225 '''return the first line of text'''
226 try:
227 return text.splitlines(1)[0].rstrip('\r\n')
228 except IndexError:
229 return ''
230
224 def isodate(date): 231 def isodate(date):
225 '''turn a (timestamp, tzoff) tuple into an iso 8631 date and time.''' 232 '''turn a (timestamp, tzoff) tuple into an iso 8631 date and time.'''
226 return util.datestr(date, format='%Y-%m-%d %H:%M') 233 return util.datestr(date, format='%Y-%m-%d %H:%M')
227 234
228 def hgdate(date): 235 def hgdate(date):
282 "domain": domain, 289 "domain": domain,
283 "email": email, 290 "email": email,
284 "escape": lambda x: cgi.escape(x, True), 291 "escape": lambda x: cgi.escape(x, True),
285 "fill68": lambda x: fill(x, width=68), 292 "fill68": lambda x: fill(x, width=68),
286 "fill76": lambda x: fill(x, width=76), 293 "fill76": lambda x: fill(x, width=76),
287 "firstline": lambda x: x.splitlines(1)[0].rstrip('\r\n'), 294 "firstline": firstline,
288 "tabindent": lambda x: indent(x, '\t'), 295 "tabindent": lambda x: indent(x, '\t'),
289 "hgdate": hgdate, 296 "hgdate": hgdate,
290 "isodate": isodate, 297 "isodate": isodate,
291 "obfuscate": obfuscate, 298 "obfuscate": obfuscate,
292 "permissions": lambda x: x and "-rwxr-xr-x" or "-rw-r--r--", 299 "permissions": lambda x: x and "-rwxr-xr-x" or "-rw-r--r--",