File tree Expand file tree Collapse file tree 2 files changed +37
-11
lines changed Expand file tree Collapse file tree 2 files changed +37
-11
lines changed Original file line number Diff line number Diff line change @@ -317,6 +317,34 @@ pub(crate) fn configure_tera_env(tera: &mut Tera, crate_name: &str) {
317
317
let case = expect_str ( expect_arg ( args, "case" ) ?) ?;
318
318
Ok ( Value :: String ( str. to_case ( case_from_str ( case) ?) ) )
319
319
} ,
320
+ ) ;
321
+
322
+ tera. register_filter (
323
+ "to_arg_pattern" ,
324
+ |val : & Value , _args : & HashMap < String , Value > | {
325
+ let ty = expect_str ( val) ?;
326
+ if ty == "self" {
327
+ return Ok ( Value :: String ( "_self" . to_owned ( ) ) ) ;
328
+ }
329
+ Ok ( Value :: String ( ty. to_owned ( ) ) )
330
+ } ,
331
+ ) ;
332
+
333
+ tera. register_function (
334
+ "function_call_expression" ,
335
+ |args : & HashMap < String , Value > | {
336
+ let ident = expect_str ( expect_arg ( args, "type" ) ?) ?;
337
+ let function_name = expect_str ( expect_arg ( args, "function" ) ?) ?;
338
+ let trait_name: Option < & str > = args. get ( "trait" ) . and_then ( |v| v. as_str ( ) ) ;
339
+
340
+ if let Some ( trait_name) = trait_name {
341
+ Ok ( Value :: String ( format ! (
342
+ "<{ident} as {trait_name}>::{function_name}"
343
+ ) ) )
344
+ } else {
345
+ Ok ( Value :: String ( format ! ( "{ident}::{function_name}" ) ) )
346
+ }
347
+ } ,
320
348
)
321
349
}
322
350
Original file line number Diff line number Diff line change @@ -18,25 +18,23 @@ impl ::bevy::app::Plugin for {{ "ScriptingPlugin" | prefix_cratename | convert_c
18
18
{%- for arg in function.args -%}
19
19
{%- if arg.proxy_ty is matching("Mut.*")-%}
20
20
mut {% endif -%}
21
- {%- if arg.ident != "self" -%}
22
- {{- arg.ident -}}
23
- {%- else -%}
24
- _{{- arg.ident -}}
25
- {%- endif -%}
21
+ {{- arg.ident | to_arg_pattern() -}}
26
22
: {{- arg.proxy_ty -}},
27
23
{%- endfor -%}
28
24
| {
29
- let output: {{ function.output.proxy_ty }} = ::{{ item.import_path }}::{{ function.ident }}(
25
+ let output: {{ function.output.proxy_ty }} =
26
+ {%- if function.from_trait_path -%}
27
+ {{- function_call_expression(type=item.import_path, trait=function.from_trait_path, function=function.ident) -}}
28
+ {%- else -%}
29
+ {{- function_call_expression(type=item.import_path, function=function.ident) -}}
30
+ {%- endif -%}
31
+ (
30
32
{%- for arg in function.args -%}
31
33
{%- if arg.proxy_ty is matching("Ref.*")-%}
32
34
&{% endif -%}
33
35
{%- if arg.proxy_ty is matching ("Mut.*")-%}
34
36
&mut {% endif -%}
35
- {%- if arg.ident != "self" -%}
36
- {{- arg.ident -}}
37
- {%- else -%}
38
- _{{- arg.ident -}}
39
- {%- endif -%}
37
+ {{- arg.ident | to_arg_pattern() -}}
40
38
{%- if arg.proxy_ty is matching("Val.*")-%}
41
39
.into_inner()
42
40
{%- endif -%},
You can’t perform that action at this time.
0 commit comments