Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

possible to use for generating documentation of registered rust functions? #5

Open
jonathanstrong opened this issue Mar 25, 2022 · 5 comments
Labels
enhancement New feature or request

Comments

@jonathanstrong
Copy link

I don't think this is possible with rhai-doc as is but wanted to double check. in my case I have a fairly large api of registered rust types/functions that I would love to generate docs for.

@schungx schungx added the enhancement New feature or request label Mar 25, 2022
@schungx
Copy link
Contributor

schungx commented Mar 25, 2022

I have thought of this before and wanted essentially the same thing.

However, rhai-doc is written to really read script files and recurse into directories to search for script files.

All the mechanisms are already there: You can easily get a JSON file of all the registered functions in one single call.

https://rhai.rs/book/engine/metadata/export_to_json.html

All you need to do is a templating system (e.g. handlebars) that takes this JSON file and generates documentation pages.

In fact, you'd probably want to first use a templating system to generate a MarkDown file containing the functions plus doc-comments (in MarkDown), then convert that MarkDown into HTML.

@jonathanstrong
Copy link
Author

cool - I will have a look! thanks.

@schungx
Copy link
Contributor

schungx commented Mar 26, 2022

It seems like you can use a static site generator which supports JSON sources to automatically generate documentation pages.

Something like Hugo: https://gohugo.io/templates/data-templates/

Or, it probably won't be difficult to write your own using handlebars as the templating engine and pulldown-cmark as the MarkDown renderer, which is what rhai-doc does.

@semirix
Copy link
Member

semirix commented Apr 11, 2022

@schungx This is probably something that should be supported but this currently only parses .rhai files. Adding this functionality would require parsing Rust code. An immediate solution I can think of would be to attach a macro (or leverage an existing one) to generate an output file that rhai-doc can parse and add to the docs.

@schungx
Copy link
Contributor

schungx commented Apr 11, 2022

There is already a way to generate similar documentation on native Rust functions into a JSON format.

It would be more in-depth than the current Rhai functions because you have to deal with parameter types, return types and &mut etc.

Nevertheless, the logic is similar to rhai-doc. It probably only requires a different template.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants