##// END OF EJS Templates
templates: make {indent("", " ")} be empty...
Martin von Zweigbergk -
r44093:fa246ada default
parent child Browse files
Show More
@@ -299,7 +299,7 b' def isodatesec(text):'
299 return dateutil.datestr(text, b'%Y-%m-%d %H:%M:%S %1%2')
299 return dateutil.datestr(text, b'%Y-%m-%d %H:%M:%S %1%2')
300
300
301
301
302 def indent(text, prefix):
302 def indent(text, prefix, firstline=b''):
303 '''indent each non-empty line of text after first with prefix.'''
303 '''indent each non-empty line of text after first with prefix.'''
304 lines = text.splitlines()
304 lines = text.splitlines()
305 num_lines = len(lines)
305 num_lines = len(lines)
@@ -308,8 +308,8 b' def indent(text, prefix):'
308 def indenter():
308 def indenter():
309 for i in pycompat.xrange(num_lines):
309 for i in pycompat.xrange(num_lines):
310 l = lines[i]
310 l = lines[i]
311 if i and l.strip():
311 if l.strip():
312 yield prefix
312 yield prefix if i else firstline
313 yield l
313 yield l
314 if i < num_lines - 1 or endswithnewline:
314 if i < num_lines - 1 or endswithnewline:
315 yield b'\n'
315 yield b'\n'
@@ -310,13 +310,11 b' def indent(context, mapping, args):'
310 text = evalstring(context, mapping, args[0])
310 text = evalstring(context, mapping, args[0])
311 indent = evalstring(context, mapping, args[1])
311 indent = evalstring(context, mapping, args[1])
312
312
313 firstline = indent
313 if len(args) == 3:
314 if len(args) == 3:
314 firstline = evalstring(context, mapping, args[2])
315 firstline = evalstring(context, mapping, args[2])
315 else:
316 firstline = indent
317
316
318 # the indent function doesn't indent the first line, so we do it here
317 return templatefilters.indent(text, indent, firstline=firstline)
319 return templatefilters.indent(firstline + text, indent)
320
318
321
319
322 @templatefunc(b'get(dict, key)')
320 @templatefunc(b'get(dict, key)')
@@ -6,6 +6,9 b''
6
6
7 == Bug Fixes ==
7 == Bug Fixes ==
8
8
9 * The `indent()` template function was documented to not indent empty lines,
10 but it still indented the first line even if it was empty. It no longer does
11 that.
9
12
10 == Backwards Compatibility Changes ==
13 == Backwards Compatibility Changes ==
11
14
@@ -1507,16 +1507,16 b' Test indent and not adding to empty line'
1507 Test indent with empty first line
1507 Test indent with empty first line
1508
1508
1509 $ hg version -T "{indent('', '>> ')}\n"
1509 $ hg version -T "{indent('', '>> ')}\n"
1510 >>
1510
1511
1511
1512 $ hg version -T "{indent('
1512 $ hg version -T "{indent('
1513 > second', '>> ')}\n"
1513 > second', '>> ')}\n"
1514 >>
1514
1515 >> second
1515 >> second
1516
1516
1517 $ hg version -T "{indent('
1517 $ hg version -T "{indent('
1518 > second', '>> ', ' > ')}\n"
1518 > second', '>> ', ' > ')}\n"
1519 >
1519
1520 >> second
1520 >> second
1521
1521
1522 Test with non-strings like dates
1522 Test with non-strings like dates
General Comments 0
You need to be logged in to leave comments. Login now