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

This commit is contained in:
EricFromCanada
2019-09-09 23:01:21 -04:00
parent ea6b176363
commit bea649dc63
13 changed files with 58 additions and 50 deletions
+2 -2
View File
@@ -19,7 +19,7 @@ Liquid code can be categorized into [**objects**](#objects), [**tags**](#tags),
<p class="code-label">Output</p> <p class="code-label">Output</p>
```text ```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`. 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> <p class="code-label">Output</p>
```text ```text
Hello Adam! {{ "adam!" | capitalize | prepend: "Hello " }}
``` ```
+3 -3
View File
@@ -15,7 +15,7 @@ Returns the absolute value of a number.
<p class="code-label">Output</p> <p class="code-label">Output</p>
```text ```text
17 {{ -17 | abs }}
``` ```
<p class="code-label">Input</p> <p class="code-label">Input</p>
@@ -27,7 +27,7 @@ Returns the absolute value of a number.
<p class="code-label">Output</p> <p class="code-label">Output</p>
```text ```text
4 {{ 4 | abs }}
``` ```
`abs` will also work on a string if the string only contains a number. `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> <p class="code-label">Output</p>
```text ```text
19.86 {{ "-19.86" | abs }}
``` ```
+2 -2
View File
@@ -13,7 +13,7 @@ Limits a number to a minimum value.
``` ```
<p class="code-label">Output</p> <p class="code-label">Output</p>
``` ```text
5 5
``` ```
@@ -25,6 +25,6 @@ Limits a number to a minimum value.
``` ```
<p class="code-label">Output</p> <p class="code-label">Output</p>
``` ```text
4 4
``` ```
+2 -2
View File
@@ -13,7 +13,7 @@ Limits a number to a maximum value.
``` ```
<p class="code-label">Output</p> <p class="code-label">Output</p>
``` ```text
4 4
``` ```
@@ -25,6 +25,6 @@ Limits a number to a maximum value.
``` ```
<p class="code-label">Output</p> <p class="code-label">Output</p>
``` ```text
3 3
``` ```
+2 -2
View File
@@ -14,7 +14,7 @@ Makes the first character of a string capitalized.
<p class="code-label">Output</p> <p class="code-label">Output</p>
```text ```text
Title {{ "title" | capitalize }}
``` ```
`capitalize` only capitalizes the first character of the string, so later words are not affected: `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> <p class="code-label">Output</p>
```text ```text
My great title {{ "my great title" | capitalize }}
``` ```
+14 -14
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' %} {% assign site_categories = site.pages | map: 'category' %}
{% for category in site_categories %} {% for category in site_categories %}
{{ category }} - {{ category }}
{% endfor %} {% endfor %}
{% endraw %} {% endraw %}
``` ```
<p class="code-label">Output</p> <p class="code-label">Output</p>
```text ```text
business - business
celebrities - celebrities
-
lifestyle - lifestyle
sports - sports
-
technology - technology
``` ```
By using `compact` when we create our `site_categories` array, we can remove all the `nil` values in the array. 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 %} {% assign site_categories = site.pages | map: 'category' | compact %}
{% for category in site_categories %} {% for category in site_categories %}
{{ category }} - {{ category }}
{% endfor %} {% endfor %}
{% endraw %} {% endraw %}
``` ```
<p class="code-label">Output</p> <p class="code-label">Output</p>
```text ```text
business - business
celebrities - celebrities
lifestyle - lifestyle
sports - sports
technology - technology
``` ```
+2 -6
View File
@@ -8,17 +8,13 @@ Returns the first item of an array.
<p class="code-label">Input</p> <p class="code-label">Input</p>
```liquid ```liquid
{% raw %} {% raw %}
{% assign my_array = "apples, oranges, peaches, plums" | split: ", " %} {{ "Ground control to Major Tom." | split: " " | first }}
{{ my_array.first }}
{% endraw %} {% endraw %}
``` ```
<p class="code-label">Output</p> <p class="code-label">Output</p>
```text ```text
{% assign my_array = "apples, oranges, peaches, plums" | split: ", " %} {{ "Ground control to Major Tom." | split: " " | first }}
{{ my_array.first }}
``` ```
<p class="code-label">Input</p> <p class="code-label">Input</p>
+2 -6
View File
@@ -8,17 +8,13 @@ Returns the last item of an array.
<p class="code-label">Input</p> <p class="code-label">Input</p>
```liquid ```liquid
{% raw %} {% raw %}
{% assign my_array = "apples, oranges, peaches, plums" | split: ", " %} {{ "Ground control to Major Tom." | split: " " | last }}
{{ my_array.last }}
{% endraw %} {% endraw %}
``` ```
<p class="code-label">Output</p> <p class="code-label">Output</p>
```text ```text
{% assign my_array = "apples, oranges, peaches, plums" | split: ", " %} {{ "Ground control to Major Tom." | split: " " | last }}
{{ my_array.last }}
``` ```
<p class="code-label">Input</p> <p class="code-label">Input</p>
+6 -6
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" %} {% assign all_categories = site.pages | map: "category" %}
{% for item in all_categories %} {% for item in all_categories %}
{{ item }} - {{ item }}
{% endfor %} {% endfor %}
{% endraw %} {% endraw %}
``` ```
<p class="code-label">Output</p> <p class="code-label">Output</p>
```text ```text
business - business
celebrities - celebrities
lifestyle - lifestyle
sports - sports
technology - technology
``` ```
+2 -4
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> <p class="code-label">Input</p>
```liquid ```liquid
{% raw %} {% raw %}
{% assign my_string = "Take my protein pills and put my helmet on" %} {{ "Take my protein pills and put my helmet on" | replace_first: "my", "your" }}
{{ my_string | replace_first: "my", "your" }}
{% endraw %} {% endraw %}
``` ```
<p class="code-label">Output</p> <p class="code-label">Output</p>
```text ```text
{% assign my_string = "Take my protein pills and put my helmet on" %} {{ "Take my protein pills and put my helmet on" | replace_first: "my", "your" }}
{{ my_string | replace_first: "my", "your" }}
``` ```
+2 -2
View File
@@ -22,7 +22,7 @@ Returns the number of characters in a string or the number of items in an array.
{% raw %} {% raw %}
{% assign my_array = "apples, oranges, peaches, plums" | split: ", " %} {% assign my_array = "apples, oranges, peaches, plums" | split: ", " %}
{{ my_array | size }} {{ my_array.size }}
{% endraw %} {% endraw %}
``` ```
@@ -30,7 +30,7 @@ Returns the number of characters in a string or the number of items in an array.
```text ```text
{% assign my_array = "apples, oranges, peaches, plums" | split: ", " %} {% 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. You can use `size` with dot notation when you need to use the filter inside a tag.
+1 -1
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> <p class="code-label">Output</p>
```text ```text
'Stop!' said Fred {{ "%27Stop%21%27+said+Fred" | url_decode }}
``` ```
+18
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. `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 ## tablerow
Generates an HTML table. Must be wrapped in opening `<table>` and closing `</table>` HTML tags. Generates an HTML table. Must be wrapped in opening `<table>` and closing `</table>` HTML tags.