Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit e72fba4

Browse files
committedJul 14, 2023
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.
1 parent 34bc8fb commit e72fba4

File tree

7 files changed

+26
-26
lines changed

7 files changed

+26
-26
lines changed
 

‎src/librustdoc/html/render/write_shared.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ pub(super) fn write_shared(
270270
hierarchy.add_path(source);
271271
}
272272
let hierarchy = Rc::try_unwrap(hierarchy).unwrap();
273-
let dst = cx.dst.join(&format!("source-files{}.js", cx.shared.resource_suffix));
273+
let dst = cx.dst.join(&format!("src-files{}.js", cx.shared.resource_suffix));
274274
let make_sources = || {
275275
let (mut all_sources, _krates) =
276276
try_err!(collect_json(&dst, krate.name(cx.tcx()).as_str()), &dst);
@@ -286,12 +286,12 @@ pub(super) fn write_shared(
286286
.replace("\\\"", "\\\\\"")
287287
));
288288
all_sources.sort();
289-
let mut v = String::from("var sourcesIndex = JSON.parse('{\\\n");
289+
let mut v = String::from("var srcIndex = JSON.parse('{\\\n");
290290
v.push_str(&all_sources.join(",\\\n"));
291-
v.push_str("\\\n}');\ncreateSourceSidebar();\n");
291+
v.push_str("\\\n}');\ncreateSrcSidebar();\n");
292292
Ok(v.into_bytes())
293293
};
294-
write_invocation_specific("source-files.js", &make_sources)?;
294+
write_invocation_specific("src-files.js", &make_sources)?;
295295
}
296296

297297
// Update the search index and crate list.

‎src/librustdoc/html/static/css/rustdoc.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1562,7 +1562,7 @@ However, it's not needed with smaller screen width because the doc/code block is
15621562
/*
15631563
WARNING: RUSTDOC_MOBILE_BREAKPOINT MEDIA QUERY
15641564
If you update this line, then you also need to update the line with the same warning
1565-
in source-script.js
1565+
in src-script.js
15661566
*/
15671567
@media (max-width: 700px) {
15681568
/* When linking to an item with an `id` (for instance, by clicking a link in the sidebar,

‎src/librustdoc/html/static/js/source-script.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// From rust:
2-
/* global sourcesIndex */
2+
/* global srcIndex */
33

44
// Local js definitions:
55
/* global addClass, getCurrentValue, onEachLazy, removeClass, browserSupportsHistoryApi */
@@ -101,9 +101,9 @@ function createSidebarToggle() {
101101
return sidebarToggle;
102102
}
103103

104-
// This function is called from "source-files.js", generated in `html/render/write_shared.rs`.
104+
// This function is called from "src-files.js", generated in `html/render/write_shared.rs`.
105105
// eslint-disable-next-line no-unused-vars
106-
function createSourceSidebar() {
106+
function createSrcSidebar() {
107107
const container = document.querySelector("nav.sidebar");
108108

109109
const sidebarToggle = createSidebarToggle();
@@ -118,9 +118,9 @@ function createSourceSidebar() {
118118
title.className = "title";
119119
title.innerText = "Files";
120120
sidebar.appendChild(title);
121-
Object.keys(sourcesIndex).forEach(key => {
122-
sourcesIndex[key][NAME_OFFSET] = key;
123-
hasFoundFile = createDirEntry(sourcesIndex[key], sidebar, "", hasFoundFile);
121+
Object.keys(srcIndex).forEach(key => {
122+
srcIndex[key][NAME_OFFSET] = key;
123+
hasFoundFile = createDirEntry(srcIndex[key], sidebar, "", hasFoundFile);
124124
});
125125

126126
container.appendChild(sidebar);
@@ -133,7 +133,7 @@ function createSourceSidebar() {
133133

134134
const lineNumbersRegex = /^#?(\d+)(?:-(\d+))?$/;
135135

136-
function highlightSourceLines(match) {
136+
function highlightSrcLines(match) {
137137
if (typeof match === "undefined") {
138138
match = window.location.hash.match(lineNumbersRegex);
139139
}
@@ -172,15 +172,15 @@ function highlightSourceLines(match) {
172172
}
173173
}
174174

175-
const handleSourceHighlight = (function() {
175+
const handleSrcHighlight = (function() {
176176
let prev_line_id = 0;
177177

178178
const set_fragment = name => {
179179
const x = window.scrollX,
180180
y = window.scrollY;
181181
if (browserSupportsHistoryApi()) {
182182
history.replaceState(null, null, "#" + name);
183-
highlightSourceLines();
183+
highlightSrcLines();
184184
} else {
185185
location.replace("#" + name);
186186
}
@@ -221,15 +221,15 @@ const handleSourceHighlight = (function() {
221221
window.addEventListener("hashchange", () => {
222222
const match = window.location.hash.match(lineNumbersRegex);
223223
if (match) {
224-
return highlightSourceLines(match);
224+
return highlightSrcLines(match);
225225
}
226226
});
227227

228228
onEachLazy(document.getElementsByClassName("src-line-numbers"), el => {
229-
el.addEventListener("click", handleSourceHighlight);
229+
el.addEventListener("click", handleSrcHighlight);
230230
});
231231

232-
highlightSourceLines();
232+
highlightSrcLines();
233233

234-
window.createSourceSidebar = createSourceSidebar;
234+
window.createSrcSidebar = createSrcSidebar;
235235
})();

‎src/librustdoc/html/static_files.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ static_files! {
9797
main_js => "static/js/main.js",
9898
search_js => "static/js/search.js",
9999
settings_js => "static/js/settings.js",
100-
source_script_js => "static/js/source-script.js",
100+
src_script_js => "static/js/src-script.js",
101101
storage_js => "static/js/storage.js",
102102
scrape_examples_js => "static/js/scrape-examples.js",
103103
wheel_svg => "static/images/wheel.svg",

‎src/librustdoc/html/templates/page.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@
4343
{% if page.css_class.contains("crate") %}
4444
<script defer src="{{page.root_path|safe}}crates{{page.resource_suffix}}.js"></script> {# #}
4545
{% else if page.css_class == "src" %}
46-
<script defer src="{{static_root_path|safe}}{{files.source_script_js}}"></script> {# #}
47-
<script defer src="{{page.root_path|safe}}source-files{{page.resource_suffix}}.js"></script> {# #}
46+
<script defer src="{{static_root_path|safe}}{{files.src_script_js}}"></script> {# #}
47+
<script defer src="{{page.root_path|safe}}src-files{{page.resource_suffix}}.js"></script> {# #}
4848
{% else if !page.css_class.contains("mod") %}
4949
<script defer src="sidebar-items{{page.resource_suffix}}.js"></script> {# #}
5050
{% endif %}

‎tests/rustdoc/source-file.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#![crate_name = "foo"]
22

3-
// @hasraw source-files.js source-file.rs
3+
// @hasraw src-files.js source-file.rs
44

55
pub struct Foo;

‎tests/rustdoc/static-root-path.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
pub struct SomeStruct;
99

1010
// @has src/static_root_path/static-root-path.rs.html
11-
// @matchesraw - '"/cache/source-script-'
12-
// @!matchesraw - '"\.\./\.\./source-script'
13-
// @matchesraw - '"\.\./\.\./source-files.js"'
14-
// @!matchesraw - '"/cache/source-files\.js"'
11+
// @matchesraw - '"/cache/src-script-'
12+
// @!matchesraw - '"\.\./\.\./src-script'
13+
// @matchesraw - '"\.\./\.\./src-files.js"'
14+
// @!matchesraw - '"/cache/src-files\.js"'
1515

1616
// @has settings.html
1717
// @matchesraw - '/cache/settings-'

0 commit comments

Comments
 (0)
Please sign in to comment.