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

rustdoc: use real buttons for scrape examples controls #104611

Merged
merged 4 commits into from
Nov 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/bootstrap/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1011,6 +1011,8 @@ impl Step for RustdocGUI {
// instead of hard-coding this test
if entry.file_name() == "link_to_definition" {
cargo.env("RUSTDOCFLAGS", "-Zunstable-options --generate-link-to-definition");
} else if entry.file_name() == "scrape_examples" {
cargo.arg("-Zrustdoc-scrape-examples=examples");
}
builder.run(&mut cargo);
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/html/render/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2915,7 +2915,7 @@ fn render_call_locations(w: &mut Buffer, cx: &mut Context<'_>, item: &clean::Ite
);

if line_ranges.len() > 1 {
write!(w, r#"<span class="prev">&pr;</span> <span class="next">&sc;</span>"#);
write!(w, r#"<button class="prev">&pr;</button> <button class="next">&sc;</button>"#);
}

// Look for the example file in the source map if it exists, otherwise return a dummy span
Expand Down
7 changes: 5 additions & 2 deletions src/librustdoc/html/sources.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,8 +287,11 @@ pub(crate) fn print_src(
}
}
SourceContext::Embedded { offset, needs_expansion } => {
extra =
if needs_expansion { Some(r#"<span class="expand">&varr;</span>"#) } else { None };
extra = if needs_expansion {
Some(r#"<button class="expand">&varr;</button>"#)
} else {
None
};
for line_number in 1..=lines {
let line = line_number + offset;
writeln!(line_numbers, "<span>{line}</span>")
Expand Down
6 changes: 6 additions & 0 deletions src/librustdoc/html/static/css/rustdoc.css
Original file line number Diff line number Diff line change
Expand Up @@ -1959,6 +1959,12 @@ in storage.js
top: 0.25em;
z-index: 1;
cursor: pointer;
padding: 0;
background: none;
border: none;
/* iOS button gradient: https://stackoverflow.com/q/5438567 */
-webkit-appearance: none;
opacity: 1;
}
.scraped-example .code-wrapper .prev {
right: 2.25em;
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/html/templates/page.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
{%- endif -%}
<script defer src="{{static_root_path|safe}}{{files.main_js}}"></script> {#- -#}
{%- if layout.scrape_examples_extension -%}
<script defer src="{{page.root_path|safe}}{{files.scrape_examples_js}}"></script> {#- -#}
<script defer src="{{static_root_path|safe}}{{files.scrape_examples_js}}"></script> {#- -#}
{%- endif -%}
<noscript> {#- -#}
<link rel="stylesheet" {# -#}
Expand Down
14 changes: 14 additions & 0 deletions src/test/rustdoc-gui/scrape-examples-button-focus.goml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
goto: "file://" + |DOC_PATH| + "/scrape_examples/fn.test.html"
store-property: (smallOffsetHeight, ".scraped-example-list > .scraped-example pre", "offsetHeight")
assert-property-false: (".scraped-example-list > .scraped-example pre", {
"scrollHeight": |smallOffsetHeight|
})
focus: ".scraped-example-list > .scraped-example .expand"
press-key: "Enter"
assert-property-false: (".scraped-example-list > .scraped-example pre", {
"offsetHeight": |smallOffsetHeight|
})
store-property: (fullOffsetHeight, ".scraped-example-list > .scraped-example pre", "offsetHeight")
assert-property: (".scraped-example-list > .scraped-example pre", {
"scrollHeight": |fullOffsetHeight|
})
2 changes: 1 addition & 1 deletion src/test/rustdoc-gui/sidebar-source-code.goml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ assert: "//*[@class='dir-entry' and @open]/*[text()='sub_mod']"
// Only "another_folder" should be "open" in "lib2".
assert: "//*[@class='dir-entry' and not(@open)]/*[text()='another_mod']"
// All other trees should be collapsed.
assert-count: ("//*[@id='source-sidebar']/details[not(text()='lib2') and not(@open)]", 6)
assert-count: ("//*[@id='source-sidebar']/details[not(text()='lib2') and not(@open)]", 7)

// We now switch to mobile mode.
size: (600, 600)
Expand Down
7 changes: 7 additions & 0 deletions src/test/rustdoc-gui/src/scrape_examples/Cargo.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3

[[package]]
name = "scrape_examples"
version = "0.1.0"
8 changes: 8 additions & 0 deletions src/test/rustdoc-gui/src/scrape_examples/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[package]
name = "scrape_examples"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
25 changes: 25 additions & 0 deletions src/test/rustdoc-gui/src/scrape_examples/examples/check.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
fn main() {
for i in 0..9 {
println!("hello world!");
println!("hello world!");
println!("hello world!");
println!("hello world!");
println!("hello world!");
println!("hello world!");
println!("hello world!");
println!("hello world!");
println!("hello world!");
}
scrape_examples::test();
for i in 0..9 {
println!("hello world!");
println!("hello world!");
println!("hello world!");
println!("hello world!");
println!("hello world!");
println!("hello world!");
println!("hello world!");
println!("hello world!");
println!("hello world!");
}
}
7 changes: 7 additions & 0 deletions src/test/rustdoc-gui/src/scrape_examples/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/// # Examples
///
/// ```
/// test();
/// test();
/// ```
pub fn test() {}