@@ -54,11 +54,6 @@ pub struct Jinja {
5454 context : BTreeMap < String , Value > ,
5555}
5656
57- struct ForceString {
58- value : String ,
59- force : bool ,
60- }
61-
6257impl Jinja {
6358 /// Create a new Jinja instance with the given selector configuration.
6459 pub fn new ( config : SelectorConfig ) -> Self {
@@ -100,24 +95,23 @@ impl Jinja {
10095 }
10196
10297 /// Render a template with the current context.
103- pub fn render_str ( & self , template : & str ) -> Result < String , minijinja:: Error > {
98+ pub fn render_str ( & self , template : & str ) -> Result < ( String , bool ) , minijinja:: Error > {
10499 if template. starts_with ( "${{" ) && template. ends_with ( "}}" ) {
105100 // render as expression so that we know the type of the result, and can stringify accordingly
106101 // If we find something like "${{ foo }}" then we want to evaluate it type-safely and make sure that the MiniJinja type is kept
107- println ! ( "eval: {:?}" , template) ;
108102 let tmplt = & template[ 3 ..template. len ( ) - 2 ] ;
109103 let expr = self . env . compile_expression ( tmplt) ?;
110104 let evaled = expr. eval ( self . context ( ) ) ?;
111105 if let Some ( s) = evaled. to_str ( ) {
112- // quote the string so that YAML is not getting confused
113- println ! ( "evaled: {:?}" , s) ;
114- return Ok ( format ! ( "\" {}\" " , s) ) ;
106+ // Make sure that the string stays a string by returning can_coerce: false
107+ return Ok ( ( s. to_string ( ) , false ) ) ;
115108 } else {
116- return Ok ( evaled. to_string ( ) ) ;
109+ return Ok ( ( evaled. to_string ( ) , true ) ) ;
117110 }
118111 }
119112
120- self . env . render_str ( template, & self . context )
113+ let rendered = self . env . render_str ( template, & self . context ) ?;
114+ Ok ( ( rendered, !template. contains ( "${{" ) ) )
121115 }
122116
123117 /// Render, compile and evaluate a expr string with the current context.
0 commit comments