Skip to content
This repository

Update the Docstring of do_truncate in jinja2/filters.py #165

Merged
merged 1 commit into from 11 months ago

2 participants

Lou Xun / 楼洵 Armin Ronacher
Lou Xun / 楼洵
  1. Now it says "discard the last word" not "try to save" if killwords=False
  2. Fix a typo in the beginning of example
  3. Add 2 easy examples to show the usage of the confusing killwords
Armin Ronacher mitsuhiko merged commit 604752b into from
Armin Ronacher mitsuhiko closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Nov 26, 2012
Lou Xun / 楼洵 update the Docstring of do_truncate, add useful examples 8e01f54
This page is out of date. Refresh to see the latest.

Showing 1 changed file with 6 additions and 5 deletions. Show diff stats Hide diff stats

  1. 11  jinja2/filters.py
11  jinja2/filters.py
@@ -443,16 +443,17 @@ def do_truncate(s, length=255, killwords=False, end='...'):
443 443
     """Return a truncated copy of the string. The length is specified
444 444
     with the first parameter which defaults to ``255``. If the second
445 445
     parameter is ``true`` the filter will cut the text at length. Otherwise
446  
-    it will try to save the last word. If the text was in fact
  446
+    it will discard the last word. If the text was in fact
447 447
     truncated it will append an ellipsis sign (``"..."``). If you want a
448 448
     different ellipsis sign than ``"..."`` you can specify it using the
449 449
     third parameter.
450 450
 
451  
-    .. sourcecode jinja::
  451
+    .. sourcecode:: jinja
452 452
 
453  
-        {{ mytext|truncate(300, false, '»') }}
454  
-            truncate mytext to 300 chars, don't split up words, use a
455  
-            right pointing double arrow as ellipsis sign.
  453
+        {{ "foo bar"|truncate(5) }}
  454
+            -> "foo ..."
  455
+        {{ "foo bar"|truncate(5, True) }}
  456
+            -> "foo b..."
456 457
     """
457 458
     if len(s) <= length:
458 459
         return s
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.