1
Fork 0

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); hierarchy.add_path(source);
} }
let hierarchy = Rc::try_unwrap(hierarchy).unwrap(); 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 make_sources = || {
let (mut all_sources, _krates) = let (mut all_sources, _krates) =
try_err!(collect_json(&dst, krate.name(cx.tcx()).as_str()), &dst); try_err!(collect_json(&dst, krate.name(cx.tcx()).as_str()), &dst);
@ -286,12 +286,12 @@ pub(super) fn write_shared(
.replace("\\\"", "\\\\\"") .replace("\\\"", "\\\\\"")
)); ));
all_sources.sort(); 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(&all_sources.join(",\\\n"));
v.push_str("\\\n}');\ncreateSourceSidebar();\n"); v.push_str("\\\n}');\ncreateSrcSidebar();\n");
Ok(v.into_bytes()) 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. // 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 WARNING: RUSTDOC_MOBILE_BREAKPOINT MEDIA QUERY
If you update this line, then you also need to update the line with the same warning 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) { @media (max-width: 700px) {
/* When linking to an item with an `id` (for instance, by clicking a link in the sidebar, /* 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: // From rust:
/* global sourcesIndex */ /* global srcIndex */
// Local js definitions: // Local js definitions:
/* global addClass, getCurrentValue, onEachLazy, removeClass, browserSupportsHistoryApi */ /* global addClass, getCurrentValue, onEachLazy, removeClass, browserSupportsHistoryApi */
@ -101,9 +101,9 @@ function createSidebarToggle() {
return sidebarToggle; 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 // eslint-disable-next-line no-unused-vars
function createSourceSidebar() { function createSrcSidebar() {
const container = document.querySelector("nav.sidebar"); const container = document.querySelector("nav.sidebar");
const sidebarToggle = createSidebarToggle(); const sidebarToggle = createSidebarToggle();
@ -118,9 +118,9 @@ function createSourceSidebar() {
title.className = "title"; title.className = "title";
title.innerText = "Files"; title.innerText = "Files";
sidebar.appendChild(title); sidebar.appendChild(title);
Object.keys(sourcesIndex).forEach(key => { Object.keys(srcIndex).forEach(key => {
sourcesIndex[key][NAME_OFFSET] = key; srcIndex[key][NAME_OFFSET] = key;
hasFoundFile = createDirEntry(sourcesIndex[key], sidebar, "", hasFoundFile); hasFoundFile = createDirEntry(srcIndex[key], sidebar, "", hasFoundFile);
}); });
container.appendChild(sidebar); container.appendChild(sidebar);
@ -133,7 +133,7 @@ function createSourceSidebar() {
const lineNumbersRegex = /^#?(\d+)(?:-(\d+))?$/; const lineNumbersRegex = /^#?(\d+)(?:-(\d+))?$/;
function highlightSourceLines(match) { function highlightSrcLines(match) {
if (typeof match === "undefined") { if (typeof match === "undefined") {
match = window.location.hash.match(lineNumbersRegex); match = window.location.hash.match(lineNumbersRegex);
} }
@ -172,7 +172,7 @@ function highlightSourceLines(match) {
} }
} }
const handleSourceHighlight = (function() { const handleSrcHighlight = (function() {
let prev_line_id = 0; let prev_line_id = 0;
const set_fragment = name => { const set_fragment = name => {
@ -180,7 +180,7 @@ const handleSourceHighlight = (function() {
y = window.scrollY; y = window.scrollY;
if (browserSupportsHistoryApi()) { if (browserSupportsHistoryApi()) {
history.replaceState(null, null, "#" + name); history.replaceState(null, null, "#" + name);
highlightSourceLines(); highlightSrcLines();
} else { } else {
location.replace("#" + name); location.replace("#" + name);
} }
@ -221,15 +221,15 @@ const handleSourceHighlight = (function() {
window.addEventListener("hashchange", () => { window.addEventListener("hashchange", () => {
const match = window.location.hash.match(lineNumbersRegex); const match = window.location.hash.match(lineNumbersRegex);
if (match) { if (match) {
return highlightSourceLines(match); return highlightSrcLines(match);
} }
}); });
onEachLazy(document.getElementsByClassName("src-line-numbers"), el => { 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", main_js => "static/js/main.js",
search_js => "static/js/search.js", search_js => "static/js/search.js",
settings_js => "static/js/settings.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", storage_js => "static/js/storage.js",
scrape_examples_js => "static/js/scrape-examples.js", scrape_examples_js => "static/js/scrape-examples.js",
wheel_svg => "static/images/wheel.svg", wheel_svg => "static/images/wheel.svg",

View file

@ -43,8 +43,8 @@
{% if page.css_class.contains("crate") %} {% if page.css_class.contains("crate") %}
<script defer src="{{page.root_path|safe}}crates{{page.resource_suffix}}.js"></script> {# #} <script defer src="{{page.root_path|safe}}crates{{page.resource_suffix}}.js"></script> {# #}
{% else if page.css_class == "src" %} {% else if page.css_class == "src" %}
<script defer src="{{static_root_path|safe}}{{files.source_script_js}}"></script> {# #} <script defer src="{{static_root_path|safe}}{{files.src_script_js}}"></script> {# #}
<script defer src="{{page.root_path|safe}}source-files{{page.resource_suffix}}.js"></script> {# #} <script defer src="{{page.root_path|safe}}src-files{{page.resource_suffix}}.js"></script> {# #}
{% else if !page.css_class.contains("mod") %} {% else if !page.css_class.contains("mod") %}
<script defer src="sidebar-items{{page.resource_suffix}}.js"></script> {# #} <script defer src="sidebar-items{{page.resource_suffix}}.js"></script> {# #}
{% endif %} {% endif %}

View file

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

View file

@ -8,10 +8,10 @@
pub struct SomeStruct; pub struct SomeStruct;
// @has src/static_root_path/static-root-path.rs.html // @has src/static_root_path/static-root-path.rs.html
// @matchesraw - '"/cache/source-script-' // @matchesraw - '"/cache/src-script-'
// @!matchesraw - '"\.\./\.\./source-script' // @!matchesraw - '"\.\./\.\./src-script'
// @matchesraw - '"\.\./\.\./source-files.js"' // @matchesraw - '"\.\./\.\./src-files.js"'
// @!matchesraw - '"/cache/source-files\.js"' // @!matchesraw - '"/cache/src-files\.js"'
// @has settings.html // @has settings.html
// @matchesraw - '/cache/settings-' // @matchesraw - '/cache/settings-'