Skip to content

Commit

Permalink
Rollup merge of #107783 - notriddle:notriddle/item-table-ul, r=Guilla…
Browse files Browse the repository at this point in the history
…umeGomez

rustdoc: simplify DOM for `.item-table`

This switches from using `<div>` to the more semantic `<ul>`, and using class names that rhyme with the classes the search results table uses.
  • Loading branch information
Dylan-DPC committed Feb 19, 2023
2 parents e802713 + 894c986 commit 4165de4
Show file tree
Hide file tree
Showing 23 changed files with 103 additions and 101 deletions.
20 changes: 10 additions & 10 deletions src/librustdoc/html/render/print_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ use crate::html::{highlight, static_files};
use askama::Template;
use itertools::Itertools;

const ITEM_TABLE_OPEN: &str = "<div class=\"item-table\">";
const ITEM_TABLE_CLOSE: &str = "</div>";
const ITEM_TABLE_ROW_OPEN: &str = "<div class=\"item-row\">";
const ITEM_TABLE_ROW_CLOSE: &str = "</div>";
const ITEM_TABLE_OPEN: &str = "<ul class=\"item-table\">";
const ITEM_TABLE_CLOSE: &str = "</ul>";
const ITEM_TABLE_ROW_OPEN: &str = "<li>";
const ITEM_TABLE_ROW_CLOSE: &str = "</li>";

// A component in a `use` path, like `string` in std::string::ToString
struct PathComponent {
Expand Down Expand Up @@ -338,14 +338,14 @@ fn item_module(w: &mut Buffer, cx: &mut Context<'_>, item: &clean::Item, items:
match *src {
Some(src) => write!(
w,
"<div class=\"item-left\"><code>{}extern crate {} as {};",
"<div class=\"item-name\"><code>{}extern crate {} as {};",
visibility_print_with_space(myitem.visibility(tcx), myitem.item_id, cx),
anchor(myitem.item_id.expect_def_id(), src, cx),
myitem.name.unwrap(),
),
None => write!(
w,
"<div class=\"item-left\"><code>{}extern crate {};",
"<div class=\"item-name\"><code>{}extern crate {};",
visibility_print_with_space(myitem.visibility(tcx), myitem.item_id, cx),
anchor(myitem.item_id.expect_def_id(), myitem.name.unwrap(), cx),
),
Expand Down Expand Up @@ -384,11 +384,11 @@ fn item_module(w: &mut Buffer, cx: &mut Context<'_>, item: &clean::Item, items:
let (stab_tags_before, stab_tags_after) = if stab_tags.is_empty() {
("", "")
} else {
("<div class=\"item-right docblock-short\">", "</div>")
("<div class=\"desc docblock-short\">", "</div>")
};
write!(
w,
"<div class=\"item-left\"{id}>\
"<div class=\"item-name\"{id}>\
<code>{vis}{imp}</code>\
</div>\
{stab_tags_before}{stab_tags}{stab_tags_after}",
Expand Down Expand Up @@ -426,11 +426,11 @@ fn item_module(w: &mut Buffer, cx: &mut Context<'_>, item: &clean::Item, items:
let (docs_before, docs_after) = if docs.is_empty() {
("", "")
} else {
("<div class=\"item-right docblock-short\">", "</div>")
("<div class=\"desc docblock-short\">", "</div>")
};
write!(
w,
"<div class=\"item-left\">\
"<div class=\"item-name\">\
<a class=\"{class}\" href=\"{href}\" title=\"{title}\">{name}</a>\
{visibility_emoji}\
{unsafety_flag}\
Expand Down
16 changes: 9 additions & 7 deletions src/librustdoc/html/static/css/rustdoc.css
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ h1, h2, h3, h4, h5, h6,
.mobile-topbar,
.search-input,
.search-results .result-name,
.item-left > a,
.item-name > a,
.out-of-band,
span.since,
a.srclink,
Expand Down Expand Up @@ -750,14 +750,16 @@ table,

.item-table {
display: table;
padding: 0;
margin: 0;
}
.item-row {
.item-table > li {
display: table-row;
}
.item-left, .item-right {
.item-table > li > div {
display: table-cell;
}
.item-left {
.item-table > li > .item-name {
padding-right: 1.25rem;
}

Expand Down Expand Up @@ -962,7 +964,7 @@ so that we can apply CSS-filters to change the arrow color in themes */
padding: 3px;
margin-bottom: 5px;
}
.item-left .stab {
.item-name .stab {
margin-left: 0.3125em;
}
.stab {
Expand Down Expand Up @@ -1695,7 +1697,7 @@ in storage.js
}

/* Display an alternating layout on tablets and phones */
.item-table, .item-row, .item-left, .item-right,
.item-table, .item-row, .item-table > li, .item-table > li > div,
.search-results > a, .search-results > a > div {
display: block;
}
Expand All @@ -1704,7 +1706,7 @@ in storage.js
.search-results > a {
padding: 5px 0px;
}
.search-results > a > div.desc, .item-right {
.search-results > a > div.desc, .item-table > li > div.desc {
padding-left: 2em;
}

Expand Down
4 changes: 2 additions & 2 deletions tests/rustdoc-gui/huge-collection-of-constants.goml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
goto: "file://" + |DOC_PATH| + "/test_docs/huge_amount_of_consts/index.html"

compare-elements-position-near-false: (
"//*[@class='item-table']//div[last()-1]",
"//*[@class='item-table']//div[last()-3]",
"//ul[@class='item-table']/li[last()-1]",
"//ul[@class='item-table']/li[last()-3]",
{"y": 12},
)
4 changes: 2 additions & 2 deletions tests/rustdoc-gui/item-summary-table.goml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// This test ensures that <table> elements aren't display in items summary.
goto: "file://" + |DOC_PATH| + "/lib2/summary_table/index.html"
// We check that we picked the right item first.
assert-text: (".item-table .item-left", "Foo")
assert-text: (".item-table .item-name", "Foo")
// Then we check that its summary is empty.
assert-false: ".item-table .item-right"
assert-false: ".item-table .desc"
36 changes: 18 additions & 18 deletions tests/rustdoc-gui/label-next-to-symbol.goml
Original file line number Diff line number Diff line change
Expand Up @@ -9,58 +9,58 @@ assert: (".stab.portability")

// make sure that deprecated and portability have the right colors
assert-css: (
".item-table .item-left .stab.deprecated",
".item-table .item-name .stab.deprecated",
{ "background-color": "rgb(255, 245, 214)" },
)
assert-css: (
".item-table .item-left .stab.portability",
".item-table .item-name .stab.portability",
{ "background-color": "rgb(255, 245, 214)" },
)

// table like view
assert-css: (".item-right.docblock-short", { "padding-left": "0px" })
assert-css: (".desc.docblock-short", { "padding-left": "0px" })
compare-elements-position-near: (
"//*[@class='item-left']//a[text()='replaced_function']",
".item-left .stab.deprecated",
"//*[@class='item-name']//a[text()='replaced_function']",
".item-name .stab.deprecated",
{"y": 2},
)
compare-elements-position: (
".item-left .stab.deprecated",
".item-left .stab.portability",
".item-name .stab.deprecated",
".item-name .stab.portability",
("y"),
)

// Ensure no wrap
compare-elements-position: (
"//*[@class='item-left']//a[text()='replaced_function']/..",
"//*[@class='item-right docblock-short'][text()='a thing with a label']",
"//*[@class='item-name']//a[text()='replaced_function']/..",
"//*[@class='desc docblock-short'][text()='a thing with a label']",
("y"),
)


// Mobile view
size: (600, 600)
// staggered layout with 2em spacing
assert-css: (".item-right.docblock-short", { "padding-left": "32px" })
assert-css: (".desc.docblock-short", { "padding-left": "32px" })
compare-elements-position-near: (
"//*[@class='item-left']//a[text()='replaced_function']",
".item-left .stab.deprecated",
"//*[@class='item-name']//a[text()='replaced_function']",
".item-name .stab.deprecated",
{"y": 2},
)
compare-elements-position: (
".item-left .stab.deprecated",
".item-left .stab.portability",
".item-name .stab.deprecated",
".item-name .stab.portability",
("y"),
)

// Ensure wrap
compare-elements-position-false: (
"//*[@class='item-left']//a[text()='replaced_function']/..",
"//*[@class='item-right docblock-short'][text()='a thing with a label']",
"//*[@class='item-name']//a[text()='replaced_function']/..",
"//*[@class='desc docblock-short'][text()='a thing with a label']",
("y"),
)
compare-elements-position-false: (
".item-left .stab.deprecated",
"//*[@class='item-right docblock-short'][text()='a thing with a label']",
".item-name .stab.deprecated",
"//*[@class='desc docblock-short'][text()='a thing with a label']",
("y"),
)
26 changes: 13 additions & 13 deletions tests/rustdoc-gui/module-items-font.goml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// This test checks that the correct font is used on module items (in index.html pages).
goto: "file://" + |DOC_PATH| + "/test_docs/index.html"
assert-css: (
".item-table .item-left > a",
".item-table .item-name > a",
{"font-family": '"Fira Sans", Arial, NanumBarunGothic, sans-serif'},
ALL,
)
Expand All @@ -13,55 +13,55 @@ assert-css: (

// modules
assert-css: (
"#modules + .item-table .item-left a",
"#modules + .item-table .item-name a",
{"font-family": '"Fira Sans", Arial, NanumBarunGothic, sans-serif'},
)
assert-css: (
"#modules + .item-table .item-right.docblock-short",
"#modules + .item-table .desc.docblock-short",
{"font-family": '"Source Serif 4", NanumBarunGothic, serif'},
)
// structs
assert-css: (
"#structs + .item-table .item-left a",
"#structs + .item-table .item-name a",
{"font-family": '"Fira Sans", Arial, NanumBarunGothic, sans-serif'},
)
assert-css: (
"#structs + .item-table .item-right.docblock-short",
"#structs + .item-table .desc.docblock-short",
{"font-family": '"Source Serif 4", NanumBarunGothic, serif'},
)
// enums
assert-css: (
"#enums + .item-table .item-left a",
"#enums + .item-table .item-name a",
{"font-family": '"Fira Sans", Arial, NanumBarunGothic, sans-serif'},
)
assert-css: (
"#enums + .item-table .item-right.docblock-short",
"#enums + .item-table .desc.docblock-short",
{"font-family": '"Source Serif 4", NanumBarunGothic, serif'},
)
// traits
assert-css: (
"#traits + .item-table .item-left a",
"#traits + .item-table .item-name a",
{"font-family": '"Fira Sans", Arial, NanumBarunGothic, sans-serif'},
)
assert-css: (
"#traits + .item-table .item-right.docblock-short",
"#traits + .item-table .desc.docblock-short",
{"font-family": '"Source Serif 4", NanumBarunGothic, serif'},
)
// functions
assert-css: (
"#functions + .item-table .item-left a",
"#functions + .item-table .item-name a",
{"font-family": '"Fira Sans", Arial, NanumBarunGothic, sans-serif'},
)
assert-css: (
"#functions + .item-table .item-right.docblock-short",
"#functions + .item-table .desc.docblock-short",
{"font-family": '"Source Serif 4", NanumBarunGothic, serif'},
)
// keywords
assert-css: (
"#keywords + .item-table .item-left a",
"#keywords + .item-table .item-name a",
{"font-family": '"Fira Sans", Arial, NanumBarunGothic, sans-serif'},
)
assert-css: (
"#keywords + .item-table .item-right.docblock-short",
"#keywords + .item-table .desc.docblock-short",
{"font-family": '"Source Serif 4", NanumBarunGothic, serif'},
)
10 changes: 5 additions & 5 deletions tests/rustdoc-gui/sidebar.goml
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ assert-text: (".sidebar-elems section ul > li:nth-child(8)", "Functions")
assert-text: (".sidebar-elems section ul > li:nth-child(9)", "Type Definitions")
assert-text: (".sidebar-elems section ul > li:nth-child(10)", "Unions")
assert-text: (".sidebar-elems section ul > li:nth-child(11)", "Keywords")
assert-text: ("#structs + .item-table .item-left > a", "Foo")
click: "#structs + .item-table .item-left > a"
assert-text: ("#structs + .item-table .item-name > a", "Foo")
click: "#structs + .item-table .item-name > a"

// PAGE: struct.Foo.html
assert-count: (".sidebar .location", 1)
Expand Down Expand Up @@ -103,8 +103,8 @@ assert-text: (".sidebar-elems > section ul.block > li:nth-child(2)", "Structs")
assert-text: (".sidebar-elems > section ul.block > li:nth-child(3)", "Traits")
assert-text: (".sidebar-elems > section ul.block > li:nth-child(4)", "Functions")
assert-text: (".sidebar-elems > section ul.block > li:nth-child(5)", "Type Definitions")
assert-text: ("#functions + .item-table .item-left > a", "foobar")
click: "#functions + .item-table .item-left > a"
assert-text: ("#functions + .item-table .item-name > a", "foobar")
click: "#functions + .item-table .item-name > a"

// PAGE: fn.foobar.html
// In items containing no items (like functions or constants) and in modules, we have no
Expand All @@ -127,7 +127,7 @@ assert-text: (".sidebar > .location", "Module sub_sub_module")
// We check that we don't have the crate list.
assert-false: ".sidebar-elems .crate"
assert-text: (".sidebar-elems > section ul > li:nth-child(1)", "Functions")
assert-text: ("#functions + .item-table .item-left > a", "foo")
assert-text: ("#functions + .item-table .item-name > a", "foo")

// Links to trait implementations in the sidebar should not wrap even if they are long.
goto: "file://" + |DOC_PATH| + "/lib2/struct.HasALongTraitWithParams.html"
Expand Down
2 changes: 1 addition & 1 deletion tests/rustdoc-gui/unsafe-fn.goml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ define-function: (
local-storage: {"rustdoc-theme": |theme|, "rustdoc-use-system-theme": "false"}
// We reload the page so the local storage settings are being used.
reload:
assert-css: (".item-left sup", {"color": |color|})
assert-css: (".item-name sup", {"color": |color|})
},
)

Expand Down
4 changes: 2 additions & 2 deletions tests/rustdoc/cfg_doc_reexport.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
#![no_core]

// @has 'foo/index.html'
// @has - '//*[@class="item-left"]/*[@class="stab portability"]' 'foobar'
// @has - '//*[@class="item-left"]/*[@class="stab portability"]' 'bar'
// @has - '//*[@class="item-name"]/*[@class="stab portability"]' 'foobar'
// @has - '//*[@class="item-name"]/*[@class="stab portability"]' 'bar'

#[doc(cfg(feature = "foobar"))]
mod imp_priv {
Expand Down
6 changes: 3 additions & 3 deletions tests/rustdoc/deprecated.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// @has deprecated/index.html '//*[@class="item-left"]/span[@class="stab deprecated"]' \
// @has deprecated/index.html '//*[@class="item-name"]/span[@class="stab deprecated"]' \
// 'Deprecated'
// @has - '//*[@class="item-right docblock-short"]' 'Deprecated docs'
// @has - '//*[@class="desc docblock-short"]' 'Deprecated docs'

// @has deprecated/struct.S.html '//*[@class="stab deprecated"]' \
// 'Deprecated since 1.0.0: text'
/// Deprecated docs
#[deprecated(since = "1.0.0", note = "text")]
pub struct S;

// @matches deprecated/index.html '//*[@class="item-right docblock-short"]' '^Docs'
// @matches deprecated/index.html '//*[@class="desc docblock-short"]' '^Docs'
/// Docs
pub struct T;

Expand Down
6 changes: 3 additions & 3 deletions tests/rustdoc/doc-cfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub struct Portable;
// @has doc_cfg/unix_only/index.html \
// '//*[@id="main-content"]/*[@class="item-info"]/*[@class="stab portability"]' \
// 'Available on Unix only.'
// @matches - '//*[@class="item-left"]//*[@class="stab portability"]' '\AARM\Z'
// @matches - '//*[@class="item-name"]//*[@class="stab portability"]' '\AARM\Z'
// @count - '//*[@class="stab portability"]' 2
#[doc(cfg(unix))]
pub mod unix_only {
Expand Down Expand Up @@ -42,7 +42,7 @@ pub mod unix_only {
// @has doc_cfg/wasi_only/index.html \
// '//*[@id="main-content"]/*[@class="item-info"]/*[@class="stab portability"]' \
// 'Available on WASI only.'
// @matches - '//*[@class="item-left"]//*[@class="stab portability"]' '\AWebAssembly\Z'
// @matches - '//*[@class="item-name"]//*[@class="stab portability"]' '\AWebAssembly\Z'
// @count - '//*[@class="stab portability"]' 2
#[doc(cfg(target_os = "wasi"))]
pub mod wasi_only {
Expand Down Expand Up @@ -74,7 +74,7 @@ pub mod wasi_only {

// the portability header is different on the module view versus the full view
// @has doc_cfg/index.html
// @matches - '//*[@class="item-left"]//*[@class="stab portability"]' '\Aavx\Z'
// @matches - '//*[@class="item-name"]//*[@class="stab portability"]' '\Aavx\Z'

// @has doc_cfg/fn.uses_target_feature.html
// @has - '//*[@id="main-content"]/*[@class="item-info"]/*[@class="stab portability"]' \
Expand Down
4 changes: 2 additions & 2 deletions tests/rustdoc/duplicate-cfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
#![feature(doc_cfg)]

// @has 'foo/index.html'
// @matches '-' '//*[@class="item-left"]//*[@class="stab portability"]' '^sync$'
// @has '-' '//*[@class="item-left"]//*[@class="stab portability"]/@title' 'Available on crate feature `sync` only'
// @matches '-' '//*[@class="item-name"]//*[@class="stab portability"]' '^sync$'
// @has '-' '//*[@class="item-name"]//*[@class="stab portability"]/@title' 'Available on crate feature `sync` only'

// @has 'foo/struct.Foo.html'
// @has '-' '//*[@class="stab portability"]' 'sync'
Expand Down
Loading

0 comments on commit 4165de4

Please sign in to comment.