1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
8 WebInspector.JSArticle = function()
13 this.standardizationStatus;
14 /** @type {?WebInspector.WikiParser.Block} */
16 /** @type {!Array.<!WebInspector.JSArticle.Parameter>} */
18 /** @type {?WebInspector.JSArticle.Method} */
20 /** @type {?WebInspector.WikiParser.Block} */
22 /** @type {!Array.<!WebInspector.JSArticle.Example>} */
28 * @param {?WebInspector.WikiParser.Block} name
29 * @param {?WebInspector.WikiParser.Block} dataType
30 * @param {?WebInspector.WikiParser.Block} optional
31 * @param {?WebInspector.WikiParser.Block} description
33 WebInspector.JSArticle.Parameter = function(name, dataType, optional, description)
35 this.name = WebInspector.JSArticle.unfoldStringValue(name);
36 this.dataType = WebInspector.JSArticle.unfoldStringValue(dataType);
37 var textContent = WebInspector.JSArticle.unfoldStringValue(optional);
38 this.optional = textContent ? textContent.toUpperCase() === "YES" : false;
39 this.description = description;
44 * @param {?WebInspector.WikiParser.Block} language
45 * @param {!WebInspector.WikiParser.Block} code
46 * @param {?WebInspector.WikiParser.Block} liveUrl
47 * @param {?WebInspector.WikiParser.Block} description
49 WebInspector.JSArticle.Example = function(language, code, liveUrl, description)
51 this.language = WebInspector.JSArticle.unfoldStringValue(language);
52 this.code = WebInspector.JSArticle.unfoldStringValue(code);
53 this.liveUrl = WebInspector.JSArticle.unfoldStringValue(liveUrl);
54 this.description = description;
59 * @param {?WebInspector.WikiParser.Block} returnValueName
60 * @param {?WebInspector.WikiParser.Block} returnValueDescription
62 WebInspector.JSArticle.Method = function(returnValueName, returnValueDescription)
64 this.returnValueName = WebInspector.JSArticle.unfoldStringValue(returnValueName);
65 this.returnValueDescription = returnValueDescription;
69 * @param {?WebInspector.WikiParser.Block} block
72 WebInspector.JSArticle.unfoldStringValue = function(block)
74 if (block && block.hasChildren() && block.children()[0].hasChildren())
75 return block.children()[0].children()[0].text();
80 * @param {string} wikiMarkupText
81 * @return {!WebInspector.JSArticle}
83 WebInspector.JSArticle.parse = function(wikiMarkupText)
85 var wikiParser = new WebInspector.WikiParser(wikiMarkupText);
86 var wikiDocument = wikiParser.document();
87 var article = new WebInspector.JSArticle();
88 article.pageTitle = wikiDocument["Page_Title"];
89 if (typeof article.pageTitle !== "string")
90 delete article.pageTitle;
91 article.standardizationStatus = wikiDocument["Standardization_Status"];
92 if (article.standardizationStatus !== "string")
93 delete article.standardizationStatus;
94 var apiObjectMethod = wikiDocument["API_Object_Method"];
95 if (apiObjectMethod) {
96 var returnValueName = apiObjectMethod["Javascript_data_type"];
97 var returnValue = apiObjectMethod["Return_value_description"];
98 if (returnValueName && returnValue)
99 article.methods = new WebInspector.JSArticle.Method(returnValueName, returnValue);
102 article.remarks = wikiDocument["Remarks_Section"] ? wikiDocument["Remarks_Section"]["Remarks"] : null;
103 article.summary = wikiDocument["Summary_Section"];
105 var examples = wikiDocument["Examples_Section"] && wikiDocument["Examples_Section"]["Examples"] ? wikiDocument["Examples_Section"]["Examples"] : [];
106 if (!Array.isArray(examples) && typeof examples !== "undefined")
107 examples = [examples];
109 for (var i = 0; i < examples.length; ++i) {
110 if (!examples[i].values)
112 var language = examples[i].values["Language"];
113 var code = examples[i].values["Code"];
114 var liveUrl = examples[i].values["LiveURL"];
115 var description = examples[i].values["Description"];
116 article.examples.push(new WebInspector.JSArticle.Example(language, code, liveUrl, description));
119 var parameters = apiObjectMethod ? apiObjectMethod["Parameters"] : [];
120 if (!Array.isArray(parameters) && typeof parameters !== "undefined")
121 parameters = [parameters];
123 for (var i = 0; i < parameters.length; ++i) {
124 if (!parameters[i].values)
126 var name = parameters[i].values["Name"];
127 var dataType = parameters[i].values["Data type"];
128 var optional = parameters[i].values["Optional"];
129 var description = parameters[i].values["Description"];
130 article.parameters.push(new WebInspector.JSArticle.Parameter(name, dataType, optional, description));