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 20 matching lines...) Expand all Loading... |
31 | 31 |
32 // The current module for this page (if this page is an api module); | 32 // The current module for this page (if this page is an api module); |
33 var module; | 33 var module; |
34 | 34 |
35 // Mapping from typeId to module. | 35 // Mapping from typeId to module. |
36 var typeModule = {}; | 36 var typeModule = {}; |
37 | 37 |
38 // Auto-created page name as default | 38 // Auto-created page name as default |
39 var pageName; | 39 var pageName; |
40 | 40 |
41 // If this page is an apiModule, the title of the api module | 41 // If this page is an apiModule, the name of the api module |
42 var apiModuleTitle; | 42 var apiModuleName; |
43 | 43 |
44 Array.prototype.each = function(f) { | 44 Array.prototype.each = function(f) { |
45 for (var i = 0; i < this.length; i++) { | 45 for (var i = 0; i < this.length; i++) { |
46 f(this[i], i); | 46 f(this[i], i); |
47 } | 47 } |
48 } | 48 } |
49 | 49 |
50 // Visits each item in the list in-order. Stops when f returns any truthy | 50 // Visits each item in the list in-order. Stops when f returns any truthy |
51 // value and returns that node. | 51 // value and returns that node. |
52 Array.prototype.select = function(f) { | 52 Array.prototype.select = function(f) { |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 console.error("exception: " + e); | 164 console.error("exception: " + e); |
165 handleError(); | 165 handleError(); |
166 } | 166 } |
167 } | 167 } |
168 | 168 |
169 function renderTemplate() { | 169 function renderTemplate() { |
170 schema.each(function(mod) { | 170 schema.each(function(mod) { |
171 if (mod.namespace == pageBase) { | 171 if (mod.namespace == pageBase) { |
172 // This page is an api page. Setup types and apiDefinition. | 172 // This page is an api page. Setup types and apiDefinition. |
173 module = mod; | 173 module = mod; |
174 apiModuleTitle = "chrome." + module.namespace; | 174 apiModuleName = "chrome." + module.namespace; |
175 pageData.apiDefinition = module; | 175 pageData.apiDefinition = module; |
176 } | 176 } |
177 | 177 |
178 if (mod.types) { | 178 if (mod.types) { |
179 mod.types.each(function(type) { | 179 mod.types.each(function(type) { |
180 typeModule[type.id] = mod; | 180 typeModule[type.id] = mod; |
181 }); | 181 }); |
182 } | 182 } |
183 }); | 183 }); |
184 | 184 |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
310 } | 310 } |
311 }); | 311 }); |
312 | 312 |
313 return retval; | 313 return retval; |
314 } | 314 } |
315 | 315 |
316 function getTypeRefPage(type) { | 316 function getTypeRefPage(type) { |
317 return typeModule[type.$ref].namespace + ".html"; | 317 return typeModule[type.$ref].namespace + ".html"; |
318 } | 318 } |
319 | 319 |
| 320 function getPageName() { |
| 321 var pageDataName = getDataFromPageHTML("pageData-name"); |
| 322 // Allow empty string to be explitly set via pageData. |
| 323 if (pageDataName == "") { |
| 324 return pageDataName; |
| 325 } |
| 326 |
| 327 return pageDataName || apiModuleName || pageName; |
| 328 } |
| 329 |
320 function getPageTitle() { | 330 function getPageTitle() { |
| 331 var pageName = getPageName(); |
321 var pageTitleSuffix = "Google Chrome Extensions - Google Code"; | 332 var pageTitleSuffix = "Google Chrome Extensions - Google Code"; |
322 var pageDataTitle = getDataFromPageHTML("pageData-title"); | 333 if (pageName == "") { |
323 // Allows an emptry string to be set as the title from pageData. | |
324 if (pageDataTitle == "") { | |
325 return pageTitleSuffix; | 334 return pageTitleSuffix; |
326 } | 335 } |
327 | 336 |
328 return (pageDataTitle || apiModuleTitle || pageName) + | 337 return pageName + " - " + pageTitleSuffix; |
329 " - " + pageTitleSuffix; | |
330 } | 338 } |
331 | 339 |
332 function getModuleName() { | 340 function getModuleName() { |
333 return "chrome." + module.namespace; | 341 return "chrome." + module.namespace; |
334 } | 342 } |
335 | 343 |
336 function getFullyQualifiedFunctionName(func) { | 344 function getFullyQualifiedFunctionName(func) { |
337 return getModuleName() + "." + func.name; | 345 return getModuleName() + "." + func.name; |
338 } | 346 } |
339 | 347 |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
393 | 401 |
394 function sortByName(a, b) { | 402 function sortByName(a, b) { |
395 if (a.name < b.name) { | 403 if (a.name < b.name) { |
396 return -1; | 404 return -1; |
397 } | 405 } |
398 if (a.name > b.name) { | 406 if (a.name > b.name) { |
399 return 1; | 407 return 1; |
400 } | 408 } |
401 return 0; | 409 return 0; |
402 } | 410 } |
OLD | NEW |