From ae1676c786e3601f44c0afe6c1de3bb6986f0a5a Mon Sep 17 00:00:00 2001 From: Maccesch Date: Mon, 2 Sep 2024 12:12:11 +0100 Subject: [PATCH] properly handle web-sys unstable apis config in the new function template --- template/.ffizer.yaml | 2 +- template/modify_files.py | 11 ++++++++++- .../{{ module }}/{{ function_name }}.ffizer.hbs.rs | 1 - 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/template/.ffizer.yaml b/template/.ffizer.yaml index ed9de45..b13294c 100644 --- a/template/.ffizer.yaml +++ b/template/.ffizer.yaml @@ -19,4 +19,4 @@ ignores: - createfn.sh scripts: - - cmd: python3 template/modify_files.py {{ function_name }} {{ category }}{{#if module}} --module {{ module }}{{/if}} --feature {{ feature }} + - cmd: python3 template/modify_files.py {{ function_name }} {{ category }}{{#if module}} --module {{ module }}{{/if}} --feature {{ feature }} --unstable_apis {{ unstable_apis }} diff --git a/template/modify_files.py b/template/modify_files.py index 4efdb23..a54b852 100644 --- a/template/modify_files.py +++ b/template/modify_files.py @@ -10,6 +10,7 @@ def main(): parser.add_argument("category") parser.add_argument("--module", type=str) parser.add_argument("--feature", type=str) + parser.add_argument("--unstable_apis", type=lambda x: x.lower() == "true") args = parser.parse_args() @@ -94,7 +95,14 @@ def modify_librs(args): with open("src/lib.rs", "r") as f: lib_source = f.read() - feature_prefix = "" if args.feature is None else f"#[cfg(feature = \"{args.feature}\")]\n" + feature_prefix = [] + if args.feature is not None: + feature_prefix.append(f"#[cfg(feature = \"{args.feature}\")]\n") + + if args.unstable_apis: + feature_prefix.append("#[cfg(web_sys_unstable_apis)]\n") + + feature_prefix = "".join(feature_prefix) if args.module is None: lib_source = lib_source.replace("mod on_click_outside;", @@ -163,5 +171,6 @@ def modify_cargo_toml(args): with open("Cargo.toml", "w") as f: f.write("".join(cargo_toml_source)) + if __name__ == '__main__': main() diff --git a/template/src/{{ module }}/{{ function_name }}.ffizer.hbs.rs b/template/src/{{ module }}/{{ function_name }}.ffizer.hbs.rs index e50778c..1eaad99 100644 --- a/template/src/{{ module }}/{{ function_name }}.ffizer.hbs.rs +++ b/template/src/{{ module }}/{{ function_name }}.ffizer.hbs.rs @@ -27,7 +27,6 @@ use leptos::*; /// ## Server-Side Rendering /// // #[doc(cfg(feature = "{{feature}}"))] - pub fn {{ function_name }}() -> {{ to_pascal_case function_name }}Return { {{ function_name }}_with_options({{ to_pascal_case function_name }}Options::default()) }