From f65537d774b81556521a6c7208c39ad027240935 Mon Sep 17 00:00:00 2001 From: Kurt Wolf Date: Tue, 19 Dec 2023 17:47:48 -0500 Subject: [PATCH] add docs; add `libninja: static` functionality for file templates --- README.md | 20 ++++++++++++++++++++ libninja/src/rust.rs | 3 +++ 2 files changed, 23 insertions(+) diff --git a/README.md b/README.md index c3d735d..ba872a1 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,26 @@ Use the command line help to see required arguments & options when generating li The open source version builds client libraries for Rust. Libninja also supports other languages with a commercial license. Reach out at the email in author Github profile. +# Usage + +## Customizing generation + +There are two ways to customize codegen, first by modifying the OpenAPI spec, and second, using a file template system. + +During codegen, `libninja` will look for a directory called `template`, and use files there to customize the generated code. + +For example, if libninja generates `src/model/user.rs`, it will check for `template/src/model/user.rs`. + +If it's found, `libninja` will try to intelligently interpolate generated code with the templated file. The specific order of items in the output file will be: + +1. codegen docstring +2. codegen imports +3. template imports +4. template items (structs, enums, traits, impl, etc) +5. codegen items + +Alternatively, if the string `libninja: static` is found in the file template, it will ignore all codegen for that file, and pass the template file through as-is. + # Development If you run into errors about a missing `commericial` package, run the command `just dummy_commericial` to create a dummy diff --git a/libninja/src/rust.rs b/libninja/src/rust.rs index ede48ed..0bf183d 100644 --- a/libninja/src/rust.rs +++ b/libninja/src/rust.rs @@ -187,6 +187,9 @@ fn write_file_with_template(mut file: File, template: Option