mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-15 04:10:40 -07:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0d41f7467e | ||
|
|
1d35e3fcfb | ||
|
|
04c874b174 | ||
|
|
29f42847a5 | ||
|
|
426863a9b4 | ||
|
|
8f9639f1d6 | ||
|
|
3e130e01a7 | ||
|
|
3e3d84a5ed | ||
|
|
69f1a394b1 | ||
|
|
ae8636d95d | ||
|
|
1fd76acf28 | ||
|
|
62f8f707e9 | ||
|
|
9c7cb5752b | ||
|
|
4e394b9072 | ||
|
|
251a50801c | ||
|
|
aa5d63fdf7 | ||
|
|
65487654c4 | ||
|
|
8bab7957da | ||
|
|
666df5a8e6 | ||
|
|
a4aa9ba0d6 | ||
|
|
f5f54c82bf | ||
|
|
28f154554b | ||
|
|
2bc03d6a01 | ||
|
|
354a971b9e | ||
|
|
b41be92dfd | ||
|
|
bad12ea936 | ||
|
|
b5a22fa091 | ||
|
|
7d92f25cbb | ||
|
|
4584867b65 | ||
|
|
695e3c18bc | ||
|
|
2133ed20d7 | ||
|
|
dbc23e8b04 | ||
|
|
1acace5a16 | ||
|
|
9a9b792c63 | ||
|
|
99d14e76d7 | ||
|
|
aff9976042 | ||
|
|
cd8cb39329 | ||
|
|
9ed3b98db3 | ||
|
|
151ff4cbf3 | ||
|
|
2e66e8b02e | ||
|
|
24306722ec | ||
|
|
2f059f6a25 | ||
|
|
4e82da689e | ||
|
|
e37824fd8a | ||
|
|
81e11bb9c4 | ||
|
|
71d5d24813 | ||
|
|
20f559e545 | ||
|
|
dce75a1a22 |
@@ -351,6 +351,24 @@
|
||||
"contributions": [
|
||||
"code"
|
||||
]
|
||||
},
|
||||
{
|
||||
"login": "kayuapi",
|
||||
"name": "ZC",
|
||||
"avatar_url": "https://avatars.githubusercontent.com/u/10304328?v=4",
|
||||
"profile": "https://github.com/kayuapi",
|
||||
"contributions": [
|
||||
"doc"
|
||||
]
|
||||
},
|
||||
{
|
||||
"login": "mems",
|
||||
"name": "Memmie Lenglet",
|
||||
"avatar_url": "https://avatars.githubusercontent.com/u/729275?v=4",
|
||||
"profile": "https://memmie.lenglet.name",
|
||||
"contributions": [
|
||||
"code"
|
||||
]
|
||||
}
|
||||
],
|
||||
"contributorsPerLine": 7,
|
||||
|
||||
@@ -1,3 +1,82 @@
|
||||
# [9.25.0](https://github.com/harttle/liquidjs/compare/v9.24.2...v9.25.0) (2021-05-07)
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* when tag with multiple values ([8f9639f](https://github.com/harttle/liquidjs/commit/8f9639f))
|
||||
|
||||
## [9.24.2](https://github.com/harttle/liquidjs/compare/v9.24.1...v9.24.2) (2021-05-04)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* operator boundary not correctly recognized, fixes [#342](https://github.com/harttle/liquidjs/issues/342) ([3e3d84a](https://github.com/harttle/liquidjs/commit/3e3d84a))
|
||||
|
||||
## [9.24.1](https://github.com/harttle/liquidjs/compare/v9.24.0...v9.24.1) (2021-05-01)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* make LiquidError context property public ([1fd76ac](https://github.com/harttle/liquidjs/commit/1fd76ac))
|
||||
|
||||
# [9.24.0](https://github.com/harttle/liquidjs/compare/v9.23.4...v9.24.0) (2021-05-01)
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* add context as a property on the LiquidError error ([9c7cb57](https://github.com/harttle/liquidjs/commit/9c7cb57))
|
||||
* export errors for better error handling in user-land ([4e394b9](https://github.com/harttle/liquidjs/commit/4e394b9))
|
||||
|
||||
## [9.23.4](https://github.com/harttle/liquidjs/compare/v9.23.3...v9.23.4) (2021-04-17)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* capitalize filter not lower case trailing string, fixes [#326](https://github.com/harttle/liquidjs/issues/326) ([6548765](https://github.com/harttle/liquidjs/commit/6548765))
|
||||
|
||||
## [9.23.3](https://github.com/harttle/liquidjs/compare/v9.23.2...v9.23.3) (2021-03-21)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* expose TokenKind ([dbc23e8](https://github.com/harttle/liquidjs/commit/dbc23e8))
|
||||
|
||||
## [9.23.2](https://github.com/harttle/liquidjs/compare/v9.23.1...v9.23.2) (2021-03-13)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* comparison for empty/nil, fixes [#321](https://github.com/harttle/liquidjs/issues/321) ([99d14e7](https://github.com/harttle/liquidjs/commit/99d14e7))
|
||||
* newline_to_br filter should output <br /> instead of <br/>, fixes [#320](https://github.com/harttle/liquidjs/issues/320) ([9a9b792](https://github.com/harttle/liquidjs/commit/9a9b792))
|
||||
|
||||
## [9.23.1](https://github.com/harttle/liquidjs/compare/v9.23.0...v9.23.1) (2021-02-19)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* lenientIf not working for the umd bundle, closes [#313](https://github.com/harttle/liquidjs/issues/313) ([2e66e8b](https://github.com/harttle/liquidjs/commit/2e66e8b))
|
||||
|
||||
# [9.23.0](https://github.com/harttle/liquidjs/compare/v9.22.1...v9.23.0) (2021-02-12)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* respect `fs` in parser options, for [#233](https://github.com/harttle/liquidjs/issues/233) ([4e82da6](https://github.com/harttle/liquidjs/commit/4e82da6))
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* support filters in if/unless/case, see [#287](https://github.com/harttle/liquidjs/issues/287) ([2f059f6](https://github.com/harttle/liquidjs/commit/2f059f6))
|
||||
* support function calls, closes [#222](https://github.com/harttle/liquidjs/issues/222) ([e37824f](https://github.com/harttle/liquidjs/commit/e37824f))
|
||||
* support layout none, closes [#299](https://github.com/harttle/liquidjs/issues/299) ([81e11bb](https://github.com/harttle/liquidjs/commit/81e11bb))
|
||||
|
||||
## [9.22.1](https://github.com/harttle/liquidjs/compare/v9.22.0...v9.22.1) (2021-02-05)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* default to precedence 1 for custom operators ([20f559e](https://github.com/harttle/liquidjs/commit/20f559e))
|
||||
|
||||
# [9.22.0](https://github.com/harttle/liquidjs/compare/v9.21.0...v9.22.0) (2021-02-04)
|
||||
|
||||
|
||||
|
||||
@@ -106,6 +106,8 @@ Want to contribute? see [Contribution Guidelines][contribution]. Thanks goes to
|
||||
<tr>
|
||||
<td align="center"><a href="https://github.com/Pixcell"><img src="https://avatars0.githubusercontent.com/u/4005291?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Pixcell</b></sub></a><br /><a href="https://github.com/harttle/liquidjs/commits?author=Pixcell" title="Code">💻</a></td>
|
||||
<td align="center"><a href="https://jasonet.co"><img src="https://avatars.githubusercontent.com/u/10660468?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Jason Etcovitch</b></sub></a><br /><a href="https://github.com/harttle/liquidjs/commits?author=JasonEtco" title="Code">💻</a></td>
|
||||
<td align="center"><a href="https://github.com/kayuapi"><img src="https://avatars.githubusercontent.com/u/10304328?v=4?s=100" width="100px;" alt=""/><br /><sub><b>ZC</b></sub></a><br /><a href="https://github.com/harttle/liquidjs/commits?author=kayuapi" title="Documentation">📖</a></td>
|
||||
<td align="center"><a href="https://memmie.lenglet.name"><img src="https://avatars.githubusercontent.com/u/729275?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Memmie Lenglet</b></sub></a><br /><a href="https://github.com/harttle/liquidjs/commits?author=mems" title="Code">💻</a></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
|
||||
@@ -7,7 +7,11 @@
|
||||
"start": "ts-node index.ts"
|
||||
},
|
||||
"dependencies": {
|
||||
"ts-node": "^8.0.2",
|
||||
"liquidjs": "*"
|
||||
"liquidjs": "*",
|
||||
"ts-node": "^8.10.2",
|
||||
"typescript": "^4.2.4"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^14.14.37"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
{%header content: "welcome to liquid" | capitalize%}
|
||||
{%header content: title | capitalize%}
|
||||
|
||||
<ul>
|
||||
{% for todo in todos %}
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"types": [
|
||||
"node"
|
||||
]
|
||||
}
|
||||
}
|
||||
Generated
+9
-9
@@ -3060,9 +3060,9 @@
|
||||
"integrity": "sha1-t+PqQkNaTJsnWdmeDyAesZWALuE="
|
||||
},
|
||||
"prismjs": {
|
||||
"version": "1.21.0",
|
||||
"resolved": "https://registry.npmjs.org/prismjs/-/prismjs-1.21.0.tgz",
|
||||
"integrity": "sha512-uGdSIu1nk3kej2iZsLyDoJ7e9bnPzIgY0naW/HdknGj61zScaprVEVGHrPoXqI+M9sP0NDnTK2jpkvmldpuqDw==",
|
||||
"version": "1.23.0",
|
||||
"resolved": "https://registry.npmjs.org/prismjs/-/prismjs-1.23.0.tgz",
|
||||
"integrity": "sha512-c29LVsqOaLbBHuIbsTxaKENh1N2EQBOHaWv7gkHN4dgRbxSREqDnDbtFJYdpPauS4YCplMSNCABQ6Eeor69bAA==",
|
||||
"requires": {
|
||||
"clipboard": "^2.0.0"
|
||||
}
|
||||
@@ -3118,9 +3118,9 @@
|
||||
}
|
||||
},
|
||||
"pug-code-gen": {
|
||||
"version": "2.0.2",
|
||||
"resolved": "https://registry.npmjs.org/pug-code-gen/-/pug-code-gen-2.0.2.tgz",
|
||||
"integrity": "sha512-kROFWv/AHx/9CRgoGJeRSm+4mLWchbgpRzTEn8XCiwwOy6Vh0gAClS8Vh5TEJ9DBjaP8wCjS3J6HKsEsYdvaCw==",
|
||||
"version": "2.0.3",
|
||||
"resolved": "https://registry.npmjs.org/pug-code-gen/-/pug-code-gen-2.0.3.tgz",
|
||||
"integrity": "sha512-r9sezXdDuZJfW9J91TN/2LFbiqDhmltTFmGpHTsGdrNGp3p4SxAjjXEfnuK2e4ywYsRIVP0NeLbSAMHUcaX1EA==",
|
||||
"requires": {
|
||||
"constantinople": "^3.1.2",
|
||||
"doctypes": "^1.1.0",
|
||||
@@ -4110,9 +4110,9 @@
|
||||
}
|
||||
},
|
||||
"y18n": {
|
||||
"version": "4.0.0",
|
||||
"resolved": "https://registry.npmjs.org/y18n/-/y18n-4.0.0.tgz",
|
||||
"integrity": "sha512-r9S/ZyXu/Xu9q1tYlpsLIsa3EeLXXk0VwlxqTcFRfg9EhMW+17kbt9G0NrgCmhGb5vT2hyhJZLfDGx+7+5Uj/w==",
|
||||
"version": "4.0.1",
|
||||
"resolved": "https://registry.npmjs.org/y18n/-/y18n-4.0.1.tgz",
|
||||
"integrity": "sha512-wNcy4NvjMYL8gogWWYAO7ZFWFfHcbdbE57tZO8e4cbpj8tfUcwrwqSl3ad8HxpYWCdXcJUCeKKZS62Av1affwQ==",
|
||||
"dev": true
|
||||
},
|
||||
"yargs": {
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
'use strict'
|
||||
|
||||
hexo.extend.tag.register('note', (args, content) => {
|
||||
hexo.extend.tag.register('note', (args, text) => {
|
||||
const className = args.shift()
|
||||
let header = ''
|
||||
let result = ''
|
||||
@@ -12,8 +12,12 @@ hexo.extend.tag.register('note', (args, content) => {
|
||||
}
|
||||
|
||||
result += `<blockquote class="note ${className}">${header}`
|
||||
result += hexo.render.renderSync({ text: content, engine: 'markdown' })
|
||||
result += hexo.render.renderSync({ text, engine: 'markdown' })
|
||||
result += '</blockquote>'
|
||||
|
||||
return result
|
||||
}, true)
|
||||
|
||||
hexo.extend.tag.register('since', (args, text) => {
|
||||
return `<p class="since">Added in: ${text.trim()}</p>`
|
||||
}, true)
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
title: abs
|
||||
---
|
||||
|
||||
{% since %}v1.9.1{% endsince %}
|
||||
|
||||
Liquid filter that returns the absolute value of a number.
|
||||
|
||||
Input
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
title: append
|
||||
---
|
||||
|
||||
{% since %}v1.9.1{% endsince %}
|
||||
|
||||
Concatenates two strings and returns the concatenated value.
|
||||
|
||||
Input
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
title: at_least
|
||||
---
|
||||
|
||||
{% since %}v8.4.0{% endsince %}
|
||||
|
||||
Limits a number to a minimum value.
|
||||
|
||||
Input
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
title: at_most
|
||||
---
|
||||
|
||||
{% since %}v8.4.0{% endsince %}
|
||||
|
||||
Limits a number to a maximum value.
|
||||
|
||||
Input
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
title: capitalize
|
||||
---
|
||||
|
||||
{% since %}v1.9.1{% endsince %}
|
||||
|
||||
Makes the first character of a string capitalized.
|
||||
|
||||
Input
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
title: ceil
|
||||
---
|
||||
|
||||
{% since %}v1.9.1{% endsince %}
|
||||
|
||||
Rounds the input up to the nearest whole number. LiquidJS tries to convert the input to a number before the filter is applied.
|
||||
|
||||
Input
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
title: compact
|
||||
---
|
||||
|
||||
{% since %}v9.22.0{% endsince %}
|
||||
|
||||
Removes any `nil` values from an array.
|
||||
|
||||
For this example, assume `site.pages` is an array of content pages for a website, and some of these pages have an attribute called `category` that specifies their content category. If we `map` those categories to an array, some of the array items might be `nil` if any pages do not have a `category` attribute.
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
title: date
|
||||
---
|
||||
|
||||
{% since %}v1.9.1{% endsince %}
|
||||
|
||||
Converts a timestamp into another date format. LiquidJS tries to be conformant with Shopify/Liquid which is using Ruby's core [Time#strftime(string)](http://www.ruby-doc.org/core/Time.html#method-i-strftime). The input is firstly converted to `Date` object via [new Date()][newDate].
|
||||
|
||||
Input
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
title: default
|
||||
---
|
||||
|
||||
{% since %}v1.9.1{% endsince %}
|
||||
|
||||
Allows you to specify a fallback in case a value doesn't exist. `default` will show its value if the left side is [falsy][falsy] or empty (`string` or `Array`).
|
||||
|
||||
In this example, `product_price` is not defined, so the default value is used.
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
title: divided_by
|
||||
---
|
||||
|
||||
{% since %}v1.9.1{% endsince %}
|
||||
|
||||
Divides a number by another number. The result is the string obtained by JavaScript `.toString()` of the result number.
|
||||
|
||||
Input
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
title: downcase
|
||||
---
|
||||
|
||||
{% since %}v1.9.1{% endsince %}
|
||||
|
||||
Makes each character in a string lowercase. It has no effect on strings which are already all lowercase.
|
||||
|
||||
Input
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
title: escape
|
||||
---
|
||||
|
||||
{% since %}v1.9.1{% endsince %}
|
||||
|
||||
Escapes a string by replacing HTML special characters with escape sequences. It doesn't change strings that don't have anything to escape.
|
||||
|
||||
Input
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
title: escape_once
|
||||
---
|
||||
|
||||
{% since %}v1.9.1{% endsince %}
|
||||
|
||||
Escapes a string without changing existing escaped entities. It doesn't change strings that don't have anything to escape.
|
||||
|
||||
Input
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
title: first
|
||||
---
|
||||
|
||||
{% since %}v1.9.1{% endsince %}
|
||||
|
||||
Returns the first item of an array.
|
||||
|
||||
Input
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
title: floor
|
||||
---
|
||||
|
||||
{% since %}v1.9.1{% endsince %}
|
||||
|
||||
Rounds the input down to the nearest whole number. LiquidJS tries to convert the input to a number before the filter is applied.
|
||||
|
||||
Input
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
title: join
|
||||
---
|
||||
|
||||
{% since %}v1.9.1{% endsince %}
|
||||
|
||||
Combines the items in an array into a single string using the argument as a separator.
|
||||
|
||||
Input
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
title: json
|
||||
---
|
||||
|
||||
{% since %}v9.10.0{% endsince %}
|
||||
|
||||
Convert values to string via `JSON.stringify()`, for debug purpose.
|
||||
|
||||
Input
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
title: last
|
||||
---
|
||||
|
||||
{% since %}v1.9.1{% endsince %}
|
||||
|
||||
Returns the last item of an array.
|
||||
|
||||
Input
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
title: lstrip
|
||||
---
|
||||
|
||||
{% since %}v1.9.1{% endsince %}
|
||||
|
||||
Removes all whitespace (tabs, spaces, and newlines) from the left side of a string. It does not affect spaces between words.
|
||||
|
||||
Input
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
title: map
|
||||
---
|
||||
|
||||
{% since %}v1.9.1{% endsince %}
|
||||
|
||||
Creates an array of values by extracting the values of a named property from another object.
|
||||
|
||||
In this example, assume the object `site.pages` contains all the metadata for a website. Using `assign` with the `map` filter creates a variable that contains only the values of the `category` properties of everything in the `site.pages` object.
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
title: minus
|
||||
---
|
||||
|
||||
{% since %}v1.9.1{% endsince %}
|
||||
|
||||
Subtracts a number from another number.
|
||||
|
||||
Input
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
title: modulo
|
||||
---
|
||||
|
||||
{% since %}v1.9.1{% endsince %}
|
||||
|
||||
Returns the remainder of a division operation.
|
||||
|
||||
Input
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
title: newline_to_br
|
||||
---
|
||||
|
||||
{% since %}v1.9.1{% endsince %}
|
||||
|
||||
Replaces every newline (`\n`) in a string with an HTML line break (`<br />`).
|
||||
|
||||
Input
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
title: plus
|
||||
---
|
||||
|
||||
{% since %}v1.9.1{% endsince %}
|
||||
|
||||
Adds a number to another number.
|
||||
|
||||
Input
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
title: prepend
|
||||
---
|
||||
|
||||
{% since %}v1.9.1{% endsince %}
|
||||
|
||||
Adds the specified string to the beginning of another string.
|
||||
|
||||
Input
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
title: remove
|
||||
---
|
||||
|
||||
{% since %}v1.9.1{% endsince %}
|
||||
|
||||
Removes every occurrence of the specified substring from a string.
|
||||
|
||||
Input
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
title: remove_first
|
||||
---
|
||||
|
||||
{% since %}v1.9.1{% endsince %}
|
||||
|
||||
Removes only the first occurrence of the specified substring from a string.
|
||||
|
||||
Input
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
title: replace
|
||||
---
|
||||
|
||||
{% since %}v1.9.1{% endsince %}
|
||||
|
||||
Replaces every occurrence of the first argument in a string with the second argument.
|
||||
|
||||
Input
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
title: replace_first
|
||||
---
|
||||
|
||||
{% since %}v1.9.1{% endsince %}
|
||||
|
||||
Replaces only the first occurrence of the first argument in a string with the second argument.
|
||||
|
||||
Input
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
title: reverse
|
||||
---
|
||||
|
||||
{% since %}v1.9.1{% endsince %}
|
||||
|
||||
Reverses the order of the items in an array. `reverse` cannot reverse a string.
|
||||
|
||||
Input
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
title: round
|
||||
---
|
||||
|
||||
{% since %}v1.9.1{% endsince %}
|
||||
|
||||
Rounds a number to the nearest integer or, if a number is passed as an argument, to that number of decimal places.
|
||||
|
||||
Input
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
title: rstrip
|
||||
---
|
||||
|
||||
{% since %}v1.9.1{% endsince %}
|
||||
|
||||
Removes all whitespace (tabs, spaces, and newlines) from the right side of a string. It does not affect spaces between words.
|
||||
|
||||
Input
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
title: size
|
||||
---
|
||||
|
||||
{% since %}v1.9.1{% endsince %}
|
||||
|
||||
Returns the number of characters in a string or the number of items in an array.
|
||||
|
||||
Input
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
title: slice
|
||||
---
|
||||
|
||||
{% since %}v1.9.1{% endsince %}
|
||||
|
||||
Returns a substring of 1 character beginning at the index specified by the first argument. An optional second argument specifies the length of the substring to be returned.
|
||||
|
||||
String indices are numbered starting from 0.
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
title: sort
|
||||
---
|
||||
|
||||
{% since %}v1.9.1{% endsince %}
|
||||
|
||||
Sorts items in an array in case-sensitive order.
|
||||
|
||||
Input
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
title: sort_natural
|
||||
---
|
||||
|
||||
{% since %}v8.4.0{% endsince %}
|
||||
|
||||
Sorts items in an array in case-insensitive order.
|
||||
|
||||
Input
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
title: split
|
||||
---
|
||||
|
||||
{% since %}v1.9.1{% endsince %}
|
||||
|
||||
Divides a string into an array using the argument as a separator. `split` is commonly used to convert comma-separated items from a string to an array.
|
||||
|
||||
Input
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
title: strip
|
||||
---
|
||||
|
||||
{% since %}v1.9.1{% endsince %}
|
||||
|
||||
Removes all whitespace (tabs, spaces, and newlines) from both the left and right sides of a string. It does not affect spaces between words.
|
||||
|
||||
Input
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
title: strip_html
|
||||
---
|
||||
|
||||
{% since %}v1.9.1{% endsince %}
|
||||
|
||||
Removes any HTML tags from a string.
|
||||
|
||||
Input
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
title: strip_newlines
|
||||
---
|
||||
|
||||
{% since %}v1.9.1{% endsince %}
|
||||
|
||||
Removes any newline characters (line breaks) from a string.
|
||||
|
||||
Input
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
title: times
|
||||
---
|
||||
|
||||
{% since %}v1.9.1{% endsince %}
|
||||
|
||||
Multiplies a number by another number.
|
||||
|
||||
Input
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
title: truncate
|
||||
---
|
||||
|
||||
{% since %}v1.9.1{% endsince %}
|
||||
|
||||
Shortens a string down to the number of characters passed as an argument. If the specified number of characters is less than the length of the string, an ellipsis (...) is appended to the string and is included in the character count.
|
||||
|
||||
## Basic Usage
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
title: truncatewords
|
||||
---
|
||||
|
||||
{% since %}v1.9.1{% endsince %}
|
||||
|
||||
Shortens a string down to the number of words passed as an argument. If the specified number of words is less than the number of words in the string, an ellipsis (...) is appended to the string.
|
||||
|
||||
Input
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
title: uniq
|
||||
---
|
||||
|
||||
{% since %}v1.9.1{% endsince %}
|
||||
|
||||
Removes any duplicate elements in an array.
|
||||
|
||||
Input
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
title: upcase
|
||||
---
|
||||
|
||||
{% since %}v1.9.1{% endsince %}
|
||||
|
||||
Makes each character in a string uppercase. It has no effect on strings which are already all uppercase.
|
||||
|
||||
Input
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
title: url_decode
|
||||
---
|
||||
|
||||
{% since %}v6.1.0{% endsince %}
|
||||
|
||||
Decodes a string that has been encoded as a URL.
|
||||
|
||||
Input
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
title: url_encode
|
||||
---
|
||||
|
||||
{% since %}v1.9.1{% endsince %}
|
||||
|
||||
Converts any URL-unsafe characters in a string into percent-encoded characters.
|
||||
|
||||
Input
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
title: where
|
||||
---
|
||||
|
||||
{% since %}v8.1.0{% endsince %}
|
||||
|
||||
Creates an array including only the objects with a given property value, or any [truthy][truthy] value by default.
|
||||
|
||||
In this example, assume you have a list of products and you want to show your kitchen products separately. Using `where`, you can create an array containing only the products that have a `"type"` of `"kitchen"`.
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
title: Assign
|
||||
---
|
||||
|
||||
{% since %}v1.9.1{% endsince %}
|
||||
|
||||
Creates a new variable.
|
||||
|
||||
Input
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
title: capture
|
||||
---
|
||||
|
||||
{% since %}v1.9.1{% endsince %}
|
||||
|
||||
Captures the string inside of the opening and closing tags and assigns it to a variable. Variables created through `capture` are strings.
|
||||
|
||||
Input
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
title: case
|
||||
---
|
||||
|
||||
{% since %}v1.9.1{% endsince %}
|
||||
|
||||
Creates a switch statement to compare a variable with different values. `case` initializes the switch statement, and `when` compares its values.
|
||||
|
||||
Input
|
||||
@@ -10,7 +12,7 @@ Input
|
||||
{% case handle %}
|
||||
{% when "cake" %}
|
||||
This is a cake
|
||||
{% when "cookie" %}
|
||||
{% when "cookie", "biscuit" %}
|
||||
This is a cookie
|
||||
{% else %}
|
||||
This is not a cake nor a cookie
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
title: Comment
|
||||
---
|
||||
|
||||
{% since %}v1.9.1{% endsince %}
|
||||
|
||||
Allows you to leave un-rendered code inside a Liquid template. Any text within the opening and closing `comment` blocks will not be printed, and any Liquid code within will not be executed.
|
||||
|
||||
Input
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
title: cycle
|
||||
---
|
||||
|
||||
{% since %}v1.9.1{% endsince %}
|
||||
|
||||
Loops through a group of strings and prints them in the order that they were passed as arguments. Each time `cycle` is called, the next string argument is printed.
|
||||
|
||||
## Basic Usage
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
title: Decrement
|
||||
---
|
||||
|
||||
{% since %}v1.9.1{% endsince %}
|
||||
|
||||
Creates a new number variable, and decreases its value by one every time it is called. The first value is `-1`.
|
||||
|
||||
Input
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
title: For
|
||||
---
|
||||
|
||||
{% since %}v1.9.1{% endsince %}
|
||||
|
||||
Iteration tags run blocks of code repeatedly.
|
||||
|
||||
## Basic Usage
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
title: If
|
||||
---
|
||||
|
||||
{% since %}v1.9.1{% endsince %}
|
||||
|
||||
Executes a block of code only if a certain condition is `true`.
|
||||
|
||||
## if
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
title: Include
|
||||
---
|
||||
|
||||
{% since %}v1.9.1{% endsince %}
|
||||
|
||||
{% note warn Deprecated %}
|
||||
This tag is deprecated, use <a href="./render.html">render</a> tag instead for better encapsulation.
|
||||
{% endnote %}
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
title: Increment
|
||||
---
|
||||
|
||||
{% since %}v1.9.1{% endsince %}
|
||||
|
||||
Creates a new number variable, and increases its value by one every time it is called. The first value is `0`.
|
||||
|
||||
Input
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
title: Layout
|
||||
---
|
||||
|
||||
{% since %}v1.9.1{% endsince %}
|
||||
|
||||
## Using a Layout Template
|
||||
|
||||
Renders current template inside a layout template from the template [roots][root].
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
title: Raw
|
||||
---
|
||||
|
||||
{% since %}v1.9.1{% endsince %}
|
||||
|
||||
Raw temporarily disables tag processing. This is useful for generating content
|
||||
(eg, Mustache, Handlebars) which uses conflicting syntax.
|
||||
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
title: Render
|
||||
---
|
||||
|
||||
{% since %}v9.2.0{% endsince %}
|
||||
|
||||
## Basic Usage
|
||||
|
||||
### Render a Template
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
title: Table Row
|
||||
---
|
||||
|
||||
{% since %}v1.9.1{% endsince %}
|
||||
|
||||
Generates an HTML table. Must be wrapped in opening `<table>` and closing `</table>` HTML tags.
|
||||
|
||||
## Basic Usage
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
title: Unless
|
||||
---
|
||||
|
||||
{% since %}v1.9.1{% endsince %}
|
||||
|
||||
The opposite of `if` – executes a block of code only if a certain condition is **not** met.
|
||||
|
||||
Input
|
||||
|
||||
@@ -4,15 +4,17 @@ title: Register Filters/Tags
|
||||
|
||||
## Register Tags
|
||||
|
||||
```javascript
|
||||
```typescript
|
||||
// Usage: {% upper name %}
|
||||
import { TagToken, Context, Emitter, TopLevelToken } from 'liquidjs'
|
||||
|
||||
engine.registerTag('upper', {
|
||||
parse: function(tagToken, remainTokens) {
|
||||
parse: function(tagToken: TagToken, remainTokens: TopLevelToken[]) {
|
||||
this.str = tagToken.args; // name
|
||||
},
|
||||
render: async function(scope, hash) {
|
||||
var str = await this.liquid.evalValue(this.str, scope); // 'alice'
|
||||
return str.toUpperCase() // 'Alice'
|
||||
render: async function(ctx: Context) {
|
||||
var str = await this.liquid.evalValue(this.str, ctx); // 'alice'
|
||||
return str.toUpperCase() // 'ALICE'
|
||||
}
|
||||
});
|
||||
```
|
||||
@@ -21,6 +23,7 @@ engine.registerTag('upper', {
|
||||
* `render`: Combine scope data with your parsed tokens into HTML string.
|
||||
|
||||
See existing tag implementations here: <https://github.com/harttle/liquidjs/tree/master/src/builtin/tags>
|
||||
See demo example here: https://github.com/harttle/liquidjs/blob/master/demo/typescript/index.ts
|
||||
|
||||
## Register Filters
|
||||
|
||||
@@ -37,3 +40,25 @@ engine.registerFilter('add', (initial, arg1, arg2) => initial + arg1 + arg2)
|
||||
```
|
||||
|
||||
See existing filter implementations here: <https://github.com/harttle/liquidjs/tree/master/src/builtin/filters>
|
||||
|
||||
## Unregister Tags/Filters
|
||||
|
||||
In some cases it's desirable to disable some tags/filters (see [#324](https://github.com/harttle/liquidjs/issues/324)), you'll need to register a dummy tag/filter in which an corresponding Error throws.
|
||||
|
||||
```javascript
|
||||
// disable a tag
|
||||
const disabledTag = {
|
||||
parse: function(token) {
|
||||
throw new Error(`tag "${token.name}" disabled`);
|
||||
}
|
||||
}
|
||||
engine.registerTag('include', disabledTag);
|
||||
|
||||
// disable a filter
|
||||
function disabledFilter(name) {
|
||||
return function () {
|
||||
throw new Error(`filter "${name}" disabled`);
|
||||
}
|
||||
}
|
||||
engine.registerFilter('plus', disabledFilter('plus'));
|
||||
```
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
title: abs
|
||||
---
|
||||
|
||||
{% since %}v1.9.1{% endsince %}
|
||||
|
||||
返回数字的绝对值。
|
||||
|
||||
输入
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
title: append
|
||||
---
|
||||
|
||||
{% since %}v1.9.1{% endsince %}
|
||||
|
||||
连接两个字符串并返回结果。
|
||||
|
||||
输入
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
title: at_least
|
||||
---
|
||||
|
||||
{% since %}v8.4.0{% endsince %}
|
||||
|
||||
限制数字到某个最小值。
|
||||
|
||||
输入
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
title: at_most
|
||||
---
|
||||
|
||||
{% since %}v8.4.0{% endsince %}
|
||||
|
||||
限制数字到某个最大值。
|
||||
|
||||
输入
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
title: capitalize
|
||||
---
|
||||
|
||||
{% since %}v1.9.1{% endsince %}
|
||||
|
||||
把字符串首字母改为大写。
|
||||
|
||||
输入
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
title: ceil
|
||||
---
|
||||
|
||||
{% since %}v1.9.1{% endsince %}
|
||||
|
||||
向上取整,取整前 LiquidJS 会首先把输入转换为数字。
|
||||
|
||||
输入
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
title: compact
|
||||
---
|
||||
|
||||
{% since %}v9.22.0{% endsince %}
|
||||
|
||||
从数组里移除任何 `null` 和 `undefined` 值。
|
||||
|
||||
假设 `site.pages` 是网页列表,有些网页包含 `category` 属性用来标明类别。如果把它们 `map` 到数组里,那么对于没有 `category` 属性的元素就会是 `undefined`。
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
title: date
|
||||
---
|
||||
|
||||
{% since %}v1.9.1{% endsince %}
|
||||
|
||||
把时间戳转换为字符串。LiquidJS 尝试跟 Shopify/Liquid 保持一致,它用的是 Ruby 核心的 [Time#strftime(string)](http://www.ruby-doc.org/core/Time.html#method-i-strftime)。此外 LiquidJS 会先通过 [new Date()][newDate] 尝试把输入转换为 Date 对象。
|
||||
|
||||
输入
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
title: default
|
||||
---
|
||||
|
||||
{% since %}v1.9.1{% endsince %}
|
||||
|
||||
在值不存在时给一个默认值,如果左侧是 [falsy][falsy] 或空(`string` 或 `Array`)就会使用这个默认值。下面的例子中 `product_price` 没有定义,因此使用了默认值。
|
||||
|
||||
输入
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
title: divided_by
|
||||
---
|
||||
|
||||
{% since %}v1.9.1{% endsince %}
|
||||
|
||||
两数相除返回商,返回结果数字在 JavaScript 中 `.toString()` 得到的字符串。
|
||||
|
||||
输入
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
title: downcase
|
||||
---
|
||||
|
||||
{% since %}v1.9.1{% endsince %}
|
||||
|
||||
字符串中每个字符都转为小写,对已经是小写的字符没有影响。
|
||||
|
||||
输入
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
title: escape
|
||||
---
|
||||
|
||||
{% since %}v1.9.1{% endsince %}
|
||||
|
||||
把字符串中的 HTML 特殊字符转义,对不需要转义的字符串不会产生影响。
|
||||
|
||||
输入
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
title: escape_once
|
||||
---
|
||||
|
||||
{% since %}v1.9.1{% endsince %}
|
||||
|
||||
把字符串中的特殊字符转义得到可用在 URL 里的字符串,对已经转义过的字符串和不需要转义的字符串不会产生影响。
|
||||
|
||||
输入
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
title: first
|
||||
---
|
||||
|
||||
{% since %}v1.9.1{% endsince %}
|
||||
|
||||
返回数组的第一个元素。
|
||||
|
||||
输入
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
title: floor
|
||||
---
|
||||
|
||||
{% since %}v1.9.1{% endsince %}
|
||||
|
||||
数字下取整,LiquidJS 会尝试把输入转换为数字再做下取整操作。
|
||||
|
||||
输入
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
title: join
|
||||
---
|
||||
|
||||
{% since %}v1.9.1{% endsince %}
|
||||
|
||||
把数组中的元素连接成为一个字符串,以传入的参数作为分隔符。
|
||||
|
||||
输入
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
title: json
|
||||
---
|
||||
|
||||
{% since %}v9.10.0{% endsince %}
|
||||
|
||||
通过 `JSON.stringify()` 把值转换为字符串,多用于调试用途。
|
||||
|
||||
输入
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
title: last
|
||||
---
|
||||
|
||||
{% since %}v1.9.1{% endsince %}
|
||||
|
||||
返回数组的最后一个元素。
|
||||
|
||||
输入
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
title: lstrip
|
||||
---
|
||||
|
||||
{% since %}v1.9.1{% endsince %}
|
||||
|
||||
移除字符串左侧的空白字符(制表符、空格、换行),不影响词之间的空格。
|
||||
|
||||
输入
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
title: map
|
||||
---
|
||||
|
||||
{% since %}v1.9.1{% endsince %}
|
||||
|
||||
按照属性名提取对象的属性形成另一个数组并返回。
|
||||
|
||||
下面的例子中假设 `site.pages` 包含了站点的所有网页元信息。使用 `assign` 加 `map` 过滤器创建了一个 `site.pages` 中所有对象的 `category` 属性的值构成的数组。
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
title: minus
|
||||
---
|
||||
|
||||
{% since %}v1.9.1{% endsince %}
|
||||
|
||||
两数相减。
|
||||
|
||||
输入
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
title: modulo
|
||||
---
|
||||
|
||||
{% since %}v1.9.1{% endsince %}
|
||||
|
||||
返回两数相除的余数。
|
||||
|
||||
输入
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
title: newline_to_br
|
||||
---
|
||||
|
||||
{% since %}v1.9.1{% endsince %}
|
||||
|
||||
把字符串里的所有换行符(`\n`)替换为 HTML 换行(`<br />`)。
|
||||
|
||||
输入
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
title: plus
|
||||
---
|
||||
|
||||
{% since %}v1.9.1{% endsince %}
|
||||
|
||||
两数相加。
|
||||
|
||||
输入
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
title: prepend
|
||||
---
|
||||
|
||||
{% since %}v1.9.1{% endsince %}
|
||||
|
||||
在字符串开头添加另一个字符串。
|
||||
|
||||
输入
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
title: remove
|
||||
---
|
||||
|
||||
{% since %}v1.9.1{% endsince %}
|
||||
|
||||
移除字符串中出现的所有指定子字符串。
|
||||
|
||||
输入
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
title: remove_first
|
||||
---
|
||||
|
||||
{% since %}v1.9.1{% endsince %}
|
||||
|
||||
移除字符串中出现的第一个指定子字符串。
|
||||
|
||||
输入
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
title: replace
|
||||
---
|
||||
|
||||
{% since %}v1.9.1{% endsince %}
|
||||
|
||||
把字符串中出现的每一个指定子字符串替换为另一个字符串。
|
||||
|
||||
输入
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user