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

Migrate top doc and non-exhaustive toggles to details tag #85074

Merged
merged 2 commits into from
May 10, 2021

Conversation

GuillaumeGomez
Copy link
Member

Fixes #83332.

r? @jsha

@GuillaumeGomez GuillaumeGomez added T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. A-rustdoc-ui Area: rustdoc UI (generated HTML) A-rustdoc-js Area: Rustdoc's front-end labels May 8, 2021
@rust-highfive
Copy link
Collaborator

Some changes occurred in HTML/CSS themes.

cc @GuillaumeGomez

Some changes occurred in HTML/CSS/JS.

cc @GuillaumeGomez

A change occurred in the Ayu theme.

cc @Cldfire

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label May 8, 2021
@rust-log-analyzer

This comment has been minimized.

@jsha
Copy link
Contributor

jsha commented May 8, 2021 via email

@GuillaumeGomez GuillaumeGomez changed the title End toggle migration Migrate top doc and nom-exhaustive toggles to details tag May 8, 2021
@rust-log-analyzer

This comment has been minimized.

@jsha
Copy link
Contributor

jsha commented May 8, 2021 via email

@GuillaumeGomez
Copy link
Member Author

I see that document_full has a new boolean parameter, is_collapsible. I'm always wary of boolean params because it's not clear at the call site what they mean. How about this: at the one call site that has is_collapsible = true, emit the opening and closing details tags there rather than inside document_full? Also the CSS rules for the [+] that were formerly split can be merged since your latest updates.

It's problematic in case there isn't any documentation generated because then we'd have a <details> with no content, which is why I went for this solution.

@rust-log-analyzer

This comment has been minimized.

@GuillaumeGomez GuillaumeGomez marked this pull request as ready for review May 8, 2021 20:44
@camelid camelid changed the title Migrate top doc and nom-exhaustive toggles to details tag Migrate top doc and non-exhaustive toggles to details tag May 9, 2021
@@ -561,10 +561,21 @@ fn document_short(
}
}

fn document_full(w: &mut Buffer, item: &clean::Item, cx: &Context<'_>) {
fn document_full(w: &mut Buffer, item: &clean::Item, cx: &Context<'_>, is_collapsible: bool) {
Copy link
Member

Choose a reason for hiding this comment

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

nit: Could you use an enum instead? document_full(w, item, cx, true) doesn't tell me what the boolean means and could be confusing.

enum Collapsible { True, False }

// Example usage
document_full(w, item, cx, Collapsible::True);

Or, if you want to be able to use ifs, you could use a wrapper struct. This might be a better approach.

struct Collapsible { is: bool }

// Example call
document_full(w, item, cx, Collapsible { is: true });

// Example check
if collapsible.is { /* ... */ }

I suggested naming the field is so that it's clear in the if conditional what the field is for.

Copy link
Member Author

Choose a reason for hiding this comment

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

Creating a new type for a boolean seems completely overkill. The argument name is pretty explicit in itself I think. Here what I will do: create another function called document_full_collapsible so that it doesn't require an extra argument and it will be explicit what it's doing. :)

Copy link
Contributor

Choose a reason for hiding this comment

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

The beauty of Rust's enums is that they're really easy to make and use. :-) But I'm good with document_full_collapsible if @camelid is.

Another possibility, going back to my idea of writing out the <details> wrapper at the call site: What if document_full returns an Option<Buffer>? Then the call sites can either splat the contents directly into their copy of w, or wrap them in <details> as appropriate.

Copy link
Member Author

Choose a reason for hiding this comment

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

I didn't want to create a new Buffer, but that could work too, just not as performant.

@camelid camelid added the C-cleanup Category: PRs that clean code up or issues documenting cleanup. label May 9, 2021
src/librustdoc/html/static/main.js Outdated Show resolved Hide resolved
src/librustdoc/html/static/main.js Outdated Show resolved Hide resolved
src/librustdoc/html/static/main.js Outdated Show resolved Hide resolved
src/librustdoc/html/static/rustdoc.css Show resolved Hide resolved
src/librustdoc/html/render/mod.rs Show resolved Hide resolved
@GuillaumeGomez GuillaumeGomez force-pushed the end-toggle-migration branch 2 times, most recently from 8eed102 to 987f5a6 Compare May 9, 2021 16:01
@GuillaumeGomez
Copy link
Member Author

Applied review comments: a huge reduction of the JS size: more than 200 lines removed! \o/ That's one of the biggest reduction we've seen I think.

hasClass(parent, "impl") === false) {
e.innerHTML = labelForToggleButton(true);
onEachLazy(document.getElementsByClassName("rustdoc-toggle"), function(e) {
if (e.parentNode.id !== "main" ||
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are direct children of main excluded from this?

Copy link
Member Author

Choose a reason for hiding this comment

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

Only the type declaration <details> and the impl blocks are ignored in this case (look in the or condition ;) ), like it's currently the case. I kept the same logic.

@jsha
Copy link
Contributor

jsha commented May 10, 2021

@bors r+

Nice work!

@bors
Copy link
Contributor

bors commented May 10, 2021

📌 Commit 3837c1c has been approved by jsha

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 10, 2021
@bors
Copy link
Contributor

bors commented May 10, 2021

⌛ Testing commit 3837c1c with merge 00f2bf4...

@bors
Copy link
Contributor

bors commented May 10, 2021

☀️ Test successful - checks-actions
Approved by: jsha
Pushing 00f2bf4 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label May 10, 2021
@bors bors merged commit 00f2bf4 into rust-lang:master May 10, 2021
@rustbot rustbot added this to the 1.54.0 milestone May 10, 2021
@GuillaumeGomez GuillaumeGomez deleted the end-toggle-migration branch May 10, 2021 08:15
JohnTitor added a commit to JohnTitor/rust that referenced this pull request May 11, 2021
…tester, r=Mark-Simulacrum

Improve rustdoc gui tester

I cherry-picked the commit from rust-lang#84834 (and modified it a bit). I also used this opportunity to update it to last version (forgot to update GUI test in rust-lang#85074, really can't wait to make rust-lang#84586 finally work).

cc `@Mark-Simulacrum` for the changes in bootstrap.

r? `@jsha`
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this pull request May 12, 2021
…, r=GuillaumeGomez

Move global click handlers to per-element ones.

In rustdoc's main.js, we had an onclick handler for the whole document that would dispatch to handlers for various elements. This change attaches the handlers to the elements that trigger them, instead. This simplifies the code and avoids reimplementing the browser's bubbling functionality.

As part of this change, change from a class to an id for help button.

Move the handlers and associated code for highlighting source lines into source-script.js (and factor out a shared regex).

Demo at https://hoffman-andrews.com/rust/bubble-bubble-toil-and-trouble/std/string/struct.String.html

Note: this conflicts with / depends on rust-lang#85074. Once that's merged I'll rebase this and resolve conflicts.

Part of rust-lang#83332. Thanks to `@Manishearth` for the [suggestion to not reimplement bubbling](rust-lang#83332 (comment)).

r? `@GuillaumeGomez`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-rustdoc-js Area: Rustdoc's front-end A-rustdoc-ui Area: rustdoc UI (generated HTML) C-cleanup Category: PRs that clean code up or issues documenting cleanup. merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Clean up toggle logic in rustdoc
7 participants