Add filter documentation in User Guide

This commit is contained in:
Kogia-sima 2020-07-17 18:06:06 +09:00
parent d0ef795161
commit 9dfcfe2c45
3 changed files with 49 additions and 2 deletions

View File

@ -0,0 +1,37 @@
# Filters
Filters are used to format the rendered contents.
Example:
```ejs
message: <%= "foo\nbar" | dbg %>
```
Output:
```html
message: &quot;foo\nbar&quot;
```
!!! Note
Since `dbg` filter accepts '<T: std::fmt::Debug>' types, that type isn't required to implement [`Render`](https://docs.rs/sailfish/latest/sailfish/runtime/trait.Render.html) trait. That means you can pass the type which doen't implement `Render` trait.
## Syntax
- Apply filter and HTML escaping
```ejs
<%= expression | filter %>
```
- Apply filter only
```ejs
<%- expression | filter %>
```
## Built-In Filters
Built-In filters can be found in [`sailfish::runtime::filter`](https://docs.rs/sailfish/latest/sailfish/runtime/filter/index.html) module.

View File

@ -32,6 +32,15 @@
Unlike EJS, you cannot omit the file extension.
## Helpers
## Filters
(Work in progress)
```ejs
<%= message | upper %>
```
```ejs
{
"id": <%= id %>
"comment": <%- comment | dbg %>
}
```

View File

@ -50,3 +50,4 @@ nav:
- 'Overview': 'syntax/overview.md'
- 'Tags': 'syntax/tags.md'
- 'Includes': 'syntax/includes.md'
- 'Filters': 'syntax/filters.md'