Skip to content

Commit

Permalink
Update "rustdoc-theme" setting name to "rustdoc-theme2"
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeGomez committed Sep 5, 2022
1 parent d7bf051 commit 87e9dc3
Show file tree
Hide file tree
Showing 19 changed files with 68 additions and 58 deletions.
17 changes: 13 additions & 4 deletions src/librustdoc/html/static/js/settings.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Local js definitions:
/* global getSettingValue, getVirtualKey, updateLocalStorage, updateSystemTheme */
/* global addClass, removeClass, onEach, onEachLazy, blurHandler, elemIsInParent */
/* global MAIN_ID, getVar, getSettingsButton, isUsingSystemTheme */
/* global MAIN_ID, getVar, getSettingsButton, isUsingSystemTheme, CURRENT_THEME_SETTING_VERSION */

"use strict";

Expand All @@ -12,7 +12,7 @@
updateLocalStorage(settingName, value);

switch (settingName) {
case "theme":
case `theme${CURRENT_THEME_SETTING_VERSION}`:
case "preferred-dark-theme":
case "preferred-light-theme":
updateSystemTheme();
Expand Down Expand Up @@ -92,6 +92,13 @@
});
}

function getOr(obj, property, or) {
if (obj[property] !== undefined) {
return obj[property];
}
return or;
}

/**
* This function builds the sections inside the "settings page". It takes a `settings` list
* as argument which describes each setting and how to render it. It returns a string
Expand All @@ -107,6 +114,7 @@
for (const setting of settings) {
output += "<div class=\"setting-line\">";
const js_data_name = setting["js_name"];
const js_data_version = getOr(setting, "js_name_version", "");
const setting_name = setting["name"];

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

output += `<label for="${js_data_name}-${optionAttr}" class="choice">\
<input type="radio" name="${js_data_name}" \
id="${js_data_name}-${optionAttr}" value="${optionAttr}"${checked}>\
<input type="radio" name="${js_data_name}${js_data_version}" \
id="${js_data_name}-${optionAttr}" value="${optionAttr}"${checked}>\
<span>${option}</span>\
</label>`;
});
Expand Down Expand Up @@ -150,6 +158,7 @@
{
"name": "Theme",
"js_name": "theme",
"js_name_version": CURRENT_THEME_SETTING_VERSION,
"default": "system-preference",
"options": themes.concat("system preference"),
},
Expand Down
3 changes: 2 additions & 1 deletion src/librustdoc/html/static/js/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ window.mainTheme = document.getElementById("mainThemeStyle");
// If you update this line, then you also need to update the two media queries with the same
// warning in rustdoc.css
window.RUSTDOC_MOBILE_BREAKPOINT = 701;
const CURRENT_THEME_SETTING_VERSION = "2";

const settingsDataset = (function() {
const settingsElement = document.getElementById("default-settings");
Expand Down Expand Up @@ -47,7 +48,7 @@ function isUsingSystemTheme() {
}

function getTheme() {
const current = getSettingValue("theme2");
const current = getSettingValue(`theme${CURRENT_THEME_SETTING_VERSION}`);
if (current === null) {
// We try to get what's being used in the previous version.
return getSettingValue("theme");
Expand Down
6 changes: 3 additions & 3 deletions src/test/rustdoc-gui/anchors.goml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ goto: file://|DOC_PATH|/staged_api/struct.Foo.html
show-text: true

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

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

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

assert-css: ("#toggle-all-docs", {"color": "rgb(197, 197, 197)"})
Expand Down
6 changes: 3 additions & 3 deletions src/test/rustdoc-gui/code-color.goml
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,23 @@ goto: file://|DOC_PATH|/test_docs/fn.foo.html
// If the text isn't displayed, the browser doesn't compute color style correctly...
show-text: true
// Set the theme to dark.
local-storage: {"rustdoc-theme": "dark"}
local-storage: {"rustdoc-theme2": "dark"}
// We reload the page so the local storage settings are being used.
reload:

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

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

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

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

Expand Down
2 changes: 1 addition & 1 deletion src/test/rustdoc-gui/docblock-details.goml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// This ensures that the `<details>`/`<summary>` elements are displayed as expected.
goto: file://|DOC_PATH|/test_docs/details/struct.Details.html
show-text: true
local-storage: {"rustdoc-theme": "dark"}
local-storage: {"rustdoc-theme2": "dark"}
reload:

// We first check that the headers in the `.top-doc` doc block still have their
Expand Down
6 changes: 3 additions & 3 deletions src/test/rustdoc-gui/headers-color.goml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ goto: file://|DOC_PATH|/test_docs/struct.Foo.html
show-text: true

// Ayu theme
local-storage: {"rustdoc-theme": "ayu"}
local-storage: {"rustdoc-theme2": "ayu"}
reload:

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

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

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

// Light theme
local-storage: {"rustdoc-theme": "light"}
local-storage: {"rustdoc-theme2": "light"}
reload:

goto: file://|DOC_PATH|/test_docs/struct.Foo.html
Expand Down
12 changes: 6 additions & 6 deletions src/test/rustdoc-gui/headings.goml
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ assert-css: ("h3#top-doc-prose-sub-heading", {"border-bottom-width": "1px"})

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

local-storage: {"rustdoc-theme": "dark"}
local-storage: {"rustdoc-theme2": "dark"}
reload:
assert-css: (
".top-doc .docblock h2",
Expand Down Expand Up @@ -214,7 +214,7 @@ assert-css: (
{"color": "rgb(221, 221, 221)", "border-bottom": "0px none rgb(210, 210, 210)"},
)

local-storage: {"rustdoc-theme": "ayu"}
local-storage: {"rustdoc-theme2": "ayu"}
reload:
assert-css: (
".top-doc .docblock h2",
Expand Down Expand Up @@ -245,14 +245,14 @@ assert-css: (
{"color": "rgb(197, 197, 197)", "border-bottom": "0px none rgb(92, 103, 115)"},
)

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

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

local-storage: {"rustdoc-theme": "ayu"}
local-storage: {"rustdoc-theme2": "ayu"}
reload:
assert-css: (".since", {"color": "rgb(128, 128, 128)"}, ALL)
6 changes: 3 additions & 3 deletions src/test/rustdoc-gui/jump-to-def-background.goml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
goto: file://|DOC_PATH|/src/link_to_definition/lib.rs.html

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

Expand All @@ -13,7 +13,7 @@ assert-css: (
)

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

Expand All @@ -24,7 +24,7 @@ assert-css: (
)

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

Expand Down
6 changes: 3 additions & 3 deletions src/test/rustdoc-gui/pocket-menu.goml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ assert-css: ("#settings-menu .popover", {"display": "none"})
// We check the borders color now:

// Ayu theme
local-storage: {"rustdoc-theme": "ayu"}
local-storage: {"rustdoc-theme2": "ayu"}
reload:

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

// Dark theme
local-storage: {"rustdoc-theme": "dark"}
local-storage: {"rustdoc-theme2": "dark"}
reload:

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

// Light theme
local-storage: {"rustdoc-theme": "light"}
local-storage: {"rustdoc-theme2": "light"}
reload:

click: "#help-button"
Expand Down
12 changes: 6 additions & 6 deletions src/test/rustdoc-gui/rust-logo.goml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
goto: file://|DOC_PATH|/test_docs/index.html

// First we start with the dark theme.
local-storage: {"rustdoc-theme": "dark"}
local-storage: {"rustdoc-theme2": "dark"}
reload:

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

local-storage: {"rustdoc-theme": "dark"}
local-storage: {"rustdoc-theme2": "dark"}
reload:

assert-css: (
Expand All @@ -22,7 +22,7 @@ assert-css: (
)

// Then with the ayu theme.
local-storage: {"rustdoc-theme": "ayu"}
local-storage: {"rustdoc-theme2": "ayu"}
reload:

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

local-storage: {"rustdoc-theme": "ayu"}
local-storage: {"rustdoc-theme2": "ayu"}
reload:

assert-css: (
Expand All @@ -42,7 +42,7 @@ assert-css: (
)

// And finally with the light theme.
local-storage: {"rustdoc-theme": "light"}
local-storage: {"rustdoc-theme2": "light"}
reload:

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

local-storage: {"rustdoc-theme": "light"}
local-storage: {"rustdoc-theme2": "light"}
reload:

assert-css: (
Expand Down
2 changes: 1 addition & 1 deletion src/test/rustdoc-gui/search-filter.goml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ assert-text: (".search-results-title", "Results in all crates", STARTS_WITH)

// Checking the display of the crate filter.
// We start with the light theme.
local-storage: {"rustdoc-theme": "light"}
local-storage: {"rustdoc-theme2": "light"}
reload:

timeout: 2000
Expand Down
2 changes: 1 addition & 1 deletion src/test/rustdoc-gui/search-reexport.goml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Checks that the reexports are present in the search index, can have
// doc aliases and are highligted when their ID is the hash of the page.
goto: file://|DOC_PATH|/test_docs/index.html
local-storage: {"rustdoc-theme": "dark"}
local-storage: {"rustdoc-theme2": "dark"}
reload:
// First we check that the reexport has the correct ID and no background color.
assert-text: ("//*[@id='reexport.TheStdReexport']", "pub use ::std as TheStdReexport;")
Expand Down
8 changes: 4 additions & 4 deletions src/test/rustdoc-gui/search-result-color.goml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ goto: file://|DOC_PATH|/test_docs/index.html?search=coo
show-text: true

// Ayu theme
local-storage: {"rustdoc-theme": "ayu"}
local-storage: {"rustdoc-theme2": "ayu"}
reload:

// Waiting for the search results to appear...
Expand Down Expand Up @@ -43,7 +43,7 @@ assert-css: (
)

// Dark theme
local-storage: {"rustdoc-theme": "dark"}
local-storage: {"rustdoc-theme2": "dark"}
reload:

// Waiting for the search results to appear...
Expand Down Expand Up @@ -81,7 +81,7 @@ assert-css: (
)

// Light theme
local-storage: {"rustdoc-theme": "light"}
local-storage: {"rustdoc-theme2": "light"}
reload:

// Waiting for the search results to appear...
Expand Down Expand Up @@ -122,7 +122,7 @@ assert-css: (
goto: file://|DOC_PATH|/test_docs/index.html
// We set the theme so we're sure that the correct values will be used, whatever the computer
// this test is running on.
local-storage: {"rustdoc-theme": "dark"}
local-storage: {"rustdoc-theme2": "dark"}
// If the text isn't displayed, the browser doesn't compute color style correctly...
show-text: true
// We reload the page so the local storage settings are being used.
Expand Down
4 changes: 2 additions & 2 deletions src/test/rustdoc-gui/settings.goml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ wait-for: "#alternative-display #search"
assert: "#main-content.hidden"

// Now let's check the content of the settings menu.
local-storage: {"rustdoc-theme": "dark"}
local-storage: {"rustdoc-theme2": "dark"}
reload:
click: "#settings-menu"
wait-for: "#settings"
Expand Down Expand Up @@ -111,7 +111,7 @@ assert-text: ("#theme-system-preference + span", "system preference")
// Wait for the hidden element to show up.
wait-for: ".setting-line:not(.hidden) #preferred-dark-theme"
assert: ".setting-line:not(.hidden) #preferred-light-theme"
assert-local-storage: {"rustdoc-theme": "system-preference"}
assert-local-storage: {"rustdoc-theme2": "system-preference"}

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

0 comments on commit 87e9dc3

Please sign in to comment.