summaryrefslogtreecommitdiffstats
path: root/chrome/common/extensions/docs/js
diff options
context:
space:
mode:
authorrafaelw@chromium.org <rafaelw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-08-05 23:58:26 +0000
committerrafaelw@chromium.org <rafaelw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-08-05 23:58:26 +0000
commit86cbd2abef20a01360a77dfd8593735cd1f0dbd4 (patch)
tree11107bd8db4b4fcf0b6e47fb7c91fe718b493c25 /chrome/common/extensions/docs/js
parentd7d1c5ca882c5cc914a2599410c0c3058dcb854b (diff)
downloadchromium_src-86cbd2abef20a01360a77dfd8593735cd1f0dbd4.zip
chromium_src-86cbd2abef20a01360a77dfd8593735cd1f0dbd4.tar.gz
chromium_src-86cbd2abef20a01360a77dfd8593735cd1f0dbd4.tar.bz2
Re-land extension docs build/render/presubmit. The original patch, http://codereview.chromium.org/159607, was reverted because of incorrect dependencies.
Note that the extension docs build.py is no longer a gyp build target. Review URL: http://codereview.chromium.org/159830 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@22558 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/common/extensions/docs/js')
-rwxr-xr-xchrome/common/extensions/docs/js/api_page_generator.js53
-rwxr-xr-xchrome/common/extensions/docs/js/bootstrap.js11
2 files changed, 44 insertions, 20 deletions
diff --git a/chrome/common/extensions/docs/js/api_page_generator.js b/chrome/common/extensions/docs/js/api_page_generator.js
index e45a5b7..4613d75 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();
@@ -96,10 +101,10 @@ function fetchContent(url, onSuccess, onError) {
function handleError(error) {
window.clearTimeout(abortTimerId);
- if (onError) {
+ if (onError)
onError(error);
- }
- console.error("XHR Failed: " + error);
+ else
+ 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 newline at end of file
diff --git a/chrome/common/extensions/docs/js/bootstrap.js b/chrome/common/extensions/docs/js/bootstrap.js
new file mode 100755
index 0000000..5282030d
--- /dev/null
+++ b/chrome/common/extensions/docs/js/bootstrap.js
@@ -0,0 +1,11 @@
+window.onload = function() {
+ // Regenerate page if we are passed the "?regenerate" search param
+ // or if the user-agent is chrome AND the document is being served
+ // from the file:/// scheme.
+ if (window.location.search == "?regenerate" ||
+ navigator.userAgent.indexOf("Chrome") > -1) {
+ // Hide body content initially to minimize flashing.
+ document.getElementsByTagName("body")[0].className = "hidden";
+ window.renderPage();
+ }
+} \ No newline at end of file