Skip to content

Commit 87e9dc3

Browse files
Update "rustdoc-theme" setting name to "rustdoc-theme2"
1 parent d7bf051 commit 87e9dc3

19 files changed

+68
-58
lines changed

src/librustdoc/html/static/js/settings.js

+13-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Local js definitions:
22
/* global getSettingValue, getVirtualKey, updateLocalStorage, updateSystemTheme */
33
/* global addClass, removeClass, onEach, onEachLazy, blurHandler, elemIsInParent */
4-
/* global MAIN_ID, getVar, getSettingsButton, isUsingSystemTheme */
4+
/* global MAIN_ID, getVar, getSettingsButton, isUsingSystemTheme, CURRENT_THEME_SETTING_VERSION */
55

66
"use strict";
77

@@ -12,7 +12,7 @@
1212
updateLocalStorage(settingName, value);
1313

1414
switch (settingName) {
15-
case "theme":
15+
case `theme${CURRENT_THEME_SETTING_VERSION}`:
1616
case "preferred-dark-theme":
1717
case "preferred-light-theme":
1818
updateSystemTheme();
@@ -92,6 +92,13 @@
9292
});
9393
}
9494

95+
function getOr(obj, property, or) {
96+
if (obj[property] !== undefined) {
97+
return obj[property];
98+
}
99+
return or;
100+
}
101+
95102
/**
96103
* This function builds the sections inside the "settings page". It takes a `settings` list
97104
* as argument which describes each setting and how to render it. It returns a string
@@ -107,6 +114,7 @@
107114
for (const setting of settings) {
108115
output += "<div class=\"setting-line\">";
109116
const js_data_name = setting["js_name"];
117+
const js_data_version = getOr(setting, "js_name_version", "");
110118
const setting_name = setting["name"];
111119

112120
if (setting["options"] !== undefined) {
@@ -119,8 +127,8 @@
119127
const checked = optionAttr === setting["default"] ? " checked" : "";
120128

121129
output += `<label for="${js_data_name}-${optionAttr}" class="choice">\
122-
<input type="radio" name="${js_data_name}" \
123-
id="${js_data_name}-${optionAttr}" value="${optionAttr}"${checked}>\
130+
<input type="radio" name="${js_data_name}${js_data_version}" \
131+
id="${js_data_name}-${optionAttr}" value="${optionAttr}"${checked}>\
124132
<span>${option}</span>\
125133
</label>`;
126134
});
@@ -150,6 +158,7 @@
150158
{
151159
"name": "Theme",
152160
"js_name": "theme",
161+
"js_name_version": CURRENT_THEME_SETTING_VERSION,
153162
"default": "system-preference",
154163
"options": themes.concat("system preference"),
155164
},

src/librustdoc/html/static/js/storage.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ window.mainTheme = document.getElementById("mainThemeStyle");
1212
// If you update this line, then you also need to update the two media queries with the same
1313
// warning in rustdoc.css
1414
window.RUSTDOC_MOBILE_BREAKPOINT = 701;
15+
const CURRENT_THEME_SETTING_VERSION = "2";
1516

1617
const settingsDataset = (function() {
1718
const settingsElement = document.getElementById("default-settings");
@@ -47,7 +48,7 @@ function isUsingSystemTheme() {
4748
}
4849

4950
function getTheme() {
50-
const current = getSettingValue("theme2");
51+
const current = getSettingValue(`theme${CURRENT_THEME_SETTING_VERSION}`);
5152
if (current === null) {
5253
// We try to get what's being used in the previous version.
5354
return getSettingValue("theme");

src/test/rustdoc-gui/anchors.goml

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ goto: file://|DOC_PATH|/staged_api/struct.Foo.html
55
show-text: true
66

77
// Set the theme to light.
8-
local-storage: {"rustdoc-theme": "light"}
8+
local-storage: {"rustdoc-theme2": "light"}
99
// We reload the page so the local storage settings are being used.
1010
reload:
1111

@@ -56,7 +56,7 @@ assert-css: ("#title-for-struct-impl-item-doc", {"margin-left": "0px"})
5656
//
5757
// We do the same checks with the dark theme now.
5858
//
59-
local-storage: {"rustdoc-theme": "dark", "rustdoc-use-system-theme": "false"}
59+
local-storage: {"rustdoc-theme2": "dark"}
6060
goto: file://|DOC_PATH|/staged_api/struct.Foo.html
6161

6262
assert-css: ("#toggle-all-docs", {"color": "rgb(221, 221, 221)"})
@@ -106,7 +106,7 @@ assert-css: ("#title-for-struct-impl-item-doc", {"margin-left": "0px"})
106106
//
107107
// We do the same checks with the ayu theme now.
108108
//
109-
local-storage: {"rustdoc-theme": "ayu", "rustdoc-use-system-theme": "false"}
109+
local-storage: {"rustdoc-theme2": "ayu"}
110110
goto: file://|DOC_PATH|/staged_api/struct.Foo.html
111111

112112
assert-css: ("#toggle-all-docs", {"color": "rgb(197, 197, 197)"})

src/test/rustdoc-gui/code-color.goml

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,23 @@ goto: file://|DOC_PATH|/test_docs/fn.foo.html
66
// If the text isn't displayed, the browser doesn't compute color style correctly...
77
show-text: true
88
// Set the theme to dark.
9-
local-storage: {"rustdoc-theme": "dark"}
9+
local-storage: {"rustdoc-theme2": "dark"}
1010
// We reload the page so the local storage settings are being used.
1111
reload:
1212

1313
assert-css: (".docblock pre > code", {"color": "rgb(221, 221, 221)"}, ALL)
1414
assert-css: (".docblock > p > code", {"color": "rgb(221, 221, 221)"}, ALL)
1515

1616
// Set the theme to ayu.
17-
local-storage: {"rustdoc-theme": "ayu"}
17+
local-storage: {"rustdoc-theme2": "ayu"}
1818
// We reload the page so the local storage settings are being used.
1919
reload:
2020

2121
assert-css: (".docblock pre > code", {"color": "rgb(230, 225, 207)"}, ALL)
2222
assert-css: (".docblock > p > code", {"color": "rgb(255, 180, 84)"}, ALL)
2323

2424
// Set the theme to light.
25-
local-storage: {"rustdoc-theme": "light"}
25+
local-storage: {"rustdoc-theme2": "light"}
2626
// We reload the page so the local storage settings are being used.
2727
reload:
2828

src/test/rustdoc-gui/docblock-details.goml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// This ensures that the `<details>`/`<summary>` elements are displayed as expected.
22
goto: file://|DOC_PATH|/test_docs/details/struct.Details.html
33
show-text: true
4-
local-storage: {"rustdoc-theme": "dark"}
4+
local-storage: {"rustdoc-theme2": "dark"}
55
reload:
66

77
// We first check that the headers in the `.top-doc` doc block still have their

src/test/rustdoc-gui/headers-color.goml

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ goto: file://|DOC_PATH|/test_docs/struct.Foo.html
55
show-text: true
66

77
// Ayu theme
8-
local-storage: {"rustdoc-theme": "ayu"}
8+
local-storage: {"rustdoc-theme2": "ayu"}
99
reload:
1010

1111
assert-css: (
@@ -40,7 +40,7 @@ goto: file://|DOC_PATH|/test_docs/struct.HeavilyDocumentedStruct.html
4040
assert-css: (".docblock > :not(p) > a", {"color": "rgb(57, 175, 215)"}, ALL)
4141

4242
// Dark theme
43-
local-storage: {"rustdoc-theme": "dark"}
43+
local-storage: {"rustdoc-theme2": "dark"}
4444
goto: file://|DOC_PATH|/test_docs/struct.Foo.html
4545

4646
assert-css: (
@@ -75,7 +75,7 @@ goto: file://|DOC_PATH|/test_docs/struct.HeavilyDocumentedStruct.html
7575
assert-css: (".docblock > :not(p) > a", {"color": "rgb(210, 153, 29)"}, ALL)
7676

7777
// Light theme
78-
local-storage: {"rustdoc-theme": "light"}
78+
local-storage: {"rustdoc-theme2": "light"}
7979
reload:
8080

8181
goto: file://|DOC_PATH|/test_docs/struct.Foo.html

src/test/rustdoc-gui/headings.goml

+6-6
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ assert-css: ("h3#top-doc-prose-sub-heading", {"border-bottom-width": "1px"})
152152

153153
// Checking colors now.
154154
show-text: true
155-
local-storage: {"rustdoc-theme": "light"}
155+
local-storage: {"rustdoc-theme2": "light"}
156156
goto: file://|DOC_PATH|/test_docs/struct.HeavilyDocumentedStruct.html
157157
assert-css: (
158158
".top-doc .docblock h2",
@@ -183,7 +183,7 @@ assert-css: (
183183
{"color": "rgb(0, 0, 0)", "border-bottom": "0px none rgb(221, 221, 221)"},
184184
)
185185

186-
local-storage: {"rustdoc-theme": "dark"}
186+
local-storage: {"rustdoc-theme2": "dark"}
187187
reload:
188188
assert-css: (
189189
".top-doc .docblock h2",
@@ -214,7 +214,7 @@ assert-css: (
214214
{"color": "rgb(221, 221, 221)", "border-bottom": "0px none rgb(210, 210, 210)"},
215215
)
216216

217-
local-storage: {"rustdoc-theme": "ayu"}
217+
local-storage: {"rustdoc-theme2": "ayu"}
218218
reload:
219219
assert-css: (
220220
".top-doc .docblock h2",
@@ -245,14 +245,14 @@ assert-css: (
245245
{"color": "rgb(197, 197, 197)", "border-bottom": "0px none rgb(92, 103, 115)"},
246246
)
247247

248-
local-storage: {"rustdoc-theme": "light"}
248+
local-storage: {"rustdoc-theme2": "light"}
249249
goto: file://|DOC_PATH|/staged_api/struct.Foo.html
250250
assert-css: (".since", {"color": "rgb(128, 128, 128)"}, ALL)
251251

252-
local-storage: {"rustdoc-theme": "dark"}
252+
local-storage: {"rustdoc-theme2": "dark"}
253253
reload:
254254
assert-css: (".since", {"color": "rgb(128, 128, 128)"}, ALL)
255255

256-
local-storage: {"rustdoc-theme": "ayu"}
256+
local-storage: {"rustdoc-theme2": "ayu"}
257257
reload:
258258
assert-css: (".since", {"color": "rgb(128, 128, 128)"}, ALL)

src/test/rustdoc-gui/jump-to-def-background.goml

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
goto: file://|DOC_PATH|/src/link_to_definition/lib.rs.html
33

44
// Set the theme to dark.
5-
local-storage: {"rustdoc-theme": "dark"}
5+
local-storage: {"rustdoc-theme2": "dark"}
66
// We reload the page so the local storage settings are being used.
77
reload:
88

@@ -13,7 +13,7 @@ assert-css: (
1313
)
1414

1515
// Set the theme to ayu.
16-
local-storage: {"rustdoc-theme": "ayu"}
16+
local-storage: {"rustdoc-theme2": "ayu"}
1717
// We reload the page so the local storage settings are being used.
1818
reload:
1919

@@ -24,7 +24,7 @@ assert-css: (
2424
)
2525

2626
// Set the theme to light.
27-
local-storage: {"rustdoc-theme": "light"}
27+
local-storage: {"rustdoc-theme2": "light"}
2828
// We reload the page so the local storage settings are being used.
2929
reload:
3030

src/test/rustdoc-gui/pocket-menu.goml

+3-3
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ assert-css: ("#settings-menu .popover", {"display": "none"})
3232
// We check the borders color now:
3333

3434
// Ayu theme
35-
local-storage: {"rustdoc-theme": "ayu"}
35+
local-storage: {"rustdoc-theme2": "ayu"}
3636
reload:
3737

3838
click: "#help-button"
@@ -44,7 +44,7 @@ compare-elements-css: ("#help-button .popover", "#help-button .top", ["border-co
4444
compare-elements-css: ("#help-button .popover", "#help-button .bottom", ["border-color"])
4545

4646
// Dark theme
47-
local-storage: {"rustdoc-theme": "dark"}
47+
local-storage: {"rustdoc-theme2": "dark"}
4848
reload:
4949

5050
click: "#help-button"
@@ -56,7 +56,7 @@ compare-elements-css: ("#help-button .popover", "#help-button .top", ["border-co
5656
compare-elements-css: ("#help-button .popover", "#help-button .bottom", ["border-color"])
5757

5858
// Light theme
59-
local-storage: {"rustdoc-theme": "light"}
59+
local-storage: {"rustdoc-theme2": "light"}
6060
reload:
6161

6262
click: "#help-button"

src/test/rustdoc-gui/rust-logo.goml

+6-6
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
goto: file://|DOC_PATH|/test_docs/index.html
33

44
// First we start with the dark theme.
5-
local-storage: {"rustdoc-theme": "dark"}
5+
local-storage: {"rustdoc-theme2": "dark"}
66
reload:
77

88
assert-css: (
@@ -13,7 +13,7 @@ assert-css: (
1313
// In the source view page now.
1414
goto: file://|DOC_PATH|/src/test_docs/lib.rs.html
1515

16-
local-storage: {"rustdoc-theme": "dark"}
16+
local-storage: {"rustdoc-theme2": "dark"}
1717
reload:
1818

1919
assert-css: (
@@ -22,7 +22,7 @@ assert-css: (
2222
)
2323

2424
// Then with the ayu theme.
25-
local-storage: {"rustdoc-theme": "ayu"}
25+
local-storage: {"rustdoc-theme2": "ayu"}
2626
reload:
2727

2828
assert-css: (
@@ -33,7 +33,7 @@ assert-css: (
3333
// In the source view page now.
3434
goto: file://|DOC_PATH|/src/test_docs/lib.rs.html
3535

36-
local-storage: {"rustdoc-theme": "ayu"}
36+
local-storage: {"rustdoc-theme2": "ayu"}
3737
reload:
3838

3939
assert-css: (
@@ -42,7 +42,7 @@ assert-css: (
4242
)
4343

4444
// And finally with the light theme.
45-
local-storage: {"rustdoc-theme": "light"}
45+
local-storage: {"rustdoc-theme2": "light"}
4646
reload:
4747

4848
assert-css: (
@@ -53,7 +53,7 @@ assert-css: (
5353
// In the source view page now.
5454
goto: file://|DOC_PATH|/src/test_docs/lib.rs.html
5555

56-
local-storage: {"rustdoc-theme": "light"}
56+
local-storage: {"rustdoc-theme2": "light"}
5757
reload:
5858

5959
assert-css: (

src/test/rustdoc-gui/search-filter.goml

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ assert-text: (".search-results-title", "Results in all crates", STARTS_WITH)
5353

5454
// Checking the display of the crate filter.
5555
// We start with the light theme.
56-
local-storage: {"rustdoc-theme": "light"}
56+
local-storage: {"rustdoc-theme2": "light"}
5757
reload:
5858

5959
timeout: 2000

src/test/rustdoc-gui/search-reexport.goml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Checks that the reexports are present in the search index, can have
22
// doc aliases and are highligted when their ID is the hash of the page.
33
goto: file://|DOC_PATH|/test_docs/index.html
4-
local-storage: {"rustdoc-theme": "dark"}
4+
local-storage: {"rustdoc-theme2": "dark"}
55
reload:
66
// First we check that the reexport has the correct ID and no background color.
77
assert-text: ("//*[@id='reexport.TheStdReexport']", "pub use ::std as TheStdReexport;")

src/test/rustdoc-gui/search-result-color.goml

+4-4
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ goto: file://|DOC_PATH|/test_docs/index.html?search=coo
55
show-text: true
66

77
// Ayu theme
8-
local-storage: {"rustdoc-theme": "ayu"}
8+
local-storage: {"rustdoc-theme2": "ayu"}
99
reload:
1010

1111
// Waiting for the search results to appear...
@@ -43,7 +43,7 @@ assert-css: (
4343
)
4444

4545
// Dark theme
46-
local-storage: {"rustdoc-theme": "dark"}
46+
local-storage: {"rustdoc-theme2": "dark"}
4747
reload:
4848

4949
// Waiting for the search results to appear...
@@ -81,7 +81,7 @@ assert-css: (
8181
)
8282

8383
// Light theme
84-
local-storage: {"rustdoc-theme": "light"}
84+
local-storage: {"rustdoc-theme2": "light"}
8585
reload:
8686

8787
// Waiting for the search results to appear...
@@ -122,7 +122,7 @@ assert-css: (
122122
goto: file://|DOC_PATH|/test_docs/index.html
123123
// We set the theme so we're sure that the correct values will be used, whatever the computer
124124
// this test is running on.
125-
local-storage: {"rustdoc-theme": "dark"}
125+
local-storage: {"rustdoc-theme2": "dark"}
126126
// If the text isn't displayed, the browser doesn't compute color style correctly...
127127
show-text: true
128128
// We reload the page so the local storage settings are being used.

src/test/rustdoc-gui/settings.goml

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ wait-for: "#alternative-display #search"
3030
assert: "#main-content.hidden"
3131

3232
// Now let's check the content of the settings menu.
33-
local-storage: {"rustdoc-theme": "dark"}
33+
local-storage: {"rustdoc-theme2": "dark"}
3434
reload:
3535
click: "#settings-menu"
3636
wait-for: "#settings"
@@ -111,7 +111,7 @@ assert-text: ("#theme-system-preference + span", "system preference")
111111
// Wait for the hidden element to show up.
112112
wait-for: ".setting-line:not(.hidden) #preferred-dark-theme"
113113
assert: ".setting-line:not(.hidden) #preferred-light-theme"
114-
assert-local-storage: {"rustdoc-theme": "system-preference"}
114+
assert-local-storage: {"rustdoc-theme2": "system-preference"}
115115

116116
// We check their text as well.
117117
assert-text: ("#preferred-dark-theme .setting-name", "Preferred dark theme")

0 commit comments

Comments
 (0)