template: Bugfix newline handling.
If a rendering ended with a zeroed out split, the output would contain an extraneous trailing newline. Rearrange the code to print a newline preceding each content line.
This commit is contained in:
parent
e758db31ad
commit
9f720527f1
1 changed files with 6 additions and 8 deletions
|
@ -165,7 +165,7 @@ class AccountSplitter:
|
|||
account_s = account.format_map(template_vars)
|
||||
amount_s = babel.numbers.format_currency(amount, template_vars['currency'], amt_fmt)
|
||||
sep_len = max(2, self.TARGET_ACCTLINE_LEN - len(account_s) - len(amount_s))
|
||||
yield ' {}{}{}\n{}'.format(
|
||||
yield '\n {}{}{}{}'.format(
|
||||
account_s, ' ' * sep_len, amount_s,
|
||||
metadata.format_map(template_vars),
|
||||
)
|
||||
|
@ -214,14 +214,12 @@ class Template:
|
|||
amount_expr = line[match.end():]
|
||||
self.splitter.add(account, amount_expr)
|
||||
self.format_funcs.append(self.splitter.render_next)
|
||||
if metadata:
|
||||
self._add_str_func(metadata)
|
||||
if not metadata[-1].endswith('\n'):
|
||||
self.format_funcs.append('\n'.format_map)
|
||||
|
||||
def _nonblank_lines(self, s):
|
||||
for line in s.splitlines(True):
|
||||
line = line.lstrip()
|
||||
line = line.strip()
|
||||
if line:
|
||||
yield line
|
||||
|
||||
|
@ -234,12 +232,12 @@ class Template:
|
|||
if self.PAYEE_LINE_RE.match(line1):
|
||||
yield '\n' + line1
|
||||
else:
|
||||
yield '\n{date} {payee}\n'
|
||||
yield '\n{date} {payee}'
|
||||
yield line1
|
||||
yield from lines
|
||||
|
||||
def _add_str_func(self, str_seq):
|
||||
str_flat = ''.join(' ' + s for s in str_seq)
|
||||
str_flat = ''.join('\n ' + s for s in str_seq)
|
||||
if not str_flat:
|
||||
pass
|
||||
elif self.splitter.is_empty():
|
||||
|
|
Loading…
Reference in a new issue