Skip to content

Commit 5b03057

Browse files
committed
add more span stuff
1 parent 0ae50f8 commit 5b03057

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed

src/recipe/jinja.rs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -138,24 +138,24 @@ impl Jinja {
138138
}
139139

140140
/// Render a template with the current context.
141-
// pub fn render_str(&self, template: &str) -> Result<(String, bool), minijinja::Error> {
142-
// if template.starts_with("${{") && template.ends_with("}}") {
143-
// // render as expression so that we know the type of the result, and can stringify accordingly
144-
// // If we find something like "${{ foo }}" then we want to evaluate it type-safely and make sure that the MiniJinja type is kept
145-
// let tmplt = &template[3..template.len() - 2];
146-
// let expr = self.env.compile_expression(tmplt)?;
147-
// let evaled = expr.eval(self.context())?;
148-
// if let Some(s) = evaled.to_str() {
149-
// // Make sure that the string stays a string by returning can_coerce: false
150-
// return Ok((s.to_string(), false));
151-
// } else {
152-
// return Ok((evaled.to_string(), true));
153-
// }
154-
// }
155-
156-
// let rendered = self.env.render_str(template, &self.context)?;
157-
// Ok((rendered, !template.contains("${{")))
158-
// }
141+
pub fn render_str(&self, template: &str) -> Result<(String, bool), minijinja::Error> {
142+
if template.starts_with("${{") && template.ends_with("}}") {
143+
// render as expression so that we know the type of the result, and can stringify accordingly
144+
// If we find something like "${{ foo }}" then we want to evaluate it type-safely and make sure that the MiniJinja type is kept
145+
let tmplt = &template[3..template.len() - 2];
146+
let expr = self.env.compile_expression(tmplt)?;
147+
let evaled = expr.eval(self.context())?;
148+
if let Some(s) = evaled.to_str() {
149+
// Make sure that the string stays a string by returning can_coerce: false
150+
return Ok((s.to_string(), false));
151+
} else {
152+
return Ok((evaled.to_string(), true));
153+
}
154+
}
155+
156+
let rendered = self.env.render_str(template, &self.context)?;
157+
Ok((rendered, !template.contains("${{")))
158+
}
159159

160160
/// Render, compile and evaluate a expr string with the current context.
161161
pub fn eval(&self, str: &str) -> Result<Value, minijinja::Error> {

0 commit comments

Comments
 (0)