Skip to content

Commit

Permalink
Merge a6b6126 into ccd83bc
Browse files Browse the repository at this point in the history
  • Loading branch information
harttle committed Apr 14, 2024
2 parents ccd83bc + a6b6126 commit f26c1ff
Show file tree
Hide file tree
Showing 46 changed files with 1,067 additions and 155 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ node_modules/

# tmp
docs/public/js/liquid.browser.min.js
docs/themes/navy/layout/partial/all-contributors.swig
dist/
demo/*/yarn.json

Expand Down
9 changes: 9 additions & 0 deletions docs/source/_data/sidebar.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ tutorials:
express: use-in-expressjs.html
advanced:
caching: caching.html
escaping: escaping.html
registeration: register-filters-tags.html
access_scope_in_filters: access-scope-in-filters.html
parse_parameters: parse-parameters.html
Expand Down Expand Up @@ -40,8 +41,12 @@ filters:
downcase: downcase.html
escape: escape.html
escape_once: escape_once.html
find: find.html
find_exp: find_exp.html
first: first.html
floor: floor.html
group_by: group_by.html
group_by_exp: group_by_exp.html
join: join.html
json: json.html
last: last.html
Expand All @@ -51,6 +56,8 @@ filters:
modulo: modulo.html
newline_to_br: newline_to_br.html
plus: plus.html
pop: pop.html
push: push.html
prepend: prepend.html
raw: raw.html
remove: remove.html
Expand All @@ -62,6 +69,7 @@ filters:
reverse: reverse.html
round: round.html
rstrip: rstrip.html
shift: shift.html
size: size.html
slice: slice.html
sort: sort.html
Expand All @@ -75,6 +83,7 @@ filters:
truncate: truncate.html
truncatewords: truncatewords.html
uniq: uniq.html
unshift: unshift.html
upcase: upcase.html
url_decode: url_decode.html
url_encode: url_encode.html
Expand Down
25 changes: 25 additions & 0 deletions docs/source/filters/find.md
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"}
```
25 changes: 25 additions & 0 deletions docs/source/filters/find_exp.md
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"}
```
48 changes: 48 additions & 0 deletions docs/source/filters/group_by.md
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"
}
]
}
]
```
48 changes: 48 additions & 0 deletions docs/source/filters/group_by_exp.md
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"
}
]
}
]
```
21 changes: 21 additions & 0 deletions docs/source/filters/json.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,24 @@ Output
```text
["foo","bar","coo"]
```

## Space

{% since %}v10.11.0{% endsince %}

An additional `space` parameter can be specified to format the JSON.

Input
```liquid
{% assign arr = "foo bar coo" | split: " " %}
{{ arr | json: 4 }}
```

Output
```text
[
"foo",
"bar",
"coo"
]
```
2 changes: 1 addition & 1 deletion docs/source/filters/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Categories | Filters
Math | plus, minus, modulo, times, floor, ceil, round, divided_by, abs, at_least, at_most
String | append, prepend, capitalize, upcase, downcase, strip, lstrip, rstrip, strip_newlines, split, replace, replace_first, replace_last,remove, remove_first, remove_last, truncate, truncatewords
HTML/URI | escape, escape_once, url_encode, url_decode, strip_html, newline_to_br
Array | slice, map, sort, sort_natural, uniq, where, first, last, join, reverse, concat, compact, size
Array | slice, map, sort, sort_natural, uniq, where, group_by, group_by_exp, find, find_exp, first, last, join, reverse, concat, compact, size, push, pop, shift, unshift
Date | date
Misc | default, json, raw

Expand Down
24 changes: 24 additions & 0 deletions docs/source/filters/pop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
title: pop
---

{% since %}v10.11.0{% endsince %}

Pop an element from the array. It's NON-DESTRUCTIVE, i.e. it does not mutate the array, but rather make a copy and mutate that.

Input
```liquid
{% assign fruits = "apples, oranges, peaches" | split: ", " %}
{% assign everything = fruits | pop %}
{% for item in everything %}
- {{ item }}
{% endfor %}
```

Output
```text
- apples
- oranges
```
25 changes: 25 additions & 0 deletions docs/source/filters/push.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
title: push
---

{% since %}v10.8.0{% endsince %}

Push an element into array. It's NON-DESTRUCTIVE, i.e. it does not mutate the array, but rather make a copy and mutate that.

Input
```liquid
{% assign fruits = "apples, oranges" | split: ", " %}
{% assign everything = fruits | push: "peaches" %}
{% for item in everything %}
- {{ item }}
{% endfor %}
```

Output
```text
- apples
- oranges
- peaches
```
24 changes: 24 additions & 0 deletions docs/source/filters/shift.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
title: shift
---

{% since %}v10.11.0{% endsince %}

Shift an element from the array. It's NON-DESTRUCTIVE, i.e. it does not mutate the array, but rather make a copy and mutate that.

Input
```liquid
{% assign fruits = "apples, oranges, peaches" | split: ", " %}
{% assign everything = fruits | shift %}
{% for item in everything %}
- {{ item }}
{% endfor %}
```

Output
```text
- oranges
- peaches
```
25 changes: 25 additions & 0 deletions docs/source/filters/unshift.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
title: unshift
---

{% since %}v10.11.0{% endsince %}

Unshift an element to the front of the array. It's NON-DESTRUCTIVE, i.e. it does not mutate the array, but rather make a copy and mutate that.

Input
```liquid
{% assign fruits = "oranges, peaches" | split: ", " %}
{% assign everything = fruits | unshift: "apples" %}
{% for item in everything %}
- {{ item }}
{% endfor %}
```

Output
```text
- apples
- oranges
- peaches
```
24 changes: 24 additions & 0 deletions docs/source/filters/where.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,28 @@ Output
Featured product: Hawaiian print sweater vest
```

Additionally, `property` can be any valid Liquid variable expression as used in output syntax, except that the scope of this expression is within each item. For the following `products` array:

```javascript
const products = [
{ meta: { details: { class: 'A' } }, order: 1 },
{ meta: { details: { class: 'B' } }, order: 2 },
{ meta: { details: { class: 'B' } }, order: 3 }
]
```

Input
```liquid
{% assign selected = products | where: 'meta.details["class"]', "B" %}
{% for item in selected -%}
- {{ item.order }}
{% endfor %}
```

Ouput
```text
- 2
- 3
```

[truthy]: ../tutorials/truthy-and-falsy.html

0 comments on commit f26c1ff

Please sign in to comment.