about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMichael Howell <michael@notriddle.com>2023-07-14 16:46:46 -0700
committerMichael Howell <michael@notriddle.com>2023-07-14 16:54:14 -0700
commite72fba416014427d14f37fa9efb48ef6a6208bf3 (patch)
tree8abfe85527065f1f6fb5a48dfb2652bb56d8f61a
parent34bc8fbea3b72ce1f9254dbed85fddb2d7985f75 (diff)
downloadrust-e72fba416014427d14f37fa9efb48ef6a6208bf3.tar.gz
rust-e72fba416014427d14f37fa9efb48ef6a6208bf3.zip
rustdoc: use `src` consistently over `source` in JavaScript
Since the directory that contains source files is called `src`,
it makes sense to name the scripts that way, too.
-rw-r--r--src/librustdoc/html/render/write_shared.rs8
-rw-r--r--src/librustdoc/html/static/css/rustdoc.css2
-rw-r--r--src/librustdoc/html/static/js/source-script.js26
-rw-r--r--src/librustdoc/html/static_files.rs2
-rw-r--r--src/librustdoc/html/templates/page.html4
-rw-r--r--tests/rustdoc/source-file.rs2
-rw-r--r--tests/rustdoc/static-root-path.rs8
7 files changed, 26 insertions, 26 deletions
diff --git a/src/librustdoc/html/render/write_shared.rs b/src/librustdoc/html/render/write_shared.rs
index 54749e9a317..3f41765a5af 100644
--- a/src/librustdoc/html/render/write_shared.rs
+++ b/src/librustdoc/html/render/write_shared.rs
@@ -270,7 +270,7 @@ pub(super) fn write_shared(
             hierarchy.add_path(source);
         }
         let hierarchy = Rc::try_unwrap(hierarchy).unwrap();
-        let dst = cx.dst.join(&format!("source-files{}.js", cx.shared.resource_suffix));
+        let dst = cx.dst.join(&format!("src-files{}.js", cx.shared.resource_suffix));
         let make_sources = || {
             let (mut all_sources, _krates) =
                 try_err!(collect_json(&dst, krate.name(cx.tcx()).as_str()), &dst);
@@ -286,12 +286,12 @@ pub(super) fn write_shared(
                     .replace("\\\"", "\\\\\"")
             ));
             all_sources.sort();
-            let mut v = String::from("var sourcesIndex = JSON.parse('{\\\n");
+            let mut v = String::from("var srcIndex = JSON.parse('{\\\n");
             v.push_str(&all_sources.join(",\\\n"));
-            v.push_str("\\\n}');\ncreateSourceSidebar();\n");
+            v.push_str("\\\n}');\ncreateSrcSidebar();\n");
             Ok(v.into_bytes())
         };
-        write_invocation_specific("source-files.js", &make_sources)?;
+        write_invocation_specific("src-files.js", &make_sources)?;
     }
 
     // Update the search index and crate list.
diff --git a/src/librustdoc/html/static/css/rustdoc.css b/src/librustdoc/html/static/css/rustdoc.css
index fa7a29be6d3..9209915895a 100644
--- a/src/librustdoc/html/static/css/rustdoc.css
+++ b/src/librustdoc/html/static/css/rustdoc.css
@@ -1562,7 +1562,7 @@ However, it's not needed with smaller screen width because the doc/code block is
 /*
 WARNING: RUSTDOC_MOBILE_BREAKPOINT MEDIA QUERY
 If you update this line, then you also need to update the line with the same warning
-in source-script.js
+in src-script.js
 */
 @media (max-width: 700px) {
 	/* When linking to an item with an `id` (for instance, by clicking a link in the sidebar,
diff --git a/src/librustdoc/html/static/js/source-script.js b/src/librustdoc/html/static/js/source-script.js
index 54f3603865c..679c2341f02 100644
--- a/src/librustdoc/html/static/js/source-script.js
+++ b/src/librustdoc/html/static/js/source-script.js
@@ -1,5 +1,5 @@
 // From rust:
-/* global sourcesIndex */
+/* global srcIndex */
 
 // Local js definitions:
 /* global addClass, getCurrentValue, onEachLazy, removeClass, browserSupportsHistoryApi */
@@ -101,9 +101,9 @@ function createSidebarToggle() {
     return sidebarToggle;
 }
 
-// This function is called from "source-files.js", generated in `html/render/write_shared.rs`.
+// This function is called from "src-files.js", generated in `html/render/write_shared.rs`.
 // eslint-disable-next-line no-unused-vars
-function createSourceSidebar() {
+function createSrcSidebar() {
     const container = document.querySelector("nav.sidebar");
 
     const sidebarToggle = createSidebarToggle();
@@ -118,9 +118,9 @@ function createSourceSidebar() {
     title.className = "title";
     title.innerText = "Files";
     sidebar.appendChild(title);
-    Object.keys(sourcesIndex).forEach(key => {
-        sourcesIndex[key][NAME_OFFSET] = key;
-        hasFoundFile = createDirEntry(sourcesIndex[key], sidebar, "", hasFoundFile);
+    Object.keys(srcIndex).forEach(key => {
+        srcIndex[key][NAME_OFFSET] = key;
+        hasFoundFile = createDirEntry(srcIndex[key], sidebar, "", hasFoundFile);
     });
 
     container.appendChild(sidebar);
@@ -133,7 +133,7 @@ function createSourceSidebar() {
 
 const lineNumbersRegex = /^#?(\d+)(?:-(\d+))?$/;
 
-function highlightSourceLines(match) {
+function highlightSrcLines(match) {
     if (typeof match === "undefined") {
         match = window.location.hash.match(lineNumbersRegex);
     }
@@ -172,7 +172,7 @@ function highlightSourceLines(match) {
     }
 }
 
-const handleSourceHighlight = (function() {
+const handleSrcHighlight = (function() {
     let prev_line_id = 0;
 
     const set_fragment = name => {
@@ -180,7 +180,7 @@ const handleSourceHighlight = (function() {
             y = window.scrollY;
         if (browserSupportsHistoryApi()) {
             history.replaceState(null, null, "#" + name);
-            highlightSourceLines();
+            highlightSrcLines();
         } else {
             location.replace("#" + name);
         }
@@ -221,15 +221,15 @@ const handleSourceHighlight = (function() {
 window.addEventListener("hashchange", () => {
     const match = window.location.hash.match(lineNumbersRegex);
     if (match) {
-        return highlightSourceLines(match);
+        return highlightSrcLines(match);
     }
 });
 
 onEachLazy(document.getElementsByClassName("src-line-numbers"), el => {
-    el.addEventListener("click", handleSourceHighlight);
+    el.addEventListener("click", handleSrcHighlight);
 });
 
-highlightSourceLines();
+highlightSrcLines();
 
-window.createSourceSidebar = createSourceSidebar;
+window.createSrcSidebar = createSrcSidebar;
 })();
diff --git a/src/librustdoc/html/static_files.rs b/src/librustdoc/html/static_files.rs
index 767b974cc91..5d2e4b073c1 100644
--- a/src/librustdoc/html/static_files.rs
+++ b/src/librustdoc/html/static_files.rs
@@ -97,7 +97,7 @@ static_files! {
     main_js => "static/js/main.js",
     search_js => "static/js/search.js",
     settings_js => "static/js/settings.js",
-    source_script_js => "static/js/source-script.js",
+    src_script_js => "static/js/src-script.js",
     storage_js => "static/js/storage.js",
     scrape_examples_js => "static/js/scrape-examples.js",
     wheel_svg => "static/images/wheel.svg",
diff --git a/src/librustdoc/html/templates/page.html b/src/librustdoc/html/templates/page.html
index f24cea5fd5a..60ccfe4da44 100644
--- a/src/librustdoc/html/templates/page.html
+++ b/src/librustdoc/html/templates/page.html
@@ -43,8 +43,8 @@
     {% if page.css_class.contains("crate") %}
     <script defer src="{{page.root_path|safe}}crates{{page.resource_suffix}}.js"></script> {# #}
     {% else if page.css_class == "src" %}
-    <script defer src="{{static_root_path|safe}}{{files.source_script_js}}"></script> {# #}
-    <script defer src="{{page.root_path|safe}}source-files{{page.resource_suffix}}.js"></script> {# #}
+    <script defer src="{{static_root_path|safe}}{{files.src_script_js}}"></script> {# #}
+    <script defer src="{{page.root_path|safe}}src-files{{page.resource_suffix}}.js"></script> {# #}
     {% else if !page.css_class.contains("mod") %}
     <script defer src="sidebar-items{{page.resource_suffix}}.js"></script> {# #}
     {% endif %}
diff --git a/tests/rustdoc/source-file.rs b/tests/rustdoc/source-file.rs
index 4e166479063..16d4cbe3a34 100644
--- a/tests/rustdoc/source-file.rs
+++ b/tests/rustdoc/source-file.rs
@@ -1,5 +1,5 @@
 #![crate_name = "foo"]
 
-// @hasraw source-files.js source-file.rs
+// @hasraw src-files.js source-file.rs
 
 pub struct Foo;
diff --git a/tests/rustdoc/static-root-path.rs b/tests/rustdoc/static-root-path.rs
index 86928b0fb0a..3148ea047b7 100644
--- a/tests/rustdoc/static-root-path.rs
+++ b/tests/rustdoc/static-root-path.rs
@@ -8,10 +8,10 @@
 pub struct SomeStruct;
 
 // @has src/static_root_path/static-root-path.rs.html
-// @matchesraw - '"/cache/source-script-'
-// @!matchesraw - '"\.\./\.\./source-script'
-// @matchesraw - '"\.\./\.\./source-files.js"'
-// @!matchesraw - '"/cache/source-files\.js"'
+// @matchesraw - '"/cache/src-script-'
+// @!matchesraw - '"\.\./\.\./src-script'
+// @matchesraw - '"\.\./\.\./src-files.js"'
+// @!matchesraw - '"/cache/src-files\.js"'
 
 // @has settings.html
 // @matchesraw - '/cache/settings-'