1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
//! Built-in filters.
//!
//! # Build your own filter
//!
//! Filters are normal Rust functions
//! where the first argument is the expression before the filter
//! and the second one is the first passed to the filter in the template.
//!
//! ```rust
//! use oxiplate::{Oxiplate, Render};
//!
//! mod filters_for_oxiplate {
//! use std::borrow::Cow;
//!
//! use oxiplate::CowStr;
//!
//! /// Your custom filter.
//! /// `expression` is the expression preceding the filter in the template.
//! /// `replacement` is the first argument passed in the template.
//! ///
//! /// In the following example,
//! /// `>some_variable` is passed in for `expression`
//! /// and `"·"` is passed in for `replacement`:
//! ///
//! /// ```oxip
//! /// {{ >some_variable | your_filter("·") }}`
//! /// ```
//! ///
//! /// The `CowStr` trait is used for more efficient string conversion.
//! pub fn your_filter<'a, E: CowStr<'a>>(expression: E, replacement: &str) -> Cow<'a, str> {
//! let expression = expression.cow_str();
//!
//! if expression.contains(' ') {
//! expression.replace(' ', replacement).into()
//! } else {
//! expression
//! }
//! }
//! }
//!
//! fn main() -> Result<(), ::core::fmt::Error> {
//! #[derive(Oxiplate)]
//! #[oxiplate_inline(html: r#"{{ >"hello world!" | your_filter("·") }}"#)]
//! struct Data;
//!
//! assert_eq!(Data.render()?, "hello·world!");
//!
//! Ok::<(), ::core::fmt::Error>(())
//! }
//! ```
pub use default;
pub use lower;
pub use ;
pub use upper;