Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Discussion: use rustdoc for blocks' documentation #1127

Closed
MaxVerevkin opened this issue Mar 21, 2021 · 26 comments
Closed

Discussion: use rustdoc for blocks' documentation #1127

MaxVerevkin opened this issue Mar 21, 2021 · 26 comments
Labels
discussion docs Documentation errors, updates, or omissions.

Comments

@MaxVerevkin
Copy link
Collaborator

MaxVerevkin commented Mar 21, 2021

In-code documentation is just easier to maintain.

The question is whether it is actually convenient for users. Here is an example of documentation (time block): https://maxverevkin.github.io/i3status-rust/doc/i3status_rs/blocks/time/index.html

@ammgws ammgws added discussion docs Documentation errors, updates, or omissions. labels Mar 21, 2021
@ammgws
Copy link
Collaborator

ammgws commented Mar 23, 2021

I like the idea of increasing maintainability but going with rustdoc it ends up being a bit overwhelming for standard users. Is there a rustdoc option to hide all the struct declarations and such?

@MaxVerevkin
Copy link
Collaborator Author

Unfortunately, I don't think there in an option to hide trait impls (it is possible to hide struct declarations).

I can imagine that if there was an option to output markdown, it would be easy to make the documentation cleaner for users.

From rust-lang/rust#44136 I understand that there were plans to support other output formats but it will never be implemented.

@MaxVerevkin
Copy link
Collaborator Author

MaxVerevkin commented May 1, 2021

Even though per-field documentation is not user-friendly, just writing all block related documentation in the beginning of source code is both convenient to maintain (better than having one huge .md file) and user friendly (is it?):
image

@ammgws
Copy link
Collaborator

ammgws commented May 5, 2021

Actually that might not be too bad!

@ammgws
Copy link
Collaborator

ammgws commented Nov 7, 2021

Should we go ahead and do it?

@MaxVerevkin
Copy link
Collaborator Author

@ammgws If you like how https://maxverevkin.github.io/swaystatus/docs/swaystatus/blocks/index.html looks then I suppose.

@ammgws
Copy link
Collaborator

ammgws commented Nov 9, 2021

It's grown on me

@jyn514
Copy link

jyn514 commented Dec 9, 2021

From rust-lang/rust#44136 I understand that there were plans to support other output formats but it will never be implemented.

That issue was out of date, I updated it - there's an unstable JSON output format on nightly :) rust-lang/rust#76578

@ammgws
Copy link
Collaborator

ammgws commented Dec 15, 2021

@MaxVerevkin Do the docs have to be checked into the repo like at swaystatus for this to be usable online?

@MaxVerevkin
Copy link
Collaborator Author

MaxVerevkin commented Dec 15, 2021

I think so, unless we publish the crate on crates.io

@ammgws
Copy link
Collaborator

ammgws commented Dec 15, 2021

Do others publish programs to crates.io? I always thought it was for libraries that other crates can then import. Wonder if there's another way..

@MaxVerevkin
Copy link
Collaborator Author

Well, there are ripgrep, alacritty and zbus_xmlgen, but... it looks like docs are not generated for binary crates 😞

@jyn514
Copy link

jyn514 commented Dec 15, 2021

docs are not generated for binary crates

rust-lang/docs.rs#238

As a workaround, you could move your current binary to a library with a main function and have the actual binary just call my_lib::main and do nothing else.

@MaxVerevkin
Copy link
Collaborator Author

As a workaround, you could move your current binary to a library with a main function and have the actual binary just call my_lib::main and do nothing else.

Will it work for a crate which is both a library and a binary?

Wonder if there's another way..

Yeah, publishing a new version after every change in documentation doesn't sound great.

@jyn514
Copy link

jyn514 commented Dec 15, 2021

Will it work for a crate which is both a library and a binary?

No, you'd have to make a new library if you want that to work. (or work on the docs.rs issue 😉)

@ammgws
Copy link
Collaborator

ammgws commented Dec 28, 2021

> @MaxVerevkin Do the docs have to be checked into the repo like at swaystatus for this to be usable online?
I think so, unless we publish the crate on crates.io

Actually if we just keep the docs in a separate branch and have a github action to generate them then we can do this, e.g.: https://github.com/houqp/leptess

@MaxVerevkin
Copy link
Collaborator Author

Actually if we just keep the docs in a separate branch and have a github action to generate them then we can do this, e.g.: https://github.com/houqp/leptess

Nice! Didn't know https://github.com/marketplace/actions/deploy-to-github-pages existed :)

@ammgws
Copy link
Collaborator

ammgws commented Jun 19, 2022

Closing now that async branch is merged into master. However we now need a way to generate manpages to replace our old script that parsed blocks.md...

@ammgws ammgws closed this as completed Jun 19, 2022
@MaxVerevkin
Copy link
Collaborator Author

However we now need a way to generate manpages to replace our old script that parsed blocks.md...

Well... A little script/program can be written to iterate through every file in /src/blocks/ and extract the top-level comment. Those comments can then be concatenated and placed in one big .md file. And then we can convert this file to manpage.

@MaxVerevkin
Copy link
Collaborator Author

MaxVerevkin commented Jun 19, 2022

My attempt - eb22f91

The result contains some .RS 2 where it doesn't make sense, don't know why yet. fixed in 97d3e0d

@ammgws
Copy link
Collaborator

ammgws commented Jun 22, 2022

BTW any idea what is going on here? Pretty sure the docs are up to date but code block formatting broken in the Github pages.

image

image

@MaxVerevkin
Copy link
Collaborator Author

BTW any idea what is going on here? Pretty sure the docs are up to date but code block formatting broken in the Github pages.

image

image

Ahh, that's because markdown is weird and "|" gets parsed as a column separator. Some kind of special escape sequence must be used, like | or something.

@MaxVerevkin
Copy link
Collaborator Author

By the way, perhaps we can remove the "Required" column for better readability (especially in manpages)? Required options are rare and their "Default" can be set to "N/A" or "Required".

@MaxVerevkin
Copy link
Collaborator Author

special escape sequence must be used, like |

And to use this escape sequence you need <code>...</code> instead of `...` 😠

@ammgws
Copy link
Collaborator

ammgws commented Jun 22, 2022

By the way, perhaps we can remove the "Required" column for better readability (especially in manpages)? Required options are rare and their "Default" can be set to "N/A" or "Required".

Good catch, sounds good to me.

@MaxVerevkin
Copy link
Collaborator Author

TIL that number of - in markdown tables matter (for manpages).

//! Placeholder        | Value
//! -------------------|----------------------------------------------------------------

renders as

image

while

//! Placeholder        | Value
//! -------------------|------

renders as

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discussion docs Documentation errors, updates, or omissions.
Projects
None yet
Development

No branches or pull requests

3 participants