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

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

Issue 10829301: Extension docs: Manual merge crrev.com/143652 (Closed) Base URL: svn://svn.chromium.org/chrome/branches/1180/src/
Patch Set: Created 8 years, 4 months 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 /** 5 /**
6 * @fileoverview This file is the controller for generating extension 6 * @fileoverview This file is the controller for generating extension
7 * doc pages. 7 * doc pages.
8 * 8 *
9 * It expects to have available via XHR (relative path): 9 * It expects to have available via XHR (relative path):
10 * 1) API_TEMPLATE which is the main template for the api pages. 10 * 1) API_TEMPLATE which is the main template for the api pages.
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 107
108 // Mappings of api calls to URLs 108 // Mappings of api calls to URLs
109 var apiMapping; 109 var apiMapping;
110 110
111 // The current module for this page (if this page is an api module); 111 // The current module for this page (if this page is an api module);
112 var module; 112 var module;
113 113
114 // Mapping from typeId to module. 114 // Mapping from typeId to module.
115 var typeModule = {}; 115 var typeModule = {};
116 116
117 // Mapping from typeId to type.
118 var typeIdType = {};
119
117 // Auto-created page name as default 120 // Auto-created page name as default
118 var pageName; 121 var pageName;
119 122
120 // If this page is an apiModule, the name of the api module 123 // If this page is an apiModule, the name of the api module
121 var apiModuleName; 124 var apiModuleName;
122 125
123 // Permission information according to PERMISSION_FEATURES. 126 // Permission information according to PERMISSION_FEATURES.
124 var permissionFeatures = {}; 127 var permissionFeatures = {};
125 128
126 // Visits each item in the list in-order. Stops when f returns any truthy 129 // Visits each item in the list in-order. Stops when f returns any truthy
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 196
194 var schemas_to_retrieve = []; 197 var schemas_to_retrieve = [];
195 if (!USE_DEVTOOLS_SCHEMA || is_experimental_index) 198 if (!USE_DEVTOOLS_SCHEMA || is_experimental_index)
196 schemas_to_retrieve = schemas_to_retrieve.concat(MODULE_SCHEMAS); 199 schemas_to_retrieve = schemas_to_retrieve.concat(MODULE_SCHEMAS);
197 if (USE_DEVTOOLS_SCHEMA || is_experimental_index) 200 if (USE_DEVTOOLS_SCHEMA || is_experimental_index)
198 schemas_to_retrieve.push(DEVTOOLS_SCHEMA); 201 schemas_to_retrieve.push(DEVTOOLS_SCHEMA);
199 202
200 var schemas_retrieved = 0; 203 var schemas_retrieved = 0;
201 schema = []; 204 schema = [];
202 205
206 function qualifyRefs(namespace, obj) {
207 if (typeof(obj) == "object") {
208 for (var i in obj) {
209 if (typeof(obj[i]) == "object") {
210 obj[i] = qualifyRefs(namespace, obj[i]);
211 } else if (i == "$ref") {
212 if (obj[i].indexOf('.') == -1) {
213 obj[i] = namespace + '.' + obj[i];
214 }
215 }
216 }
217 }
218 return obj;
219 }
220
221 function qualifyTypes(schema) {
222 schema.forEach(function(mod) {
223 if (mod.types) {
224 mod.types.forEach(function(type) {
225 type.prettyId = type.id;
226 if (type.prettyId.indexOf(mod.namespace) == 0) {
227 type.prettyId = type.prettyId.substring(mod.namespace.length + 1);
228 }
229 if (type.id.indexOf(mod.namespace) != 0) {
230 type.id = mod.namespace + '.' + type.id;
231 }
232 typeModule[type.id] = mod;
233 typeIdType[type.id] = type;
234 });
235 }
236 mod = qualifyRefs(mod.namespace, mod);
237 });
238 return schema;
239 }
240
203 function onSchemaContent(content) { 241 function onSchemaContent(content) {
204 if (content) 242 if (content)
205 schema = schema.concat(JSON.parse(JSON.minify(content))); 243 schema = schema.concat(qualifyTypes(JSON.parse(JSON.minify(content))));
206 if (++schemas_retrieved < schemas_to_retrieve.length) 244 if (++schemas_retrieved < schemas_to_retrieve.length)
207 return; 245 return;
208 if (pageName.toLowerCase() == 'samples') { 246 if (pageName.toLowerCase() == 'samples') {
209 fetchSamples(); 247 fetchSamples();
210 } else { 248 } else {
211 renderTemplate(); 249 renderTemplate();
212 } 250 }
213 } 251 }
214 252
215 schemas_to_retrieve.forEach(function(schema_path) { 253 schemas_to_retrieve.forEach(function(schema_path) {
(...skipping 488 matching lines...) Expand 10 before | Expand all | Expand 10 after
704 742
705 if (schema.type == 'array') 743 if (schema.type == 'array')
706 return 'array of ' + getTypeName(schema.items); 744 return 'array of ' + getTypeName(schema.items);
707 745
708 if (schema.isInstanceOf) 746 if (schema.isInstanceOf)
709 return schema.isInstanceOf; 747 return schema.isInstanceOf;
710 748
711 return schema.type; 749 return schema.type;
712 } 750 }
713 751
752 function getPrettyTypeId(typeName) {
753 return typeIdType[typeName].prettyId;
754 }
755
714 function hasPrimitiveValue(schema) { 756 function hasPrimitiveValue(schema) {
715 var type = typeof(schema.value); 757 var type = typeof(schema.value);
716 return type === 'string' || type === 'number'; 758 return type === 'string' || type === 'number';
717 } 759 }
718 760
719 function getPrimitiveValue(schema) { 761 function getPrimitiveValue(schema) {
720 switch (typeof(schema.value)) { 762 switch (typeof(schema.value)) {
721 case 'string': 763 case 'string':
722 return '"' + schema.value + '"'; 764 return '"' + schema.value + '"';
723 765
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
759 } 801 }
760 if (a.name > b.name) { 802 if (a.name > b.name) {
761 return 1; 803 return 1;
762 } 804 }
763 return 0; 805 return 0;
764 } 806 }
765 807
766 function disableDocs(obj) { 808 function disableDocs(obj) {
767 return !!obj.nodoc; 809 return !!obj.nodoc;
768 } 810 }
OLDNEW
« no previous file with comments | « chrome/common/extensions/docs/input.ime.html ('k') | chrome/common/extensions/docs/management.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698