From ea9c6496bb6e60c3930ddb4943516914a1604c91 Mon Sep 17 00:00:00 2001 From: Kegan Dougal Date: Thu, 21 May 2015 11:27:54 +0100 Subject: [PATCH] Account for 'required' text when wrapping desc column. --- templating/build.py | 9 ++++++--- templating/templates/events.tmpl | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/templating/build.py b/templating/build.py index da680881..6594c4f6 100755 --- a/templating/build.py +++ b/templating/build.py @@ -45,7 +45,7 @@ from argparse import ArgumentParser, FileType import json import os import sys -import textwrap +from textwrap import TextWrapper import internal.units import internal.sections @@ -85,8 +85,11 @@ def main(file_stream=None, out_dir=None): def indent(input, indent): return " "*indent + input - def wrap(input, wrap=80): - return '\n'.join(textwrap.wrap(input, wrap)) + def wrap(input, wrap=80, initial_indent=""): + if len(input) == 0: + return initial_indent + wrapper = TextWrapper(initial_indent=initial_indent, width=wrap) + return wrapper.fill(input) # make Jinja aware of the templates and filters env = Environment( diff --git a/templating/templates/events.tmpl b/templating/templates/events.tmpl index 24af5052..34b155f9 100644 --- a/templating/templates/events.tmpl +++ b/templating/templates/events.tmpl @@ -13,7 +13,7 @@ {# Desc needs to prepend the required text (maybe) and prepend spaces too -#} {# It also needs to then wrap inside the desc col (43 ch width) -#} {# -#} -{{row.key}}{{row.type|indent(19-row.key|length)}}{{row.req_str | indent(18 - (row.type|length))}}{{row.desc|wrap(43)|indent_block(37)}} +{{row.key}}{{row.type|indent(19-row.key|length)}}{{row.desc|wrap(43,row.req_str | indent(18 - (row.type|length))) |indent_block(37)}} {% endfor -%} ================== ================= ===========================================