rustdoc: Get rid of allPaths global variable by merging it into searchIndex.

This commit is contained in:
Kang Seonghoon 2014-04-10 01:27:35 +09:00
parent f6854ab46c
commit 9eb336a020
2 changed files with 34 additions and 19 deletions

View File

@ -308,7 +308,7 @@ pub fn run(mut krate: clean::Crate, dst: Path) -> io::IoResult<()> {
// Publish the search index
let index = {
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() {
if i > 0 {
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, "allPaths['{}'] = [", krate.name));
try!(write!(&mut w, r#"],"paths":["#));
for (i, &nodeid) in pathid_to_nodeid.iter().enumerate() {
let &(ref fqp, short) = cache.paths.find(&nodeid).unwrap();
if i > 0 {
@ -335,7 +334,7 @@ pub fn run(mut krate: clean::Crate, dst: Path) -> io::IoResult<()> {
try!(write!(&mut w, r#"[{:u},"{}"]"#,
short, *fqp.last().unwrap()));
}
try!(write!(&mut w, "];"));
try!(write!(&mut w, r"]\};"));
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));
try!(writeln!(&mut w, r"var searchIndex = \{\}; var allPaths = \{\};"));
try!(writeln!(&mut w, r"var searchIndex = \{\};"));
for index in all_indexes.iter() {
try!(writeln!(&mut w, "{}", *index));
}

View File

@ -9,7 +9,7 @@
// except according to those terms.
/*jslint browser: true, es5: true */
/*globals $: true, rootPath: true, allPaths: true */
/*globals $: true, rootPath: true */
(function() {
"use strict";
@ -258,7 +258,7 @@
var result = results[i],
name = result.item.name.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);
if (!valid) {
@ -294,7 +294,7 @@
if ((validate) &&
(name.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;
} else {
@ -422,15 +422,13 @@
'/index.html" class="' + type +
'">' + name + '</a>';
} else if (item.parent !== undefined) {
var myparent = allPaths[item.crate][item.parent];
var parentType = myparent[0];
var parentName = myparent[1];
var myparent = item.parent;
var anchor = '#' + type + '.' + name;
output += item.path + '::' + parentName +
output += item.path + '::' + myparent.name +
'::<a href="' + rootPath +
item.path.replace(/::/g, '/') +
'/' + itemTypes[parentType] +
'.' + parentName +
'/' + itemTypes[myparent.ty] +
'.' + myparent.name +
'.html' + anchor +
'" class="' + type +
'">' + name + '</a>';
@ -538,18 +536,36 @@
var searchWords = [];
for (var crate in rawSearchIndex) {
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
// 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
// all other search operations have access to this cached data for
// faster analysis operations
for (i = 0; i < len; i += 1) {
var rawRow = rawSearchIndex[crate][i];
var len = items.length;
for (var i = 0; i < len; i += 1) {
var rawRow = items[i];
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);
if (typeof row.name === "string") {
var word = row.name.toLowerCase();