Auto-generate more code samples, plus other fixes and improvements

This commit is contained in:
EricFromCanada
2019-09-05 00:59:24 -04:00
parent ea6b176363
commit bea649dc63
13 changed files with 58 additions and 50 deletions

View File

@@ -19,7 +19,7 @@ Liquid code can be categorized into [**objects**](#objects), [**tags**](#tags),
<p class="code-label">Output</p>
```text
Introduction
{{ page.title }}
```
In this case, Liquid is rendering the content of an object called `page.title`, and that object contains the text `Introduction`.
@@ -79,5 +79,5 @@ Multiple filters can be used on one output. They are applied from left to right.
<p class="code-label">Output</p>
```text
Hello Adam!
{{ "adam!" | capitalize | prepend: "Hello " }}
```

View File

@@ -15,7 +15,7 @@ Returns the absolute value of a number.
<p class="code-label">Output</p>
```text
17
{{ -17 | abs }}
```
<p class="code-label">Input</p>
@@ -27,7 +27,7 @@ Returns the absolute value of a number.
<p class="code-label">Output</p>
```text
4
{{ 4 | abs }}
```
`abs` will also work on a string if the string only contains a number.
@@ -41,5 +41,5 @@ Returns the absolute value of a number.
<p class="code-label">Output</p>
```text
19.86
{{ "-19.86" | abs }}
```

View File

@@ -13,7 +13,7 @@ Limits a number to a minimum value.
```
<p class="code-label">Output</p>
```
```text
5
```
@@ -25,6 +25,6 @@ Limits a number to a minimum value.
```
<p class="code-label">Output</p>
```
```text
4
```

View File

@@ -13,7 +13,7 @@ Limits a number to a maximum value.
```
<p class="code-label">Output</p>
```
```text
4
```
@@ -25,6 +25,6 @@ Limits a number to a maximum value.
```
<p class="code-label">Output</p>
```
```text
3
```

View File

@@ -14,7 +14,7 @@ Makes the first character of a string capitalized.
<p class="code-label">Output</p>
```text
Title
{{ "title" | capitalize }}
```
`capitalize` only capitalizes the first character of the string, so later words are not affected:
@@ -28,5 +28,5 @@ Title
<p class="code-label">Output</p>
```text
My great title
{{ "my great title" | capitalize }}
```

View File

@@ -13,20 +13,20 @@ For this example, assume `site.pages` is an array of content pages for a website
{% assign site_categories = site.pages | map: 'category' %}
{% for category in site_categories %}
{{ category }}
- {{ category }}
{% endfor %}
{% endraw %}
```
<p class="code-label">Output</p>
```text
business
celebrities
lifestyle
sports
technology
- business
- celebrities
-
- lifestyle
- sports
-
- technology
```
By using `compact` when we create our `site_categories` array, we can remove all the `nil` values in the array.
@@ -37,16 +37,16 @@ By using `compact` when we create our `site_categories` array, we can remove all
{% assign site_categories = site.pages | map: 'category' | compact %}
{% for category in site_categories %}
{{ category }}
- {{ category }}
{% endfor %}
{% endraw %}
```
<p class="code-label">Output</p>
```text
business
celebrities
lifestyle
sports
technology
- business
- celebrities
- lifestyle
- sports
- technology
```

View File

@@ -8,17 +8,13 @@ Returns the first item of an array.
<p class="code-label">Input</p>
```liquid
{% raw %}
{% assign my_array = "apples, oranges, peaches, plums" | split: ", " %}
{{ my_array.first }}
{{ "Ground control to Major Tom." | split: " " | first }}
{% endraw %}
```
<p class="code-label">Output</p>
```text
{% assign my_array = "apples, oranges, peaches, plums" | split: ", " %}
{{ my_array.first }}
{{ "Ground control to Major Tom." | split: " " | first }}
```
<p class="code-label">Input</p>

View File

@@ -8,17 +8,13 @@ Returns the last item of an array.
<p class="code-label">Input</p>
```liquid
{% raw %}
{% assign my_array = "apples, oranges, peaches, plums" | split: ", " %}
{{ my_array.last }}
{{ "Ground control to Major Tom." | split: " " | last }}
{% endraw %}
```
<p class="code-label">Output</p>
```text
{% assign my_array = "apples, oranges, peaches, plums" | split: ", " %}
{{ my_array.last }}
{{ "Ground control to Major Tom." | split: " " | last }}
```
<p class="code-label">Input</p>

View File

@@ -13,16 +13,16 @@ In this example, assume the object `site.pages` contains all the metadata for a
{% assign all_categories = site.pages | map: "category" %}
{% for item in all_categories %}
{{ item }}
- {{ item }}
{% endfor %}
{% endraw %}
```
<p class="code-label">Output</p>
```text
business
celebrities
lifestyle
sports
technology
- business
- celebrities
- lifestyle
- sports
- technology
```

View File

@@ -8,13 +8,11 @@ Replaces only the first occurrence of the first argument in a string with the se
<p class="code-label">Input</p>
```liquid
{% raw %}
{% assign my_string = "Take my protein pills and put my helmet on" %}
{{ my_string | replace_first: "my", "your" }}
{{ "Take my protein pills and put my helmet on" | replace_first: "my", "your" }}
{% endraw %}
```
<p class="code-label">Output</p>
```text
{% assign my_string = "Take my protein pills and put my helmet on" %}
{{ my_string | replace_first: "my", "your" }}
{{ "Take my protein pills and put my helmet on" | replace_first: "my", "your" }}
```

View File

@@ -22,7 +22,7 @@ Returns the number of characters in a string or the number of items in an array.
{% raw %}
{% assign my_array = "apples, oranges, peaches, plums" | split: ", " %}
{{ my_array | size }}
{{ my_array.size }}
{% endraw %}
```
@@ -30,7 +30,7 @@ Returns the number of characters in a string or the number of items in an array.
```text
{% assign my_array = "apples, oranges, peaches, plums" | split: ", " %}
{{ my_array | size }}
{{ my_array.size }}
```
You can use `size` with dot notation when you need to use the filter inside a tag.

View File

@@ -14,5 +14,5 @@ Decodes a string that has been encoded as a URL or by [`url_encode`]({{ '/filter
<p class="code-label">Output</p>
```text
'Stop!' said Fred
{{ "%27Stop%21%27+said+Fred" | url_decode }}
```

View File

@@ -203,6 +203,24 @@ Uses for `cycle` include:
`cycle` accepts a parameter called `cycle group` in cases where you need multiple `cycle` blocks in one template. If no name is supplied for the cycle group, then it is assumed that multiple calls with the same parameters are one group.
<p class="code-label">Input</p>
```liquid
{% raw %}
{% cycle "first": "one", "two", "three" %}
{% cycle "second": "one", "two", "three" %}
{% cycle "second": "one", "two", "three" %}
{% cycle "first": "one", "two", "three" %}
{% endraw %}
```
<p class="code-label">Output</p>
```text
one
one
two
two
```
## tablerow
Generates an HTML table. Must be wrapped in opening `<table>` and closing `</table>` HTML tags.