Skip to content

Commit

Permalink
add docs; add libninja: static functionality for file templates
Browse files Browse the repository at this point in the history
  • Loading branch information
kurtbuilds committed Dec 19, 2023
1 parent c44232d commit f65537d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions libninja/src/rust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,9 @@ fn write_file_with_template(mut file: File<TokenStream>, template: Option<String
// template.defs
// file.defs
// let template = syn::parse_file(&template)?;
if template.contains("libninja: static") {
return write_rust_file_to_path(path, file);
}
let doc = std::mem::take(&mut file.doc)
.to_rust_code();
let imports = std::mem::take(&mut file.imports)
Expand Down

0 comments on commit f65537d

Please sign in to comment.