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

Basic server mode support #1151

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Basic server mode support #1151

wants to merge 3 commits into from

Conversation

st0012
Copy link
Member

@st0012 st0012 commented Aug 5, 2024

Currently, rdoc doesn't support server mode, which makes both using it and developing it extremely inconvenient.

(ri --server is RI's web interface, which lets users read indexed RI documents in the browser. It does NOT run current project's RDoc documentation in server mode. To avoid confusion, I moved RDoc::Servlet to RDoc::RI::Servlet.)

So in this PR, I want to introduce a very rough server support to RDoc:

  • Can be used with rdoc --server or rdoc -s
    • It's marked as experimental for now as it's very slow (see below)
    • The port defaults to 4000 but can be assigned with --port=PORT
  • Will use a tmpdir to temporarily host the generated files so they don't override the original doc folder
  • It reparses and regenerates files on EVERY SINGLE REQUEST, which is pretty slow, but still faster than running rdoc or rake rdoc repeatedly
    • We can add smarter reparsing/regenerating support, but it will first take some refactoring as the current design doesn't account for those

lib/rdoc/options.rb Outdated Show resolved Hide resolved
opt.on(
"--server[=PORT]",
Integer,
"[Experimental] Run WEBrick server with generated documentation.",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel we can remove the [Experiment] flag, we're not shipping something we're not expecting will work or introduce any breaking changes.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My interpretation of "experimental" is: the feature works but may not live up to expectation at the moment and has a slight chance to be removed if it's proven problematic.

In this case, I don't expect it to be removed later but it doesn't have the maturity to work like yard server or some static site generators' server mode.

lib/rdoc/rdoc.rb Outdated
end

# Change the output directory to tmp so it doesn't overwrite the current documentation
Dir.chdir "tmp" do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Discussed this in Slack. Let's look at utilizing mktmpdir instead of $CWD/test

st0012 and others added 3 commits August 31, 2024 21:44
This class is used as a server for the ri command, not as a rdoc server.
So putting it under RDoc::RI will make its purpose clearer.
Co-authored-by: Colby Swandale <996377+colby-swandale@users.noreply.github.com>
@generator.update_data_from_store

# Regenerate the documentation and asserts
@generator.generate(server_mode: true)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Through implementing this feature I learned a lot about how data are passed around, which sometimes simply duplicate in multiple classes. And I plan to do some refactor around them.

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

Successfully merging this pull request may close these issues.

2 participants