1010//! - **Argument ordering**: Maintains Python-like behavior with positional args before keyword args
1111//! - **Spread operators**: Handles `...list` and `**dict` spread syntax
1212//! - **Filter compilation**: Converts Django filter chains to Python expressions
13- //! - **Value type handling**: Properly handles strings, numbers, variables, expressions , etc.
13+ //! - **Value type handling**: Properly handles strings, numbers, variables, template_strings , etc.
1414//! - **Error detection**: Compile-time detection of invalid argument ordering
1515//! - **Indentation**: Properly indents generated code for readability
1616//!
@@ -100,7 +100,7 @@ pub fn compile_ast_to_string(attributes: &[TagAttr]) -> Result<String, CompileEr
100100 }
101101
102102 let mut final_code = String :: new ( ) ;
103- let signature = "def compiled_func(context, *, expression , translation, variable, filter):" ;
103+ let signature = "def compiled_func(context, *, template_string , translation, variable, filter):" ;
104104 final_code. push_str ( signature) ;
105105 final_code. push_str ( "\n " ) ;
106106
@@ -163,7 +163,7 @@ fn compile_value(value: &TagValue) -> Result<String, CompileError> {
163163 Ok ( value. token . token . clone ( ) )
164164 }
165165 ValueKind :: Variable => Ok ( format ! ( "variable(context, '{}')" , value. token. token) ) ,
166- ValueKind :: Expression => Ok ( format ! ( "expression (context, {})" , value. token. token) ) ,
166+ ValueKind :: TemplateString => Ok ( format ! ( "template_string (context, {})" , value. token. token) ) ,
167167 ValueKind :: Translation => {
168168 let inner_string_start = value. token . token . find ( '(' ) . map ( |i| i + 1 ) . unwrap_or ( 0 ) ;
169169 let inner_string_end = value
@@ -281,7 +281,7 @@ mod tests {
281281 TagValue {
282282 token : create_tag_token ( & quoted_token) ,
283283 children : vec ! [ ] ,
284- kind : ValueKind :: Expression ,
284+ kind : ValueKind :: TemplateString ,
285285 spread : None ,
286286 filters : vec ! [ ] ,
287287 start_index : 0 ,
@@ -344,7 +344,7 @@ mod tests {
344344 fn test_no_attributes ( ) {
345345 let ast = vec ! [ ] ;
346346 let result = compile_ast_to_string ( & ast) . unwrap ( ) ;
347- let expected = r#"def compiled_func(context, *, expression , translation, variable, filter):
347+ let expected = r#"def compiled_func(context, *, template_string , translation, variable, filter):
348348 args = []
349349 kwargs = []
350350 return args, kwargs"# ;
@@ -355,7 +355,7 @@ mod tests {
355355 fn test_single_arg ( ) {
356356 let ast = vec ! [ create_arg_attr( create_var_tag_value( "my_var" ) ) ] ;
357357 let result = compile_ast_to_string ( & ast) . unwrap ( ) ;
358- let expected = r#"def compiled_func(context, *, expression , translation, variable, filter):
358+ let expected = r#"def compiled_func(context, *, template_string , translation, variable, filter):
359359 args = []
360360 kwargs = []
361361 args.append(variable(context, 'my_var'))
@@ -371,7 +371,7 @@ mod tests {
371371 create_arg_attr( create_int_tag_value( 123 ) ) ,
372372 ] ;
373373 let result = compile_ast_to_string ( & ast) . unwrap ( ) ;
374- let expected = r#"def compiled_func(context, *, expression , translation, variable, filter):
374+ let expected = r#"def compiled_func(context, *, template_string , translation, variable, filter):
375375 args = []
376376 kwargs = []
377377 args.append(variable(context, 'my_var'))
@@ -385,7 +385,7 @@ mod tests {
385385 fn test_single_kwarg ( ) {
386386 let ast = vec ! [ create_kwarg_attr( "key" , create_var_tag_value( "my_var" ) ) ] ;
387387 let result = compile_ast_to_string ( & ast) . unwrap ( ) ;
388- let expected = r#"def compiled_func(context, *, expression , translation, variable, filter):
388+ let expected = r#"def compiled_func(context, *, template_string , translation, variable, filter):
389389 args = []
390390 kwargs = []
391391 kwargs.append(('key', variable(context, 'my_var')))
@@ -400,7 +400,7 @@ mod tests {
400400 create_kwarg_attr( "key2" , create_string_tag_value( "hello" ) ) ,
401401 ] ;
402402 let result = compile_ast_to_string ( & ast) . unwrap ( ) ;
403- let expected = r#"def compiled_func(context, *, expression , translation, variable, filter):
403+ let expected = r#"def compiled_func(context, *, template_string , translation, variable, filter):
404404 args = []
405405 kwargs = []
406406 kwargs.append(('key1', variable(context, 'my_var')))
@@ -416,7 +416,7 @@ mod tests {
416416 create_kwarg_attr( "key" , create_string_tag_value( "value" ) ) ,
417417 ] ;
418418 let result = compile_ast_to_string ( & ast) . unwrap ( ) ;
419- let expected = r#"def compiled_func(context, *, expression , translation, variable, filter):
419+ let expected = r#"def compiled_func(context, *, template_string , translation, variable, filter):
420420 args = []
421421 kwargs = []
422422 args.append(42)
@@ -434,7 +434,7 @@ mod tests {
434434 create_kwarg_attr( "key" , create_string_tag_value( "value" ) ) ,
435435 ] ;
436436 let result = compile_ast_to_string ( & ast) . unwrap ( ) ;
437- let expected = r#"def compiled_func(context, *, expression , translation, variable, filter):
437+ let expected = r#"def compiled_func(context, *, template_string , translation, variable, filter):
438438 def _handle_spread(value, raw_token_str, args, kwargs, kwarg_seen):
439439 if hasattr(value, "keys"):
440440 kwargs.extend(value.items())
@@ -471,7 +471,7 @@ mod tests {
471471 create_kwarg_attr( "key2" , create_string_tag_value( "value2" ) ) ,
472472 ] ;
473473 let result = compile_ast_to_string ( & ast) . unwrap ( ) ;
474- let expected = r#"def compiled_func(context, *, expression , translation, variable, filter):
474+ let expected = r#"def compiled_func(context, *, template_string , translation, variable, filter):
475475 def _handle_spread(value, raw_token_str, args, kwargs, kwarg_seen):
476476 if hasattr(value, "keys"):
477477 kwargs.extend(value.items())
@@ -499,13 +499,13 @@ mod tests {
499499 }
500500
501501 #[ test]
502- fn test_expression_arg ( ) {
502+ fn test_template_string_arg ( ) {
503503 let ast = vec ! [ create_arg_attr( create_expr_tag_value( "\" {{ my_var }}\" " ) ) ] ;
504504 let result = compile_ast_to_string ( & ast) . unwrap ( ) ;
505- let expected = r#"def compiled_func(context, *, expression , translation, variable, filter):
505+ let expected = r#"def compiled_func(context, *, template_string , translation, variable, filter):
506506 args = []
507507 kwargs = []
508- args.append(expression (context, "{{ my_var }}"))
508+ args.append(template_string (context, "{{ my_var }}"))
509509 return args, kwargs"# ;
510510 assert_eq ! ( result, expected. to_string( ) ) ;
511511 }
@@ -514,7 +514,7 @@ mod tests {
514514 fn test_translation_arg ( ) {
515515 let ast = vec ! [ create_arg_attr( create_trans_tag_value( "\" hello world\" " ) ) ] ;
516516 let result = compile_ast_to_string ( & ast) . unwrap ( ) ;
517- let expected = r#"def compiled_func(context, *, expression , translation, variable, filter):
517+ let expected = r#"def compiled_func(context, *, template_string , translation, variable, filter):
518518 args = []
519519 kwargs = []
520520 args.append(translation(context, "hello world"))
@@ -534,7 +534,7 @@ mod tests {
534534 } ) ;
535535 let ast = vec ! [ create_arg_attr( value) ] ;
536536 let result = compile_ast_to_string ( & ast) . unwrap ( ) ;
537- let expected = r#"def compiled_func(context, *, expression , translation, variable, filter):
537+ let expected = r#"def compiled_func(context, *, template_string , translation, variable, filter):
538538 args = []
539539 kwargs = []
540540 args.append(filter(context, 'upper', variable(context, 'my_var'), None))
@@ -554,7 +554,7 @@ mod tests {
554554 } ) ;
555555 let ast = vec ! [ create_arg_attr( value) ] ;
556556 let result = compile_ast_to_string ( & ast) . unwrap ( ) ;
557- let expected = r#"def compiled_func(context, *, expression , translation, variable, filter):
557+ let expected = r#"def compiled_func(context, *, template_string , translation, variable, filter):
558558 args = []
559559 kwargs = []
560560 args.append(filter(context, 'default', variable(context, 'my_var'), "none"))
@@ -581,7 +581,7 @@ mod tests {
581581 } ) ;
582582 let ast = vec ! [ create_arg_attr( value) ] ;
583583 let result = compile_ast_to_string ( & ast) . unwrap ( ) ;
584- let expected = r#"def compiled_func(context, *, expression , translation, variable, filter):
584+ let expected = r#"def compiled_func(context, *, template_string , translation, variable, filter):
585585 args = []
586586 kwargs = []
587587 args.append(filter(context, 'default', filter(context, 'upper', variable(context, 'my_var'), None), "none"))
@@ -603,7 +603,7 @@ mod tests {
603603 } ;
604604 let ast = vec ! [ create_arg_attr( list_value) ] ;
605605 let result = compile_ast_to_string ( & ast) . unwrap ( ) ;
606- let expected = r#"def compiled_func(context, *, expression , translation, variable, filter):
606+ let expected = r#"def compiled_func(context, *, template_string , translation, variable, filter):
607607 args = []
608608 kwargs = []
609609 args.append([1, variable(context, 'my_var')])
@@ -628,7 +628,7 @@ mod tests {
628628 } ;
629629 let ast = vec ! [ create_kwarg_attr( "data" , dict_value) ] ;
630630 let result = compile_ast_to_string ( & ast) . unwrap ( ) ;
631- let expected = r#"def compiled_func(context, *, expression , translation, variable, filter):
631+ let expected = r#"def compiled_func(context, *, template_string , translation, variable, filter):
632632 args = []
633633 kwargs = []
634634 kwargs.append(('data', {"key": variable(context, 'my_var')}))
@@ -651,7 +651,7 @@ mod tests {
651651 ] ;
652652 let result = compile_ast_to_string ( & ast) . unwrap ( ) ;
653653
654- let expected = r#"def compiled_func(context, *, expression , translation, variable, filter):
654+ let expected = r#"def compiled_func(context, *, template_string , translation, variable, filter):
655655 def _handle_spread(value, raw_token_str, args, kwargs, kwarg_seen):
656656 if hasattr(value, "keys"):
657657 kwargs.extend(value.items())
@@ -689,7 +689,7 @@ mod tests {
689689 flag_attr,
690690 ] ;
691691 let result = compile_ast_to_string ( & ast) . unwrap ( ) ;
692- let expected = r#"def compiled_func(context, *, expression , translation, variable, filter):
692+ let expected = r#"def compiled_func(context, *, template_string , translation, variable, filter):
693693 args = []
694694 kwargs = []
695695 kwargs.append(('key', "value"))
0 commit comments