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

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
38 && Array.isArray(name.children()[0].children()) && name.children()[0].ch ildren().length > 0)
39 this.name = name.children()[0].children()[0].text();
lushnikov 2014/09/09 12:40:46 I would introduce a helper function "textContent",
iliia 2014/09/09 14:29:17 Done.
40 /** @type {string} */
41 this.dataType;
42 if (dataType && Array.isArray(dataType.children()) && dataType.children().le ngth > 0
43 && Array.isArray(dataType.children()[0].children()) && dataType.children ()[0].children().length > 0)
44 this.dataType = dataType.children()[0].children()[0].text();
lushnikov 2014/09/09 12:40:46 and here
iliia 2014/09/09 14:29:17 Done.
45 this.optional = false;
46 if (optional && Array.isArray(optional.children()) && optional.children().le ngth > 0
47 && Array.isArray(optional.children()[0].children()) && optional.children ()[0].children().length > 0)
48 this.optional = optional.children()[0].children()[0].text().toUpperCase( ) === "YES";
lushnikov 2014/09/09 12:40:46 and here
iliia 2014/09/09 14:29:17 Done.
38 this.description = description; 49 this.description = description;
39 } 50 }
40 51
41 /** 52 /**
42 * @constructor 53 * @constructor
43 * @param {string} language 54 * @param {?WebInspector.WikiParser.Block} language
44 * @param {string} code 55 * @param {string} code
45 * @param {string} liveUrl 56 * @param {?WebInspector.WikiParser.Block} liveUrl
46 * @param {?WebInspector.WikiParser.Block} description 57 * @param {?WebInspector.WikiParser.Block} description
47 */ 58 */
48 WebInspector.JSArticle.Example = function(language, code, liveUrl, description) 59 WebInspector.JSArticle.Example = function(language, code, liveUrl, description)
49 { 60 {
50 this.language = language; 61 /** @type {string} */
62 this.language;
63 if (language && Array.isArray(language.children()) && language.children().le ngth > 0
64 && Array.isArray(language.children()[0].children()) && language.children ()[0].children().length > 0)
65 this.language = language.children()[0].children()[0].text();
51 this.code = code; 66 this.code = code;
52 this.liveUrl = liveUrl; 67 /** @type {string} */
68 this.liveUrl;
69 if (liveUrl && Array.isArray(liveUrl.children()) && liveUrl.children().lengt h > 0
70 && Array.isArray(liveUrl.children()[0].children()) && liveUrl.children() [0].children().length > 0)
71 this.liveUrl = liveUrl.children()[0].children()[0].text();
53 this.description = description; 72 this.description = description;
54 } 73 }
55 74
56 /** 75 /**
57 * @constructor 76 * @constructor
58 * @param {string} returnValueName 77 * @param {?WebInspector.WikiParser.Block} returnValueName
59 * @param {string} returnValueDescription 78 * @param {?WebInspector.WikiParser.Block} returnValueDescription
60 */ 79 */
61 WebInspector.JSArticle.Method = function(returnValueName, returnValueDescription ) 80 WebInspector.JSArticle.Method = function(returnValueName, returnValueDescription )
62 { 81 {
63 this.returnValueName = returnValueName; 82 /** @type {string} */
64 this.returnValueDescription = returnValueDescription; 83 this.returnValueName;
84 if (returnValueName && Array.isArray(returnValueName.children()) && returnVa lueName.children().length > 0
85 && Array.isArray(returnValueName.children()[0].children()) && returnValu eName.children()[0].children().length > 0)
86 this.returnValueName = returnValueName.children()[0].children()[0].text( );
87 /** @type {string} */
88 this.returnValueDescription;
89 if (returnValueDescription && Array.isArray(returnValueDescription.children( ))
90 && returnValueDescription.children().length > 0
91 && Array.isArray(returnValueDescription.children()[0].children())
92 && returnValueDescription.children()[0].children().length > 0)
93 this.returnValueDescription = returnValueDescription ? returnValueDescriptio n.children()[0].children()[0].text() : null;
65 } 94 }
66 95
67 /** 96 /**
68 * @param {string} wikiMarkupText 97 * @param {string} wikiMarkupText
69 * @return {!WebInspector.JSArticle} 98 * @return {!WebInspector.JSArticle}
70 */ 99 */
71 WebInspector.JSArticle.parse = function(wikiMarkupText) 100 WebInspector.JSArticle.parse = function(wikiMarkupText)
72 { 101 {
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); 102 var wikiParser = new WebInspector.WikiParser(wikiMarkupText);
87 var wikiDocument = wikiParser.document(); 103 var wikiDocument = wikiParser.document();
88
89 var article = new WebInspector.JSArticle(); 104 var article = new WebInspector.JSArticle();
90 article.pageTitle = wikiDocument["Page_Title"]; 105 article.pageTitle = wikiDocument["Page_Title"];
91 if (typeof article.pageTitle !== "string") 106 if (typeof article.pageTitle !== "string")
92 delete article.pageTitle; 107 delete article.pageTitle;
93 article.standardizationStatus = wikiDocument["Standardization_Status"]; 108 article.standardizationStatus = wikiDocument["Standardization_Status"];
94 if (article.standardizationStatus !== "string") 109 if (article.standardizationStatus !== "string")
95 delete article.standardizationStatus; 110 delete article.standardizationStatus;
96 var apiObjectMethod = wikiDocument["API_Object_Method"]; 111 var apiObjectMethod = wikiDocument["API_Object_Method"];
97 if (apiObjectMethod) { 112 if (apiObjectMethod) {
98 var returnValueName = apiObjectMethod["Javascript_data_type"]; 113 var returnValueName = apiObjectMethod["Javascript_data_type"];
99 var returnValue = apiObjectMethod["Return_value_description"]; 114 var returnValue = apiObjectMethod["Return_value_description"];
100 if (returnValueName && returnValue) 115 if (returnValueName && returnValue)
101 article.methods = new WebInspector.JSArticle.Method(returnValueName, returnValue); 116 article.methods = new WebInspector.JSArticle.Method(returnValueName, returnValue);
102 } 117 }
103 118
104 var remarks = wikiDocument["Remarks_Section"] ? wikiDocument["Remarks_Sectio n"]["Remarks"] : null; 119 article.remarks = wikiDocument["Remarks_Section"] ? wikiDocument["Remarks_Se ction"]["Remarks"] : null;
105 if (remarks) 120 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 121
112 var examples = wikiDocument["Examples_Section"] ? wikiDocument["Examples_Sec tion"]["Examples"] : []; 122 var examples = wikiDocument["Examples_Section"] ? wikiDocument["Examples_Sec tion"]["Examples"] : [];
113 if (!Array.isArray(examples) && typeof examples !== "undefined") 123 if (!Array.isArray(examples) && typeof examples !== "undefined")
114 examples = [examples]; 124 examples = [examples];
115 125
116 for (var i = 0; i < examples.length; ++i) { 126 for (var i = 0; i < examples.length; ++i) {
117 var language = examples[i]["Single Example"]["Language"]; 127 var language = examples[i]["Single Example"]["Language"];
118 var code = examples[i]["Single Example"]["Code"]; 128 var code = examples[i]["Single Example"]["Code"];
119 var liveUrl = examples[i]["Single Example"]["LiveURL"]; 129 var liveUrl = examples[i]["Single Example"]["LiveURL"];
120 var description = parseString(examples[i]["Single Example"]["Description "], "example description"); 130 var description = examples[i]["Single Example"]["Description"];
121 article.examples.push(new WebInspector.JSArticle.Example(language, code, liveUrl, description)); 131 article.examples.push(new WebInspector.JSArticle.Example(language, code, liveUrl, description));
122 } 132 }
123 133
124 var parameters = apiObjectMethod ? apiObjectMethod["Parameters"] : []; 134 var parameters = apiObjectMethod ? apiObjectMethod["Parameters"] : [];
125 if (!Array.isArray(parameters) && typeof parameters !== "undefined") 135 if (!Array.isArray(parameters) && typeof parameters !== "undefined")
126 parameters = [parameters]; 136 parameters = [parameters];
127 137
128 for (var i = 0; i < parameters.length; ++i) { 138 for (var i = 0; i < parameters.length; ++i) {
129 var name = parameters[i]["Method Parameter"]["Name"]; 139 var name = parameters[i]["Method Parameter"]["Name"];
130 var dataType = parameters[i]["Method Parameter"]["Data type"]; 140 var dataType = parameters[i]["Method Parameter"]["Data type"];
131 var optional = parameters[i]["Method Parameter"]["Optional"]; 141 var optional = parameters[i]["Method Parameter"]["Optional"];
132 var description = parseString(parameters[i]["Method Parameter"]["Descrip tion"], "method description"); 142 var description = parameters[i]["Method Parameter"]["Description"];
133 article.parameters.push(new WebInspector.JSArticle.Parameter(name, dataT ype, optional, description)); 143 article.parameters.push(new WebInspector.JSArticle.Parameter(name, dataT ype, optional, description));
134 } 144 }
135 145
136 return article; 146 return article;
137 } 147 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698