Rollup merge of #59890 - GuillaumeGomez:empty-json-variables, r=QuietMisdreavus
Don't generate empty json variables r? @rust-lang/rustdoc
This commit is contained in:
commit
426ab8e018
2 changed files with 34 additions and 19 deletions
|
@ -1064,11 +1064,22 @@ themePicker.onblur = handleThemeButtonsBlur;
|
||||||
.expect("invalid osstring conversion")))
|
.expect("invalid osstring conversion")))
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
files.sort_unstable_by(|a, b| a.cmp(b));
|
files.sort_unstable_by(|a, b| a.cmp(b));
|
||||||
// FIXME(imperio): we could avoid to generate "dirs" and "files" if they're empty.
|
let subs = subs.iter().map(|s| s.to_json_string()).collect::<Vec<_>>().join(",");
|
||||||
format!("{{\"name\":\"{name}\",\"dirs\":[{subs}],\"files\":[{files}]}}",
|
let dirs = if subs.is_empty() {
|
||||||
|
String::new()
|
||||||
|
} else {
|
||||||
|
format!(",\"dirs\":[{}]", subs)
|
||||||
|
};
|
||||||
|
let files = files.join(",");
|
||||||
|
let files = if files.is_empty() {
|
||||||
|
String::new()
|
||||||
|
} else {
|
||||||
|
format!(",\"files\":[{}]", files)
|
||||||
|
};
|
||||||
|
format!("{{\"name\":\"{name}\"{dirs}{files}}}",
|
||||||
name=self.elem.to_str().expect("invalid osstring conversion"),
|
name=self.elem.to_str().expect("invalid osstring conversion"),
|
||||||
subs=subs.iter().map(|s| s.to_json_string()).collect::<Vec<_>>().join(","),
|
dirs=dirs,
|
||||||
files=files.join(","))
|
files=files)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -39,28 +39,32 @@ function createDirEntry(elem, parent, fullPath, currentFile, hasFoundFile) {
|
||||||
children.className = "children";
|
children.className = "children";
|
||||||
var folders = document.createElement("div");
|
var folders = document.createElement("div");
|
||||||
folders.className = "folders";
|
folders.className = "folders";
|
||||||
for (var i = 0; i < elem.dirs.length; ++i) {
|
if (elem.dirs) {
|
||||||
if (createDirEntry(elem.dirs[i], folders, fullPath, currentFile,
|
for (var i = 0; i < elem.dirs.length; ++i) {
|
||||||
hasFoundFile) === true) {
|
if (createDirEntry(elem.dirs[i], folders, fullPath, currentFile,
|
||||||
addClass(name, "expand");
|
hasFoundFile) === true) {
|
||||||
hasFoundFile = true;
|
addClass(name, "expand");
|
||||||
|
hasFoundFile = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
children.appendChild(folders);
|
children.appendChild(folders);
|
||||||
|
|
||||||
var files = document.createElement("div");
|
var files = document.createElement("div");
|
||||||
files.className = "files";
|
files.className = "files";
|
||||||
for (i = 0; i < elem.files.length; ++i) {
|
if (elem.files) {
|
||||||
var file = document.createElement("a");
|
for (i = 0; i < elem.files.length; ++i) {
|
||||||
file.innerText = elem.files[i];
|
var file = document.createElement("a");
|
||||||
file.href = window.rootPath + "src/" + fullPath + elem.files[i] + ".html";
|
file.innerText = elem.files[i];
|
||||||
if (hasFoundFile === false &&
|
file.href = window.rootPath + "src/" + fullPath + elem.files[i] + ".html";
|
||||||
currentFile === fullPath + elem.files[i]) {
|
if (hasFoundFile === false &&
|
||||||
file.className = "selected";
|
currentFile === fullPath + elem.files[i]) {
|
||||||
addClass(name, "expand");
|
file.className = "selected";
|
||||||
hasFoundFile = true;
|
addClass(name, "expand");
|
||||||
|
hasFoundFile = true;
|
||||||
|
}
|
||||||
|
files.appendChild(file);
|
||||||
}
|
}
|
||||||
files.appendChild(file);
|
|
||||||
}
|
}
|
||||||
search.fullPath = fullPath;
|
search.fullPath = fullPath;
|
||||||
children.appendChild(files);
|
children.appendChild(files);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue