From: AquarHEAD L Date: Sun, 25 Nov 2012 20:37:13 +0000 (+0800) Subject: update the Docstring of do_truncate, add useful examples X-Git-Tag: 2.7~49^2^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8e01f54765b66c2f5e8bfa316157e5669e940229;p=thirdparty%2Fjinja.git update the Docstring of do_truncate, add useful examples --- diff --git a/jinja2/filters.py b/jinja2/filters.py index 8fef6eaa..b4152f76 100644 --- a/jinja2/filters.py +++ b/jinja2/filters.py @@ -443,16 +443,17 @@ def do_truncate(s, length=255, killwords=False, end='...'): """Return a truncated copy of the string. The length is specified with the first parameter which defaults to ``255``. If the second parameter is ``true`` the filter will cut the text at length. Otherwise - it will try to save the last word. If the text was in fact + it will discard the last word. If the text was in fact truncated it will append an ellipsis sign (``"..."``). If you want a different ellipsis sign than ``"..."`` you can specify it using the third parameter. - .. sourcecode jinja:: + .. sourcecode:: jinja - {{ mytext|truncate(300, false, '»') }} - truncate mytext to 300 chars, don't split up words, use a - right pointing double arrow as ellipsis sign. + {{ "foo bar"|truncate(5) }} + -> "foo ..." + {{ "foo bar"|truncate(5, True) }} + -> "foo b..." """ if len(s) <= length: return s