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.
This commit is contained in:
Michael Howell 2023-07-14 16:46:46 -07:00
parent 34bc8fbea3
commit e72fba4160
7 changed files with 26 additions and 26 deletions

View File

@ -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.

View File

@ -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,

View File

@ -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;
})();

View File

@ -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",

View File

@ -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 %}

View File

@ -1,5 +1,5 @@
#![crate_name = "foo"]
// @hasraw source-files.js source-file.rs
// @hasraw src-files.js source-file.rs
pub struct Foo;

View File

@ -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-'