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

Refactor Darkfish implementation #1300

Draft
wants to merge 12 commits into
base: master
Choose a base branch
from
Draft

Conversation

st0012
Copy link
Member

@st0012 st0012 commented Mar 1, 2025

Notable changes:

Avoid using block binding to capture template variables

Under the current implementation, the template variables are captured
through the render_template method's block. This makes it hard to
understand if a variable is intended to be used in the template or not.

This commit changes the render_template method to require passing
a hash of local variables to the template. This makes the variable
scope explicit and easier to reason about.

@st0012 st0012 force-pushed the refactor-pages-sidebar branch from 34a27fd to 18f771a Compare March 1, 2025 23:29
Copy link

cloudflare-workers-and-pages bot commented Mar 1, 2025

Deploying rdoc with  Cloudflare Pages  Cloudflare Pages

Latest commit: 8373d70
Status: ✅  Deploy successful!
Preview URL: https://831c1cc1.rdoc-6cd.pages.dev
Branch Preview URL: https://refactor-pages-sidebar.rdoc-6cd.pages.dev

View logs

@st0012 st0012 force-pushed the refactor-pages-sidebar branch from 18f771a to 6dadc0d Compare March 2, 2025 11:58
st0012 added a commit that referenced this pull request Mar 2, 2025
Extracted from #1300

These things are not currently used by anything. Please review by
commits.
st0012 added a commit that referenced this pull request Mar 2, 2025
Discovered when working on #1300 

Currently we need to call `setup` in individual generation methods,
despite having already called it in `RDoc#generate`. This is because
`setup` is lazily called when we run `ri`'s server mode.

By calling `setup` eagerly in `Servlet#generator_for`, we can avoid the
repeated calls to `setup` in individual generation methods.

Right now we can NOT move `setup` into `Darkfish#initialize` yet because
`ri`'s server can[ initialize `Darkfish` with `nil`
store](https://github.com/ruby/rdoc/blob/master/lib/rdoc/servlet.rb#L335).
st0012 added 12 commits March 2, 2025 21:00
Under the current implementation, the template variables are captured
through the `render_template` method's block. This makes it hard to
understand if a variable is intended to be used in the template or not.

This commit changes the `render_template` method to require passing
a hash of local variables to the template. This makes the variable
scope explicit and easier to reason about.
@st0012 st0012 force-pushed the refactor-pages-sidebar branch from 6dadc0d to 8373d70 Compare March 2, 2025 21:03
io_output = out_file && !@dry_run && @file_output
erb_klass = io_output ? RDoc::ERBIO : ERB

template = template_for template_file, true, erb_klass

@context = binding
Copy link
Member

Choose a reason for hiding this comment

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

Isn’t it possible that the template accidentally affects the variables of this method?

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

Successfully merging this pull request may close these issues.

2 participants