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

Clarify which version of source code was used to generate docs #1595

Open
bogdan opened this issue Nov 19, 2024 · 3 comments
Open

Clarify which version of source code was used to generate docs #1595

bogdan opened this issue Nov 19, 2024 · 3 comments

Comments

@bogdan
Copy link

bogdan commented Nov 19, 2024

Currently when yard generates docs it attaches the following footer:

Generated on Tue Nov 19 15:01:10 2024 by [yard](http://yardoc.org/) 0.9.36 (ruby-3.3.5).

Which is not enough to understand which version of the source code was used:

  1. No time zone information on timestamp
  2. No git commit hash
  3. No library version.

Ideally all of that need to be present to understand if the doc is up to date or not.
Please add this information to footer.

@lsegal
Copy link
Owner

lsegal commented Nov 19, 2024

Adding a timezone to the timestamp seems reasonable. Would accept a PR to fix this.

As far as git commit hash and library version, these aren't something that YARD necessarily knows about. Git commit would require integrating with the system VCS which has a lot of sharp edges (git isn't in the PATH, contents generated against dirty checkout so SHA isn't valid, VCS might not be git, YARD opens itself up to fielding feature requests for ). Getting the library version is even harder as there is no static way to get this information without evaluating code.

The good news is you can build a custom template footer pretty easily with all the information you want by throwing a file into <path/to>/default/layout/html/footer.erb with any contents (you can grab initial contents from YARD's footer.erb) and then running yard with yard doc -p path/to (path/to was the prefix you used above for the file location).

<!-- templates/default/layout/html/footer.erb -->
<div id="footer">
  Generated <code>MY_LIBRARY</code> <%= YARD::VERSION %> <!-- insert your library's VERSION const here --> 
  (<%= `git rev-parse HEAD`.strip[0,6] %>) at <%= Time.now %>.
</div>

@bogdan
Copy link
Author

bogdan commented Nov 20, 2024

Getting the library version is even harder as there is no static way to get this information without evaluating code.

I saw this fragment here and thought it is possible:

<script>
window.yard_library_name = '<%= @library.name %>';
window.yard_library_version = '<%= @library.version %>';
</script>

https://github.com/docmeta/rubydoc.info/blob/main/templates/default/layout/html/footer.erb#L8

@lsegal
Copy link
Owner

lsegal commented Nov 20, 2024

Rubydoc intentionally pulls information that yard alone does not have-- specifically the rubygems package release list or git repos. That's because rubydoc explicitly pulls from these sources. YARD only uses disk.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants