rustdoc: Get rid of allPaths
global variable by merging it into searchIndex
.
This commit is contained in:
parent
f6854ab46c
commit
9eb336a020
2 changed files with 34 additions and 19 deletions
|
@ -308,7 +308,7 @@ pub fn run(mut krate: clean::Crate, dst: Path) -> io::IoResult<()> {
|
||||||
// Publish the search index
|
// Publish the search index
|
||||||
let index = {
|
let index = {
|
||||||
let mut w = MemWriter::new();
|
let mut w = MemWriter::new();
|
||||||
try!(write!(&mut w, "searchIndex['{}'] = [", krate.name));
|
try!(write!(&mut w, r#"searchIndex['{}'] = \{"items":["#, krate.name));
|
||||||
for (i, item) in cache.search_index.iter().enumerate() {
|
for (i, item) in cache.search_index.iter().enumerate() {
|
||||||
if i > 0 {
|
if i > 0 {
|
||||||
try!(write!(&mut w, ","));
|
try!(write!(&mut w, ","));
|
||||||
|
@ -325,8 +325,7 @@ pub fn run(mut krate: clean::Crate, dst: Path) -> io::IoResult<()> {
|
||||||
}
|
}
|
||||||
try!(write!(&mut w, "]"));
|
try!(write!(&mut w, "]"));
|
||||||
}
|
}
|
||||||
try!(write!(&mut w, "];"));
|
try!(write!(&mut w, r#"],"paths":["#));
|
||||||
try!(write!(&mut w, "allPaths['{}'] = [", krate.name));
|
|
||||||
for (i, &nodeid) in pathid_to_nodeid.iter().enumerate() {
|
for (i, &nodeid) in pathid_to_nodeid.iter().enumerate() {
|
||||||
let &(ref fqp, short) = cache.paths.find(&nodeid).unwrap();
|
let &(ref fqp, short) = cache.paths.find(&nodeid).unwrap();
|
||||||
if i > 0 {
|
if i > 0 {
|
||||||
|
@ -335,7 +334,7 @@ pub fn run(mut krate: clean::Crate, dst: Path) -> io::IoResult<()> {
|
||||||
try!(write!(&mut w, r#"[{:u},"{}"]"#,
|
try!(write!(&mut w, r#"[{:u},"{}"]"#,
|
||||||
short, *fqp.last().unwrap()));
|
short, *fqp.last().unwrap()));
|
||||||
}
|
}
|
||||||
try!(write!(&mut w, "];"));
|
try!(write!(&mut w, r"]\};"));
|
||||||
|
|
||||||
str::from_utf8(w.unwrap().as_slice()).unwrap().to_owned()
|
str::from_utf8(w.unwrap().as_slice()).unwrap().to_owned()
|
||||||
};
|
};
|
||||||
|
@ -371,7 +370,7 @@ pub fn run(mut krate: clean::Crate, dst: Path) -> io::IoResult<()> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let mut w = try!(File::create(&dst));
|
let mut w = try!(File::create(&dst));
|
||||||
try!(writeln!(&mut w, r"var searchIndex = \{\}; var allPaths = \{\};"));
|
try!(writeln!(&mut w, r"var searchIndex = \{\};"));
|
||||||
for index in all_indexes.iter() {
|
for index in all_indexes.iter() {
|
||||||
try!(writeln!(&mut w, "{}", *index));
|
try!(writeln!(&mut w, "{}", *index));
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
/*jslint browser: true, es5: true */
|
/*jslint browser: true, es5: true */
|
||||||
/*globals $: true, rootPath: true, allPaths: true */
|
/*globals $: true, rootPath: true */
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
@ -258,7 +258,7 @@
|
||||||
var result = results[i],
|
var result = results[i],
|
||||||
name = result.item.name.toLowerCase(),
|
name = result.item.name.toLowerCase(),
|
||||||
path = result.item.path.toLowerCase(),
|
path = result.item.path.toLowerCase(),
|
||||||
parent = allPaths[result.item.crate][result.item.parent];
|
parent = result.item.parent;
|
||||||
|
|
||||||
var valid = validateResult(name, path, split, parent);
|
var valid = validateResult(name, path, split, parent);
|
||||||
if (!valid) {
|
if (!valid) {
|
||||||
|
@ -294,7 +294,7 @@
|
||||||
if ((validate) &&
|
if ((validate) &&
|
||||||
(name.toLowerCase().indexOf(keys[i]) > -1 ||
|
(name.toLowerCase().indexOf(keys[i]) > -1 ||
|
||||||
path.toLowerCase().indexOf(keys[i]) > -1 ||
|
path.toLowerCase().indexOf(keys[i]) > -1 ||
|
||||||
parent[1].toLowerCase().indexOf(keys[i]) > -1))
|
parent.name.toLowerCase().indexOf(keys[i]) > -1))
|
||||||
{
|
{
|
||||||
validate = true;
|
validate = true;
|
||||||
} else {
|
} else {
|
||||||
|
@ -422,15 +422,13 @@
|
||||||
'/index.html" class="' + type +
|
'/index.html" class="' + type +
|
||||||
'">' + name + '</a>';
|
'">' + name + '</a>';
|
||||||
} else if (item.parent !== undefined) {
|
} else if (item.parent !== undefined) {
|
||||||
var myparent = allPaths[item.crate][item.parent];
|
var myparent = item.parent;
|
||||||
var parentType = myparent[0];
|
|
||||||
var parentName = myparent[1];
|
|
||||||
var anchor = '#' + type + '.' + name;
|
var anchor = '#' + type + '.' + name;
|
||||||
output += item.path + '::' + parentName +
|
output += item.path + '::' + myparent.name +
|
||||||
'::<a href="' + rootPath +
|
'::<a href="' + rootPath +
|
||||||
item.path.replace(/::/g, '/') +
|
item.path.replace(/::/g, '/') +
|
||||||
'/' + itemTypes[parentType] +
|
'/' + itemTypes[myparent.ty] +
|
||||||
'.' + parentName +
|
'.' + myparent.name +
|
||||||
'.html' + anchor +
|
'.html' + anchor +
|
||||||
'" class="' + type +
|
'" class="' + type +
|
||||||
'">' + name + '</a>';
|
'">' + name + '</a>';
|
||||||
|
@ -538,18 +536,36 @@
|
||||||
var searchWords = [];
|
var searchWords = [];
|
||||||
for (var crate in rawSearchIndex) {
|
for (var crate in rawSearchIndex) {
|
||||||
if (!rawSearchIndex.hasOwnProperty(crate)) { continue }
|
if (!rawSearchIndex.hasOwnProperty(crate)) { continue }
|
||||||
var len = rawSearchIndex[crate].length;
|
|
||||||
var i = 0;
|
|
||||||
|
|
||||||
|
// an array of [(Number) item type,
|
||||||
|
// (String) name,
|
||||||
|
// (String) full path,
|
||||||
|
// (String) description,
|
||||||
|
// (optional Number) the parent path index to `paths`]
|
||||||
|
var items = rawSearchIndex[crate].items;
|
||||||
|
// an array of [(Number) item type,
|
||||||
|
// (String) name]
|
||||||
|
var paths = rawSearchIndex[crate].paths;
|
||||||
|
|
||||||
|
// convert `paths` into an object form
|
||||||
|
var len = paths.length;
|
||||||
|
for (var i = 0; i < len; ++i) {
|
||||||
|
paths[i] = {ty: paths[i][0], name: paths[i][1]};
|
||||||
|
}
|
||||||
|
|
||||||
|
// convert `items` into an object form, and construct word indices.
|
||||||
|
//
|
||||||
// before any analysis is performed lets gather the search terms to
|
// before any analysis is performed lets gather the search terms to
|
||||||
// search against apart from the rest of the data. This is a quick
|
// search against apart from the rest of the data. This is a quick
|
||||||
// operation that is cached for the life of the page state so that
|
// operation that is cached for the life of the page state so that
|
||||||
// all other search operations have access to this cached data for
|
// all other search operations have access to this cached data for
|
||||||
// faster analysis operations
|
// faster analysis operations
|
||||||
for (i = 0; i < len; i += 1) {
|
var len = items.length;
|
||||||
var rawRow = rawSearchIndex[crate][i];
|
for (var i = 0; i < len; i += 1) {
|
||||||
|
var rawRow = items[i];
|
||||||
var row = {crate: crate, ty: rawRow[0], name: rawRow[1],
|
var row = {crate: crate, ty: rawRow[0], name: rawRow[1],
|
||||||
path: rawRow[2], desc: rawRow[3], parent: rawRow[4]};
|
path: rawRow[2], desc: rawRow[3],
|
||||||
|
parent: paths[rawRow[4]]};
|
||||||
searchIndex.push(row);
|
searchIndex.push(row);
|
||||||
if (typeof row.name === "string") {
|
if (typeof row.name === "string") {
|
||||||
var word = row.name.toLowerCase();
|
var word = row.name.toLowerCase();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue