@@ -88,12 +88,13 @@ impl TemplateData {
88
88
}
89
89
90
90
pub mod filters {
91
+ use askama:: Values ;
91
92
use askama:: filters:: Safe ;
92
93
use chrono:: { DateTime , Utc } ;
93
94
use std:: borrow:: Cow ;
94
95
95
96
// Copied from `tera`.
96
- pub fn escape_html ( input : & str ) -> askama:: Result < Cow < ' _ , str > > {
97
+ pub fn escape_html < ' a > ( input : & ' a str , _ : & dyn Values ) -> askama:: Result < Cow < ' a , str > > {
97
98
if !input. chars ( ) . any ( |c| "&<>\" '/" . contains ( c) ) {
98
99
return Ok ( Cow :: Borrowed ( input) ) ;
99
100
}
@@ -115,7 +116,7 @@ pub mod filters {
115
116
}
116
117
117
118
// Copied from `tera`.
118
- pub fn escape_xml ( input : & str ) -> askama:: Result < Cow < ' _ , str > > {
119
+ pub fn escape_xml < ' a > ( input : & ' a str , _ : & dyn Values ) -> askama:: Result < Cow < ' a , str > > {
119
120
if !input. chars ( ) . any ( |c| "&<>\" '" . contains ( c) ) {
120
121
return Ok ( Cow :: Borrowed ( input) ) ;
121
122
}
@@ -135,11 +136,11 @@ pub mod filters {
135
136
136
137
/// Prettily format a timestamp
137
138
// TODO: This can be replaced by chrono
138
- pub fn timeformat ( value : & DateTime < Utc > ) -> askama:: Result < String > {
139
+ pub fn timeformat ( value : & DateTime < Utc > , _ : & dyn Values ) -> askama:: Result < String > {
139
140
Ok ( crate :: web:: duration_to_str ( * value) )
140
141
}
141
142
142
- pub fn format_secs ( mut value : f32 ) -> askama:: Result < String > {
143
+ pub fn format_secs ( mut value : f32 , _ : & dyn Values ) -> askama:: Result < String > {
143
144
const TIMES : & [ & str ] = & [ "seconds" , "minutes" , "hours" ] ;
144
145
145
146
let mut chosen_time = & TIMES [ 0 ] ;
@@ -166,6 +167,7 @@ pub mod filters {
166
167
#[ allow( clippy:: unnecessary_wraps) ]
167
168
pub fn dedent < T : std:: fmt:: Display , I : Into < Option < i32 > > > (
168
169
value : T ,
170
+ _: & dyn Values ,
169
171
levels : I ,
170
172
) -> askama:: Result < String > {
171
173
let string = value. to_string ( ) ;
@@ -200,7 +202,11 @@ pub mod filters {
200
202
Ok ( unindented)
201
203
}
202
204
203
- pub fn highlight ( code : impl std:: fmt:: Display , lang : & str ) -> askama:: Result < Safe < String > > {
205
+ pub fn highlight (
206
+ code : impl std:: fmt:: Display ,
207
+ _: & dyn Values ,
208
+ lang : & str ,
209
+ ) -> askama:: Result < Safe < String > > {
204
210
let highlighted_code =
205
211
crate :: web:: highlight:: with_lang ( Some ( lang) , & code. to_string ( ) , None ) ;
206
212
Ok ( Safe ( format ! (
@@ -209,7 +215,7 @@ pub mod filters {
209
215
) ) )
210
216
}
211
217
212
- pub fn round ( value : & f32 , precision : u32 ) -> askama:: Result < String > {
218
+ pub fn round ( value : & f32 , _ : & dyn Values , precision : u32 ) -> askama:: Result < String > {
213
219
let multiplier = if precision == 0 {
214
220
1.0
215
221
} else {
@@ -218,11 +224,18 @@ pub mod filters {
218
224
Ok ( ( ( multiplier * * value) . round ( ) / multiplier) . to_string ( ) )
219
225
}
220
226
221
- pub fn split_first < ' a > ( value : & ' a str , pat : & str ) -> askama:: Result < Option < & ' a str > > {
227
+ pub fn split_first < ' a > (
228
+ value : & ' a str ,
229
+ _: & dyn Values ,
230
+ pat : & str ,
231
+ ) -> askama:: Result < Option < & ' a str > > {
222
232
Ok ( value. split ( pat) . next ( ) )
223
233
}
224
234
225
- pub fn json_encode < T : ?Sized + serde:: Serialize > ( value : & T ) -> askama:: Result < Safe < String > > {
235
+ pub fn json_encode < T : ?Sized + serde:: Serialize > (
236
+ value : & T ,
237
+ _: & dyn Values ,
238
+ ) -> askama:: Result < Safe < String > > {
226
239
Ok ( Safe (
227
240
serde_json:: to_string ( value) . expect ( "`encode_json` failed" ) ,
228
241
) )
0 commit comments