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

Side by Side Diff: Source/devtools/front_end/documentation/JSArticle.js

Issue 539353004: DevTools: [Documentation] Update parser for WikiText (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: comments addressed Created 6 years, 3 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 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 * @constructor 6 * @constructor
7 */ 7 */
8 WebInspector.JSArticle = function() 8 WebInspector.JSArticle = function()
9 { 9 {
10 /** @type {string} */ 10 /** @type {string} */
11 this.pageTitle; 11 this.pageTitle;
12 /** @type {string} */ 12 /** @type {string} */
13 this.standardizationStatus; 13 this.standardizationStatus;
14 /** @type {?WebInspector.WikiParser.Block} */ 14 /** @type {?WebInspector.WikiParser.Block} */
15 this.summary; 15 this.summary;
16 /** @type {!Array.<!WebInspector.JSArticle.Parameter>} */ 16 /** @type {!Array.<!WebInspector.JSArticle.Parameter>} */
17 this.parameters = []; 17 this.parameters = [];
18 /** @type {?WebInspector.JSArticle.Method} */ 18 /** @type {?WebInspector.JSArticle.Method} */
19 this.methods; 19 this.methods;
20 /** @type {?WebInspector.WikiParser.Block} */ 20 /** @type {?WebInspector.WikiParser.Block} */
21 this.remarks; 21 this.remarks;
22 /** @type {!Array.<!WebInspector.JSArticle.Example>} */ 22 /** @type {!Array.<!WebInspector.JSArticle.Example>} */
23 this.examples = []; 23 this.examples = [];
24 } 24 }
25 25
26 /** 26 /**
27 * @constructor 27 * @constructor
28 * @param {string} name 28 * @param {?WebInspector.WikiParser.Block} name
29 * @param {string} dataType 29 * @param {?WebInspector.WikiParser.Block} dataType
30 * @param {string} optional 30 * @param {?WebInspector.WikiParser.Block} optional
31 * @param {?WebInspector.WikiParser.Block} description 31 * @param {?WebInspector.WikiParser.Block} description
32 */ 32 */
33 WebInspector.JSArticle.Parameter = function(name, dataType, optional, descriptio n) 33 WebInspector.JSArticle.Parameter = function(name, dataType, optional, descriptio n)
34 { 34 {
35 this.name = name; 35 /** @type {string} */
36 this.dataType = dataType; 36 this.name;
37 this.optional = optional.toUpperCase() === "YES"; 37 if (name && Array.isArray(name.children()) && name.children().length > 0 && Array.isArray(name.children()[0].children()) && name.children()[0].children().le ngth > 0)
loislo 2014/09/09 08:05:04 please wrap the expression for better readability
iliia 2014/09/09 08:19:28 Done.
38 this.name = name.children()[0].children()[0].text();
39 /** @type {string} */
40 this.dataType;
41 if (dataType && Array.isArray(dataType.children()) && dataType.children().le ngth > 0 && Array.isArray(dataType.children()[0].children()) && dataType.childre n()[0].children().length > 0)
loislo 2014/09/09 08:05:04 ditto
iliia 2014/09/09 08:19:28 Done.
42 this.dataType = dataType.children()[0].children()[0].text();
43 this.optional = false;
44 if (optional && Array.isArray(optional.children()) && optional.children().le ngth > 0 && Array.isArray(optional.children()[0].children()) && optional.childre n()[0].children().length > 0)
loislo 2014/09/09 08:05:04 ditto
iliia 2014/09/09 08:19:29 Done.
45 this.optional = optional.children()[0].children()[0].text().toUpperCase( ) === "YES";
38 this.description = description; 46 this.description = description;
39 } 47 }
40 48
41 /** 49 /**
42 * @constructor 50 * @constructor
43 * @param {string} language 51 * @param {?WebInspector.WikiParser.Block} language
44 * @param {string} code 52 * @param {string} code
45 * @param {string} liveUrl 53 * @param {?WebInspector.WikiParser.Block} liveUrl
46 * @param {?WebInspector.WikiParser.Block} description 54 * @param {?WebInspector.WikiParser.Block} description
47 */ 55 */
48 WebInspector.JSArticle.Example = function(language, code, liveUrl, description) 56 WebInspector.JSArticle.Example = function(language, code, liveUrl, description)
49 { 57 {
50 this.language = language; 58 /** @type {string} */
59 this.language;
60 if (language && Array.isArray(language.children()) && language.children().le ngth > 0 && Array.isArray(language.children()[0].children()) && language.childre n()[0].children().length > 0)
loislo 2014/09/09 08:05:04 ditto
iliia 2014/09/09 08:19:28 Done.
61 this.language = language.children()[0].children()[0].text();
51 this.code = code; 62 this.code = code;
52 this.liveUrl = liveUrl; 63 /** @type {string} */
64 this.liveUrl;
65 if (liveUrl && Array.isArray(liveUrl.children()) && liveUrl.children().lengt h > 0 && Array.isArray(liveUrl.children()[0].children()) && liveUrl.children()[0 ].children().length > 0)
loislo 2014/09/09 08:05:04 ditto
iliia 2014/09/09 08:19:28 Done.
66 this.liveUrl = liveUrl.children()[0].children()[0].text();
53 this.description = description; 67 this.description = description;
54 } 68 }
55 69
56 /** 70 /**
57 * @constructor 71 * @constructor
58 * @param {string} returnValueName 72 * @param {?WebInspector.WikiParser.Block} returnValueName
59 * @param {string} returnValueDescription 73 * @param {?WebInspector.WikiParser.Block} returnValueDescription
60 */ 74 */
61 WebInspector.JSArticle.Method = function(returnValueName, returnValueDescription ) 75 WebInspector.JSArticle.Method = function(returnValueName, returnValueDescription )
62 { 76 {
63 this.returnValueName = returnValueName; 77 /** @type {string} */
64 this.returnValueDescription = returnValueDescription; 78 this.returnValueName;
79 if (returnValueName && Array.isArray(returnValueName.children()) && returnVa lueName.children().length > 0 && Array.isArray(returnValueName.children()[0].chi ldren()) && returnValueName.children()[0].children().length > 0)
loislo 2014/09/09 08:05:04 ditto
iliia 2014/09/09 08:19:28 Done.
80 this.returnValueName = returnValueName.children()[0].children()[0].text( );
81 /** @type {string} */
82 this.returnValueDescription;
83 if (returnValueDescription && Array.isArray(returnValueDescription.children( )) && returnValueDescription.children().length > 0 && Array.isArray(returnValueD escription.children()[0].children()) && returnValueDescription.children()[0].chi ldren().length > 0)
loislo 2014/09/09 08:05:04 ditto
iliia 2014/09/09 08:19:28 Done.
84 this.returnValueDescription = returnValueDescription ? returnValueDescriptio n.children()[0].children()[0].text() : null;
65 } 85 }
66 86
67 /** 87 /**
68 * @param {string} wikiMarkupText 88 * @param {string} wikiMarkupText
69 * @return {!WebInspector.JSArticle} 89 * @return {!WebInspector.JSArticle}
70 */ 90 */
71 WebInspector.JSArticle.parse = function(wikiMarkupText) 91 WebInspector.JSArticle.parse = function(wikiMarkupText)
72 { 92 {
73 /**
74 * @param {string} string
75 * @param {string} debugInfo
76 * @return {?WebInspector.WikiParser.Block}
77 */
78 function parseString(string, debugInfo)
79 {
80 var result = wikiParser.parseString(string);
81 if (!result)
82 console.error("Can't parse " + debugInfo);
83 return result;
84 }
85
86 var wikiParser = new WebInspector.WikiParser(wikiMarkupText); 93 var wikiParser = new WebInspector.WikiParser(wikiMarkupText);
87 var wikiDocument = wikiParser.document(); 94 var wikiDocument = wikiParser.document();
88
89 var article = new WebInspector.JSArticle(); 95 var article = new WebInspector.JSArticle();
90 article.pageTitle = wikiDocument["Page_Title"]; 96 article.pageTitle = wikiDocument["Page_Title"];
91 if (typeof article.pageTitle !== "string") 97 if (typeof article.pageTitle !== "string")
92 delete article.pageTitle; 98 delete article.pageTitle;
93 article.standardizationStatus = wikiDocument["Standardization_Status"]; 99 article.standardizationStatus = wikiDocument["Standardization_Status"];
94 if (article.standardizationStatus !== "string") 100 if (article.standardizationStatus !== "string")
95 delete article.standardizationStatus; 101 delete article.standardizationStatus;
96 var apiObjectMethod = wikiDocument["API_Object_Method"]; 102 var apiObjectMethod = wikiDocument["API_Object_Method"];
97 if (apiObjectMethod) { 103 if (apiObjectMethod) {
98 var returnValueName = apiObjectMethod["Javascript_data_type"]; 104 var returnValueName = apiObjectMethod["Javascript_data_type"];
99 var returnValue = apiObjectMethod["Return_value_description"]; 105 var returnValue = apiObjectMethod["Return_value_description"];
100 if (returnValueName && returnValue) 106 if (returnValueName && returnValue)
101 article.methods = new WebInspector.JSArticle.Method(returnValueName, returnValue); 107 article.methods = new WebInspector.JSArticle.Method(returnValueName, returnValue);
102 } 108 }
103 109
104 var remarks = wikiDocument["Remarks_Section"] ? wikiDocument["Remarks_Sectio n"]["Remarks"] : null; 110 article.remarks = wikiDocument["Remarks_Section"] ? wikiDocument["Remarks_Se ction"]["Remarks"] : null;
105 if (remarks) 111 article.summary = wikiDocument["Summary_Section"];
106 article.remarks = parseString(remarks, "remarks");
107
108 var summary = wikiDocument["Summary_Section"];
109 if (summary)
110 article.summary = parseString(summary, "summary");
111 112
112 var examples = wikiDocument["Examples_Section"] ? wikiDocument["Examples_Sec tion"]["Examples"] : []; 113 var examples = wikiDocument["Examples_Section"] ? wikiDocument["Examples_Sec tion"]["Examples"] : [];
113 if (!Array.isArray(examples) && typeof examples !== "undefined") 114 if (!Array.isArray(examples) && typeof examples !== "undefined")
114 examples = [examples]; 115 examples = [examples];
115 116
116 for (var i = 0; i < examples.length; ++i) { 117 for (var i = 0; i < examples.length; ++i) {
117 var language = examples[i]["Single Example"]["Language"]; 118 var language = examples[i]["Single Example"]["Language"];
118 var code = examples[i]["Single Example"]["Code"]; 119 var code = examples[i]["Single Example"]["Code"];
119 var liveUrl = examples[i]["Single Example"]["LiveURL"]; 120 var liveUrl = examples[i]["Single Example"]["LiveURL"];
120 var description = parseString(examples[i]["Single Example"]["Description "], "example description"); 121 var description = examples[i]["Single Example"]["Description"];
121 article.examples.push(new WebInspector.JSArticle.Example(language, code, liveUrl, description)); 122 article.examples.push(new WebInspector.JSArticle.Example(language, code, liveUrl, description));
122 } 123 }
123 124
124 var parameters = apiObjectMethod ? apiObjectMethod["Parameters"] : []; 125 var parameters = apiObjectMethod ? apiObjectMethod["Parameters"] : [];
125 if (!Array.isArray(parameters) && typeof parameters !== "undefined") 126 if (!Array.isArray(parameters) && typeof parameters !== "undefined")
126 parameters = [parameters]; 127 parameters = [parameters];
127 128
128 for (var i = 0; i < parameters.length; ++i) { 129 for (var i = 0; i < parameters.length; ++i) {
129 var name = parameters[i]["Method Parameter"]["Name"]; 130 var name = parameters[i]["Method Parameter"]["Name"];
130 var dataType = parameters[i]["Method Parameter"]["Data type"]; 131 var dataType = parameters[i]["Method Parameter"]["Data type"];
131 var optional = parameters[i]["Method Parameter"]["Optional"]; 132 var optional = parameters[i]["Method Parameter"]["Optional"];
132 var description = parseString(parameters[i]["Method Parameter"]["Descrip tion"], "method description"); 133 var description = parameters[i]["Method Parameter"]["Description"];
133 article.parameters.push(new WebInspector.JSArticle.Parameter(name, dataT ype, optional, description)); 134 article.parameters.push(new WebInspector.JSArticle.Parameter(name, dataT ype, optional, description));
134 } 135 }
135 136
136 return article; 137 return article;
137 } 138 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698