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

Unified Diff: chrome/common/extensions/docs/js/api_page_generator.js

Issue 159607: Extension docs build script, gyp target and PRESUBMIT.PY check (Closed)
Patch Set: remove build step on mac Created 11 years, 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/common/extensions/docs/index.html ('k') | chrome/common/extensions/docs/js/bootstrap.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/common/extensions/docs/js/api_page_generator.js
diff --git a/chrome/common/extensions/docs/js/api_page_generator.js b/chrome/common/extensions/docs/js/api_page_generator.js
index e45a5b7d56953db1a20f920c96892a01788c4c88..46406be483a6c243920fd18047d1ca14d69beffd 100755
--- a/chrome/common/extensions/docs/js/api_page_generator.js
+++ b/chrome/common/extensions/docs/js/api_page_generator.js
@@ -53,7 +53,11 @@ function extend(obj, obj2) {
function renderPage() {
var pathParts = document.location.href.split(/\/|\./);
pageName = pathParts[pathParts.length - 2];
-
+ if (!pageName) {
+ alert("Empty page name for: " + document.location.href);
+ return;
+ }
+
// Fetch the api template and insert into the <body>.
fetchContent(API_TEMPLATE, function(templateContent) {
document.getElementsByTagName("body")[0].innerHTML = templateContent;
@@ -68,7 +72,7 @@ function fetchStatic() {
fetchContent(staticResource(pageName), function(overviewContent) {
document.getElementById("static").innerHTML = overviewContent;
fetchSchema();
-
+
}, function(error) {
// Not fatal. Some api pages may not have matching static content.
fetchSchema();
@@ -88,6 +92,7 @@ function fetchSchema() {
* onSuccess(content)
*/
function fetchContent(url, onSuccess, onError) {
+ var localUrl = url;
var xhr = new XMLHttpRequest();
var abortTimerId = window.setTimeout(function() {
xhr.abort();
@@ -99,7 +104,7 @@ function fetchContent(url, onSuccess, onError) {
if (onError) {
onError(error);
}
- console.error("XHR Failed: " + error);
+ console.error("XHR Failed fetching: " + localUrl + "..." + error);
}
try {
@@ -113,9 +118,9 @@ function fetchContent(url, onSuccess, onError) {
}
}
}
-
+
xhr.onerror = handleError;
-
+
xhr.open("GET", url, true);
xhr.send(null);
} catch(e) {
@@ -134,7 +139,7 @@ function fetchContent(url, onSuccess, onError) {
function renderTemplate(schemaContent) {
pageData = {};
var schema = JSON.parse(schemaContent);
-
+
schema.each(function(module) {
if (module.namespace == pageName) {
// This page is an api page. Setup types and apiDefinition.
@@ -147,16 +152,24 @@ function renderTemplate(schemaContent) {
preprocessApi(pageData, schema);
}
});
-
+
setupPageData(pageData, schema);
-
+
// Render to template
var input = new JsEvalContext(pageData);
var output = document.getElementsByTagName("html")[0];
jstProcess(input, output);
-
+
// Show.
document.getElementsByTagName("body")[0].className = "";
+
+ if (parent && parent.done)
+ parent.done();
+}
+
+function serializePage() {
+ var s = new XMLSerializer();
+ return s.serializeToString(document);
}
function setupPageData(pageData, schema) {
@@ -170,7 +183,7 @@ function setupPageData(pageData, schema) {
pageData.apiModules.push(m);
});
pageData.apiModules.sort(function(a, b) { return a.name > b.name; });
-
+
if (!pageData.pageTitle) {
pageData.pageTitle = pageName;
pageData.h1Header = pageName;
@@ -203,13 +216,13 @@ function preprocessApi(pageData, schema) {
});
}
}
-
+
// Setup any type: "object" pameters to have an array of params (rather than
// named properties).
f.parameters.each(function(param) {
addPropertyListIfObject(param);
});
-
+
// Setup return typeName & _propertyList, if any.
if (f.returns) {
linkTypeReference(f.returns);
@@ -217,7 +230,7 @@ function preprocessApi(pageData, schema) {
addPropertyListIfObject(f.returns);
}
});
-
+
module.events.each(function(e) {
linkTypeReferences(e.parameters);
assignTypeNames(e.parameters);
@@ -274,19 +287,19 @@ function assignTypeNames(parameters) {
function typeName(schema) {
if (schema.$ref)
schema = types[schema.$ref];
-
+
if (schema.choice) {
var typeNames = [];
schema.choice.each(function(c) {
typeNames.push(typeName(c));
});
-
+
return typeNames.join(" or ");
}
-
+
if (schema.type == "array")
return "array of " + typeName(schema.items);
-
+
return schema.type;
}
@@ -299,6 +312,6 @@ function generateSignatureString(parameters) {
parameters.each(function(param, i) {
retval.push(param.typeName + " " + param.name);
});
-
+
return retval.join(", ");
}
« no previous file with comments | « chrome/common/extensions/docs/index.html ('k') | chrome/common/extensions/docs/js/bootstrap.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698