-
-
Notifications
You must be signed in to change notification settings - Fork 240
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: group_by/group_by_exp/find/find_exp from Jekyll, #443
- Loading branch information
Showing
29 changed files
with
776 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
--- | ||
title: find | ||
--- | ||
|
||
{% since %}v10.11.0{% endsince %} | ||
|
||
Return the first object in an array for which the queried attribute has the given value or return `nil` if no item in the array satisfies the given criteria. For the following `members` array: | ||
|
||
```javascript | ||
const members = [ | ||
{ graduation_year: 2013, name: 'Jay' }, | ||
{ graduation_year: 2014, name: 'John' }, | ||
{ graduation_year: 2014, name: 'Jack' } | ||
] | ||
``` | ||
|
||
Input | ||
```liquid | ||
{{ members | find: "graduation_year", 2014 | json }} | ||
``` | ||
|
||
Output | ||
```text | ||
{"graduation_year":2014,"name":"John"} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
--- | ||
title: find_exp | ||
--- | ||
|
||
{% since %}v10.11.0{% endsince %} | ||
|
||
Return the first object in an array for which the given expression evaluates to true or return `nil` if no item in the array satisfies the evaluated expression. | ||
|
||
```javascript | ||
const members = [ | ||
{ graduation_year: 2013, name: 'Jay' }, | ||
{ graduation_year: 2014, name: 'John' }, | ||
{ graduation_year: 2014, name: 'Jack' } | ||
] | ||
``` | ||
|
||
Input | ||
```liquid | ||
{{ members | find_exp: "item", "item.graduation_year == 2014" | json }} | ||
``` | ||
|
||
Output | ||
```text | ||
{"graduation_year":2014,"name":"John"} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
--- | ||
title: group_by | ||
--- | ||
|
||
{% since %}v10.11.0{% endsince %} | ||
|
||
Group an array's items by a given property. For `members` array: | ||
|
||
```javascript | ||
const members = [ | ||
{ graduation_year: 2003, name: 'Jay' }, | ||
{ graduation_year: 2003, name: 'John' }, | ||
{ graduation_year: 2004, name: 'Jack' } | ||
] | ||
``` | ||
|
||
Input | ||
```liquid | ||
{{ members | group_by: "graduation_year" | json: 2 }} | ||
``` | ||
|
||
Output | ||
```text | ||
[ | ||
{ | ||
"name": 2003, | ||
"items": [ | ||
{ | ||
"graduation_year": 2003, | ||
"name": "Jay" | ||
}, | ||
{ | ||
"graduation_year": 2003, | ||
"name": "John" | ||
} | ||
] | ||
}, | ||
{ | ||
"name": 2004, | ||
"items": [ | ||
{ | ||
"graduation_year": 2004, | ||
"name": "Jack" | ||
} | ||
] | ||
} | ||
] | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
--- | ||
title: group_by_exp | ||
--- | ||
|
||
{% since %}v10.11.0{% endsince %} | ||
|
||
Group an array's items using a Liquid expression. For `members` array below: | ||
|
||
```javascript | ||
const members = [ | ||
{ graduation_year: 2013, name: 'Jay' }, | ||
{ graduation_year: 2014, name: 'John' }, | ||
{ graduation_year: 2009, name: 'Jack' } | ||
] | ||
``` | ||
|
||
Input | ||
```liquid | ||
{{ members | group_by_exp: "item", "item.graduation_year | truncate: 3, ''" | json: 2 }} | ||
``` | ||
|
||
Output | ||
```text | ||
[ | ||
{ | ||
"name": "201", | ||
"items": [ | ||
{ | ||
"graduation_year": 2013, | ||
"name": "Jay" | ||
}, | ||
{ | ||
"graduation_year": 2014, | ||
"name": "John" | ||
} | ||
] | ||
}, | ||
{ | ||
"name": "200", | ||
"items": [ | ||
{ | ||
"graduation_year": 2009, | ||
"name": "Jack" | ||
} | ||
] | ||
} | ||
] | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
--- | ||
title: Escaping | ||
--- | ||
|
||
Escaping is important in all languages, including LiquidJS. While escaping has 2 different meanings for a template engine: | ||
|
||
1. Escaping for the output, i.e. HTML escape. Used to escape HTML special characters so the output will not break HTML structures, aka HTML safe. | ||
2. Escaping for the language itself, i.e. Liquid escape. Used to output strings that's considered special in Liquid language. This will be useful when you're writing an article in Liquid template to introduce Liquid language. | ||
|
||
## HTML Escape | ||
|
||
By default output is not escaped. While you can use [escape][escape] filter for this: | ||
|
||
Input | ||
```liquid | ||
{{ "1 < 2" | escape }} | ||
``` | ||
|
||
Output | ||
```text | ||
1 < 2 | ||
``` | ||
|
||
There's also [escape_once][escape_once], [newline_to_br][newline_to_br], [strip_html][strip_html] filters for you to fine tune your output. | ||
|
||
In cases where variables are mostly not trusted, [outputEscape][outputEscape] can be set to `"escape"` to apply escape by default. In this case, when you need some output not to be escaped, [raw][raw] filter can be used: | ||
|
||
Input | ||
```liquid | ||
{{ "1 < 2" }} | ||
{{ "<button>OK</button>" | raw }} | ||
``` | ||
|
||
Output | ||
```text | ||
1 < 2 | ||
<button>OK</button> | ||
``` | ||
|
||
## Liquid Escape | ||
|
||
To disable Liquid language and output strings like `{{` and `{%`, the [raw][raw] tag can be used. | ||
|
||
Input | ||
```liquid | ||
{% raw %} | ||
In LiquidJS, {{ this | escape }} will be HTML-escaped, but | ||
{{{ that }}} will not. | ||
{% endraw %} | ||
``` | ||
|
||
Output | ||
```text | ||
In LiquidJS, {{ this | escape }} will be HTML-escaped, but | ||
{{{ that }}} will not. | ||
``` | ||
|
||
Within strings literals in LiquidJS template, `\` can be used to escape special characters in string syntax. For example: | ||
|
||
Input | ||
```liquid | ||
{{ "\"" }} | ||
``` | ||
|
||
Output | ||
```liquid | ||
" | ||
``` | ||
|
||
[outputEscape]: ./options.html#outputEscape | ||
[escape]: ../filters/escape.html | ||
[raw]: ../filters/raw.html | ||
[escape_once]: ../filters/escape.html | ||
[strip_html]: ../filters/strip_html.html | ||
[newline_to_br]: ../filters/newline_to_br.html | ||
[raw]: ../tags/raw.html |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
--- | ||
title: find | ||
--- | ||
|
||
{% since %}v10.11.0{% endsince %} | ||
|
||
在数组中找到给定的属性为给定的值的第一个元素并返回;如果没有这样的元素则返回 `nil`。对于 `members` 数组: | ||
|
||
```javascript | ||
const members = [ | ||
{ graduation_year: 2013, name: 'Jay' }, | ||
{ graduation_year: 2014, name: 'John' }, | ||
{ graduation_year: 2014, name: 'Jack' } | ||
] | ||
``` | ||
|
||
输入 | ||
```liquid | ||
{{ members | find: "graduation_year", 2014 | json }} | ||
``` | ||
|
||
输出 | ||
```text | ||
{"graduation_year":2014,"name":"John"} | ||
``` |
Oops, something went wrong.