WIP: Adding missing filters

This commit is contained in:
Tetsuro
2015-07-25 17:48:18 -04:00
parent 7f550c8bce
commit d9b2d50045
6 changed files with 55 additions and 0 deletions

View File

@@ -1,3 +1,12 @@
---
title: round
---
Rounds the output to the nearest integer or specified number of decimals.
| Input | Output |
|:-------------------------------------------|:-------|
| {% raw %}`{{ 4.6 | round }}` {% endraw %} | 5 |
| {% raw %}`{{ 4.3 | round }}` {% endraw %} | 4 |
| {% raw %}`{{ 4.5612 | round: 2 }}` {% endraw %} | 4.56 |

View File

@@ -1,3 +1,20 @@
---
title: slice
---
The <code>slice</code> filter returns a substring, starting at the specified index. An optional second parameter can be passed to specify the length of the substring. If no second parameter is given, a substring of one character will be returned.
| Input | Output |
|:------------------------------------------------|:-------|
| {% raw %}`{{ "hello" | slice: 0 }}`{% endraw %} | h |
| {% raw %}`{{ "hello" | slice: 1 }}`{% endraw %} | e |
| {% raw %}`{{ "hello" | slice: 1, 3 }}`{% endraw %} | ell |
If the passed index is negative, it is counted from the end of the string.
| Input | Output |
|:------------------------------------------------|:-------|
| {% raw %}`{{ "hello" | slice: -3, 2 }}`{% endraw %} | ll |

View File

@@ -1,3 +1,10 @@
---
title: truncate
---
<p>Truncates a string down to 'x' characters, where x is the number passed as a parameter. An ellipsis (...) is appended to the string and is included in the character count.</p>
| Input | Output |
|:-------------------------------------------|:-------|
| {% raw %}`{{ "The cat came back the very next day" | truncate: 10 }}`{% endraw %} | "The cat..." |

View File

@@ -1,3 +1,10 @@
---
title: truncatewords
---
<p>Truncates a string down to 'x' words, where x is the number passed as a parameter. An ellipsis (...) is appended to the truncated string.</p>
| Input | Output |
|:-------------------------------------------|:-------|
| {% raw %}`{{ "The cat came back the very next day" | truncatewords: 4 }}`{% endraw %} | The cat came back...|

View File

@@ -1,3 +1,10 @@
---
title: uniq
---
<p>Removes any duplicate instances of an element in an array.</p>
| Input | Output |
|:-------------------------------------------|:-------|
| {% raw %}`{% assign fruits = "orange apple banana apple orange" %} {{ fruits | split: ' ' | uniq | join: ' ' }}`{% endraw %} | orange apple banana |

View File

@@ -1,3 +1,11 @@
---
title: upcase
---
<p>Converts a string into uppercase.</p>
| Input | Output |
|:-------------------------------------------|:-------|
| {% raw %}`{{ 'loud noises' | upcase }}`{% endraw %} | LOUD NOISES |