Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(20)

Side by Side Diff: chrome/common/extensions/docs/js/api_page_generator.js

Issue 398005: Changes to follow the codesite L&F.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 11 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/common/extensions/docs/index.html ('k') | chrome/common/extensions/docs/manifest.html » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 * It will insert the static content, if any, prepare it's pageData then 77 * It will insert the static content, if any, prepare it's pageData then
78 * render the template from |pageData|. 78 * render the template from |pageData|.
79 */ 79 */
80 function renderPage() { 80 function renderPage() {
81 var pathParts = document.location.href.split(/\/|\./); 81 var pathParts = document.location.href.split(/\/|\./);
82 pageBase = pathParts[pathParts.length - 2]; 82 pageBase = pathParts[pathParts.length - 2];
83 if (!pageBase) { 83 if (!pageBase) {
84 alert("Empty page name for: " + document.location.href); 84 alert("Empty page name for: " + document.location.href);
85 return; 85 return;
86 } 86 }
87 87
88 pageName = pageBase.replace(/([A-Z])/g, " $1"); 88 pageName = pageBase.replace(/([A-Z])/g, " $1");
89 pageName = pageName.substring(0, 1).toUpperCase() + pageName.substring(1); 89 pageName = pageName.substring(0, 1).toUpperCase() + pageName.substring(1);
90 90
91 // Fetch the api template and insert into the <body>. 91 // Fetch the api template and insert into the <body>.
92 fetchContent(API_TEMPLATE, function(templateContent) { 92 fetchContent(API_TEMPLATE, function(templateContent) {
93 document.getElementsByTagName("body")[0].innerHTML = templateContent; 93 document.getElementsByTagName("body")[0].innerHTML = templateContent;
94 fetchStatic(); 94 fetchStatic();
95 }, function(error) { 95 }, function(error) {
96 alert("Failed to load " + API_TEMPLATE + ". " + error); 96 alert("Failed to load " + API_TEMPLATE + ". " + error);
97 });» 97 });
98 } 98 }
99 99
100 function fetchStatic() { 100 function fetchStatic() {
101 // Fetch the static content and insert into the "static" <div>. 101 // Fetch the static content and insert into the "static" <div>.
102 fetchContent(staticResource(pageBase), function(overviewContent) { 102 fetchContent(staticResource(pageBase), function(overviewContent) {
103 document.getElementById("static").innerHTML = overviewContent; 103 document.getElementById("static").innerHTML = overviewContent;
104 fetchSchema(); 104 fetchSchema();
105 105
106 }, function(error) { 106 }, function(error) {
107 // Not fatal. Some api pages may not have matching static content. 107 // Not fatal. Some api pages may not have matching static content.
108 fetchSchema(); 108 fetchSchema();
109 }); 109 });
110 } 110 }
111 111
112 function fetchSchema() { 112 function fetchSchema() {
113 // Now the page is composed with the authored content, we fetch the schema 113 // Now the page is composed with the authored content, we fetch the schema
114 // and populate the templates. 114 // and populate the templates.
115 fetchContent(SCHEMA, function(schemaContent) { 115 fetchContent(SCHEMA, function(schemaContent) {
116 schema = JSON.parse(schemaContent); 116 schema = JSON.parse(schemaContent);
117 renderTemplate(); 117 renderTemplate();
118 118
119 }, function(error) { 119 }, function(error) {
120 alert("Failed to load " + SCHEMA); 120 alert("Failed to load " + SCHEMA);
121 }); 121 });
122 } 122 }
123 123
124 /** 124 /**
125 * Fetches |url| and returns it's text contents from the xhr.responseText in 125 * Fetches |url| and returns it's text contents from the xhr.responseText in
126 * onSuccess(content) 126 * onSuccess(content)
127 */ 127 */
128 function fetchContent(url, onSuccess, onError) { 128 function fetchContent(url, onSuccess, onError) {
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 apiModuleTitle = "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
185 // Render to template 185 // Render to template
186 var input = new JsEvalContext(pageData); 186 var input = new JsEvalContext(pageData);
187 var output = document.getElementsByTagName("body")[0]; 187 var output = document.getElementsByTagName("body")[0];
188 jstProcess(input, output); 188 jstProcess(input, output);
189 189
190 selectCurrentPageOnLeftNav(); 190 selectCurrentPageOnLeftNav();
191 191
192 document.title = getPageTitle(); 192 document.title = getPageTitle();
193 // Show 193 // Show
194 if (window.postRender) 194 if (window.postRender)
195 window.postRender(); 195 window.postRender();
196 196
197 if (parent && parent.done) 197 if (parent && parent.done)
198 parent.done(); 198 parent.done();
199 } 199 }
200 200
201 function removeJsTemplateAttributes(root) { 201 function removeJsTemplateAttributes(root) {
(...skipping 16 matching lines...) Expand all
218 return s.serializeToString(document); 218 return s.serializeToString(document);
219 } 219 }
220 220
221 function evalXPathFromNode(expression, node) { 221 function evalXPathFromNode(expression, node) {
222 var results = document.evaluate(expression, node, null, 222 var results = document.evaluate(expression, node, null,
223 XPathResult.ORDERED_NODE_ITERATOR_TYPE, null); 223 XPathResult.ORDERED_NODE_ITERATOR_TYPE, null);
224 var retval = []; 224 var retval = [];
225 while(n = results.iterateNext()) { 225 while(n = results.iterateNext()) {
226 retval.push(n); 226 retval.push(n);
227 } 227 }
228 228
229 return retval; 229 return retval;
230 } 230 }
231 231
232 function evalXPathFromId(expression, id) { 232 function evalXPathFromId(expression, id) {
233 return evalXPathFromNode(expression, document.getElementById(id)); 233 return evalXPathFromNode(expression, document.getElementById(id));
234 } 234 }
235 235
236 // Select the current page on the left nav. Note: if already rendered, this 236 // Select the current page on the left nav. Note: if already rendered, this
237 // will not effect any nodes. 237 // will not effect any nodes.
238 function selectCurrentPageOnLeftNav() { 238 function selectCurrentPageOnLeftNav() {
239 function finalPathPart(str) { 239 function finalPathPart(str) {
240 var pathParts = str.split(/\//); 240 var pathParts = str.split(/\//);
241 var lastPart = pathParts[pathParts.length - 1]; 241 var lastPart = pathParts[pathParts.length - 1];
242 return lastPart.split(/\?/)[0]; 242 return lastPart.split(/\?/)[0];
243 } 243 }
244 244
245 var pageBase = finalPathPart(document.location.href); 245 var pageBase = finalPathPart(document.location.href);
246 246
247 evalXPathFromId(".//li/a", "leftNav").select(function(node) { 247 evalXPathFromId(".//li/a", "gc-toc").select(function(node) {
248 if (pageBase == finalPathPart(node.href)) { 248 if (pageBase == finalPathPart(node.href)) {
249 var parent = node.parentNode; 249 var parent = node.parentNode;
250 if (node.firstChild.nodeName == 'DIV') { 250 if (node.firstChild.nodeName == 'DIV') {
251 node.firstChild.className = "leftNavSelected"; 251 node.firstChild.className = "leftNavSelected";
252 } else { 252 } else {
253 parent.className = "leftNavSelected"; 253 parent.className = "leftNavSelected";
254 } 254 }
255 parent.removeChild(node); 255 parent.removeChild(node);
256 parent.insertBefore(node.firstChild, parent.firstChild); 256 parent.insertBefore(node.firstChild, parent.firstChild);
257 return true; 257 return true;
258 } 258 }
259 }); 259 });
260 } 260 }
261 261
262 /* 262 /*
263 * Template Callout Functions 263 * Template Callout Functions
264 * The jstProcess() will call out to these functions from within the page templa te 264 * The jstProcess() will call out to these functions from within the page templa te
265 */ 265 */
266 266
267 function getDataFromPageHTML(id) { 267 function getDataFromPageHTML(id) {
268 var node = document.getElementById(id); 268 var node = document.getElementById(id);
(...skipping 11 matching lines...) Expand all
280 } 280 }
281 281
282 function showPageTOC() { 282 function showPageTOC() {
283 return module || getDataFromPageHTML('pageData-showTOC'); 283 return module || getDataFromPageHTML('pageData-showTOC');
284 } 284 }
285 285
286 function getStaticTOC() { 286 function getStaticTOC() {
287 var staticHNodes = evalXPathFromId(".//h2|h3", "static"); 287 var staticHNodes = evalXPathFromId(".//h2|h3", "static");
288 var retval = []; 288 var retval = [];
289 var lastH2; 289 var lastH2;
290 290
291 staticHNodes.each(function(n, i) { 291 staticHNodes.each(function(n, i) {
292 var anchorName = n.id || n.nodeName + "-" + i; 292 var anchorName = n.id || n.nodeName + "-" + i;
293 if (!n.id) { 293 if (!n.id) {
294 var a = document.createElement('a'); 294 var a = document.createElement('a');
295 a.name = anchorName; 295 a.name = anchorName;
296 n.parentNode.insertBefore(a, n); 296 n.parentNode.insertBefore(a, n);
297 } 297 }
298 var dataNode = { name: n.innerHTML, href: anchorName }; 298 var dataNode = { name: n.innerHTML, href: anchorName };
299 299
300 if (n.nodeName == "H2") { 300 if (n.nodeName == "H2") {
301 retval.push(dataNode); 301 retval.push(dataNode);
302 lastH2 = dataNode; 302 lastH2 = dataNode;
303 lastH2.children = []; 303 lastH2.children = [];
304 } else { 304 } else {
305 lastH2.children.push(dataNode); 305 lastH2.children.push(dataNode);
306 } 306 }
307 }); 307 });
308 308
309 return retval; 309 return retval;
310 } 310 }
311 311
312 function getTypeRefPage(type) { 312 function getTypeRefPage(type) {
313 return typeModule[type.$ref].namespace + ".html"; 313 return typeModule[type.$ref].namespace + ".html";
314 } 314 }
315 315
316 function getPageTitle() { 316 function getPageTitle() {
317 return getDataFromPageHTML("pageData-title") || 317 return getDataFromPageHTML("pageData-title") ||
318 apiModuleTitle || 318 apiModuleTitle ||
319 pageName; 319 pageName;
320 } 320 }
321 321
322 function getModuleName() { 322 function getModuleName() {
323 return "chrome." + module.namespace; 323 return "chrome." + module.namespace;
324 } 324 }
325 325
326 function getFullyQualifiedFunctionName(func) { 326 function getFullyQualifiedFunctionName(func) {
327 return getModuleName() + "." + func.name; 327 return getModuleName() + "." + func.name;
328 } 328 }
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
371 371
372 return schema.type; 372 return schema.type;
373 } 373 }
374 374
375 function getSignatureString(parameters) { 375 function getSignatureString(parameters) {
376 var retval = []; 376 var retval = [];
377 parameters.each(function(param, i) { 377 parameters.each(function(param, i) {
378 retval.push(getTypeName(param) + " " + param.name); 378 retval.push(getTypeName(param) + " " + param.name);
379 }); 379 });
380 380
381 return retval.join(", ");» 381 return retval.join(", ");
382 } 382 }
383 383
384 function sortByName(a, b) { 384 function sortByName(a, b) {
385 if (a.name < b.name) { 385 if (a.name < b.name) {
386 return -1; 386 return -1;
387 } 387 }
388 if (a.name > b.name) { 388 if (a.name > b.name) {
389 return 1; 389 return 1;
390 } 390 }
391 return 0; 391 return 0;
392 } 392 }
OLDNEW
« no previous file with comments | « chrome/common/extensions/docs/index.html ('k') | chrome/common/extensions/docs/manifest.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698