OLD | NEW |
1 /** | 1 /** |
2 * @fileoverview This file is the controller for generating extension | 2 * @fileoverview This file is the controller for generating extension |
3 * doc pages. | 3 * doc pages. |
4 * | 4 * |
5 * It expects to have available via XHR (relative path): | 5 * It expects to have available via XHR (relative path): |
6 * 1) API_TEMPLATE which is the main template for the api pages. | 6 * 1) API_TEMPLATE which is the main template for the api pages. |
7 * 2) A file located at SCHEMA which is shared with the extension system and | 7 * 2) A file located at SCHEMA which is shared with the extension system and |
8 * defines the methods and events contained in one api. | 8 * defines the methods and events contained in one api. |
9 * 3) (Possibly) A static version of the current page url in /static/. I.e. | 9 * 3) (Possibly) A static version of the current page url in /static/. I.e. |
10 * if called as ../foo.html, it will look for ../static/foo.html. | 10 * if called as ../foo.html, it will look for ../static/foo.html. |
(...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
374 lastH2 = dataNode; | 374 lastH2 = dataNode; |
375 lastH2.children = []; | 375 lastH2.children = []; |
376 } else { | 376 } else { |
377 lastH2.children.push(dataNode); | 377 lastH2.children.push(dataNode); |
378 } | 378 } |
379 }); | 379 }); |
380 | 380 |
381 return retval; | 381 return retval; |
382 } | 382 } |
383 | 383 |
| 384 // This function looks in the description for strings of the form |
| 385 // "$ref:TYPE_ID" (where TYPE_ID is something like "Tab" or "HistoryItem") and |
| 386 // substitutes a link to the documentation for that type. |
| 387 function substituteTypeRefs(description) { |
| 388 var regexp = /\$ref\:\w+/g; |
| 389 var matches = description.match(regexp); |
| 390 if (!matches) { |
| 391 return description; |
| 392 } |
| 393 var result = description; |
| 394 for (var i = 0; i < matches.length; i++) { |
| 395 var type = matches[i].split(":")[1]; |
| 396 var page = null; |
| 397 try { |
| 398 page = getTypeRefPage({"$ref": type}); |
| 399 } catch (error) { |
| 400 console.log("substituteTypeRefs couldn't find page for type " + type); |
| 401 continue; |
| 402 } |
| 403 var replacement = "<a href='" + page + "#type-" + type + "'>" + type + |
| 404 "</a>"; |
| 405 result = result.replace(matches[i], replacement); |
| 406 } |
| 407 |
| 408 return result; |
| 409 } |
| 410 |
384 function getTypeRefPage(type) { | 411 function getTypeRefPage(type) { |
385 return typeModule[type.$ref].namespace + ".html"; | 412 return typeModule[type.$ref].namespace + ".html"; |
386 } | 413 } |
387 | 414 |
388 function getPageName() { | 415 function getPageName() { |
389 var pageDataName = getDataFromPageHTML("pageData-name"); | 416 var pageDataName = getDataFromPageHTML("pageData-name"); |
390 // Allow empty string to be explitly set via pageData. | 417 // Allow empty string to be explitly set via pageData. |
391 if (pageDataName == "") { | 418 if (pageDataName == "") { |
392 return pageDataName; | 419 return pageDataName; |
393 } | 420 } |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
474 | 501 |
475 function sortByName(a, b) { | 502 function sortByName(a, b) { |
476 if (a.name < b.name) { | 503 if (a.name < b.name) { |
477 return -1; | 504 return -1; |
478 } | 505 } |
479 if (a.name > b.name) { | 506 if (a.name > b.name) { |
480 return 1; | 507 return 1; |
481 } | 508 } |
482 return 0; | 509 return 0; |
483 } | 510 } |
OLD | NEW |