OLD | NEW |
---|---|
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 this.name = name ? name.children()[0].children()[0].text() : null; |
lushnikov
2014/09/08 14:08:30
That's a very risky code. Who guarantees there'll
iliia
2014/09/08 15:20:50
It was one simple plain text before, but now it's
| |
36 this.dataType = dataType; | 36 this.dataType = dataType ? dataType.children()[0].children()[0].text() : nul l; |
lushnikov
2014/09/08 14:08:30
ditto
iliia
2014/09/08 15:20:50
Done.
| |
37 this.optional = optional.toUpperCase() === "YES"; | 37 this.optional = optional ? optional.children()[0].children()[0].text().toUpp erCase() === "YES" : false; |
38 this.description = description; | 38 this.description = description; |
39 } | 39 } |
40 | 40 |
41 /** | 41 /** |
42 * @constructor | 42 * @constructor |
43 * @param {string} language | 43 * @param {?WebInspector.WikiParser.Block} language |
44 * @param {string} code | 44 * @param {string} code |
45 * @param {string} liveUrl | 45 * @param {?WebInspector.WikiParser.Block} liveUrl |
46 * @param {?WebInspector.WikiParser.Block} description | 46 * @param {?WebInspector.WikiParser.Block} description |
47 */ | 47 */ |
48 WebInspector.JSArticle.Example = function(language, code, liveUrl, description) | 48 WebInspector.JSArticle.Example = function(language, code, liveUrl, description) |
49 { | 49 { |
50 this.language = language; | 50 this.language = language ? language.children()[0].children()[0].text() : nul l ; |
lushnikov
2014/09/08 14:08:30
you should not address that deep structures withou
iliia
2014/09/08 15:20:50
Done.
| |
51 this.code = code; | 51 this.code = code; |
52 this.liveUrl = liveUrl; | 52 this.liveUrl = liveUrl ? liveUrl.children()[0].children()[0].text() : null; |
53 this.description = description; | 53 this.description = description; |
54 } | 54 } |
55 | 55 |
56 /** | 56 /** |
57 * @constructor | 57 * @constructor |
58 * @param {string} returnValueName | 58 * @param {?WebInspector.WikiParser.Block} returnValueName |
59 * @param {string} returnValueDescription | 59 * @param {?WebInspector.WikiParser.Block} returnValueDescription |
60 */ | 60 */ |
61 WebInspector.JSArticle.Method = function(returnValueName, returnValueDescription ) | 61 WebInspector.JSArticle.Method = function(returnValueName, returnValueDescription ) |
62 { | 62 { |
63 this.returnValueName = returnValueName; | 63 this.returnValueName = returnValueName ? returnValueName.children()[0].child ren()[0].text() : null; |
lushnikov
2014/09/08 14:08:30
ditto
iliia
2014/09/08 15:20:50
Done.
| |
64 this.returnValueDescription = returnValueDescription; | 64 this.returnValueDescription = returnValueDescription ? returnValueDescriptio n.children()[0].children()[0].text() : null; |
65 } | 65 } |
66 | 66 |
67 /** | 67 /** |
68 * @param {string} wikiMarkupText | 68 * @param {string} wikiMarkupText |
69 * @return {!WebInspector.JSArticle} | 69 * @return {!WebInspector.JSArticle} |
70 */ | 70 */ |
71 WebInspector.JSArticle.parse = function(wikiMarkupText) | 71 WebInspector.JSArticle.parse = function(wikiMarkupText) |
72 { | 72 { |
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); | 73 var wikiParser = new WebInspector.WikiParser(wikiMarkupText); |
87 var wikiDocument = wikiParser.document(); | 74 var wikiDocument = wikiParser.document(); |
88 | |
89 var article = new WebInspector.JSArticle(); | 75 var article = new WebInspector.JSArticle(); |
90 article.pageTitle = wikiDocument["Page_Title"]; | 76 article.pageTitle = wikiDocument["Page_Title"]; |
91 if (typeof article.pageTitle !== "string") | 77 if (typeof article.pageTitle !== "string") |
92 delete article.pageTitle; | 78 delete article.pageTitle; |
93 article.standardizationStatus = wikiDocument["Standardization_Status"]; | 79 article.standardizationStatus = wikiDocument["Standardization_Status"]; |
94 if (article.standardizationStatus !== "string") | 80 if (article.standardizationStatus !== "string") |
95 delete article.standardizationStatus; | 81 delete article.standardizationStatus; |
96 var apiObjectMethod = wikiDocument["API_Object_Method"]; | 82 var apiObjectMethod = wikiDocument["API_Object_Method"]; |
97 if (apiObjectMethod) { | 83 if (apiObjectMethod) { |
98 var returnValueName = apiObjectMethod["Javascript_data_type"]; | 84 var returnValueName = apiObjectMethod["Javascript_data_type"]; |
99 var returnValue = apiObjectMethod["Return_value_description"]; | 85 var returnValue = apiObjectMethod["Return_value_description"]; |
100 if (returnValueName && returnValue) | 86 if (returnValueName && returnValue) |
101 article.methods = new WebInspector.JSArticle.Method(returnValueName, returnValue); | 87 article.methods = new WebInspector.JSArticle.Method(returnValueName, returnValue); |
102 } | 88 } |
103 | 89 |
104 var remarks = wikiDocument["Remarks_Section"] ? wikiDocument["Remarks_Sectio n"]["Remarks"] : null; | 90 var remarks = wikiDocument["Remarks_Section"] ? wikiDocument["Remarks_Sectio n"]["Remarks"] : null; |
lushnikov
2014/09/08 14:08:30
article.remarks = ...
iliia
2014/09/08 15:20:50
Done.
| |
105 if (remarks) | 91 if (remarks) |
106 article.remarks = parseString(remarks, "remarks"); | 92 article.remarks = remarks; |
107 | 93 |
108 var summary = wikiDocument["Summary_Section"]; | 94 var summary = wikiDocument["Summary_Section"]; |
lushnikov
2014/09/08 14:08:30
article.summary =...
iliia
2014/09/08 15:20:50
Done.
| |
109 if (summary) | 95 if (summary) |
110 article.summary = parseString(summary, "summary"); | 96 article.summary = summary; |
111 | 97 |
112 var examples = wikiDocument["Examples_Section"] ? wikiDocument["Examples_Sec tion"]["Examples"] : []; | 98 var examples = wikiDocument["Examples_Section"] ? wikiDocument["Examples_Sec tion"]["Examples"] : []; |
113 if (!Array.isArray(examples) && typeof examples !== "undefined") | 99 if (!Array.isArray(examples) && typeof examples !== "undefined") |
114 examples = [examples]; | 100 examples = [examples]; |
115 | 101 |
116 for (var i = 0; i < examples.length; ++i) { | 102 for (var i = 0; i < examples.length; ++i) { |
117 var language = examples[i]["Single Example"]["Language"]; | 103 var language = examples[i]["Single Example"]["Language"]; |
118 var code = examples[i]["Single Example"]["Code"]; | 104 var code = examples[i]["Single Example"]["Code"]; |
119 var liveUrl = examples[i]["Single Example"]["LiveURL"]; | 105 var liveUrl = examples[i]["Single Example"]["LiveURL"]; |
120 var description = parseString(examples[i]["Single Example"]["Description "], "example description"); | 106 var description = examples[i]["Single Example"]["Description"]; |
121 article.examples.push(new WebInspector.JSArticle.Example(language, code, liveUrl, description)); | 107 article.examples.push(new WebInspector.JSArticle.Example(language, code, liveUrl, description)); |
122 } | 108 } |
123 | 109 |
124 var parameters = apiObjectMethod ? apiObjectMethod["Parameters"] : []; | 110 var parameters = apiObjectMethod ? apiObjectMethod["Parameters"] : []; |
125 if (!Array.isArray(parameters) && typeof parameters !== "undefined") | 111 if (!Array.isArray(parameters) && typeof parameters !== "undefined") |
126 parameters = [parameters]; | 112 parameters = [parameters]; |
127 | 113 |
128 for (var i = 0; i < parameters.length; ++i) { | 114 for (var i = 0; i < parameters.length; ++i) { |
129 var name = parameters[i]["Method Parameter"]["Name"]; | 115 var name = parameters[i]["Method Parameter"]["Name"]; |
130 var dataType = parameters[i]["Method Parameter"]["Data type"]; | 116 var dataType = parameters[i]["Method Parameter"]["Data type"]; |
131 var optional = parameters[i]["Method Parameter"]["Optional"]; | 117 var optional = parameters[i]["Method Parameter"]["Optional"]; |
132 var description = parseString(parameters[i]["Method Parameter"]["Descrip tion"], "method description"); | 118 var description = parameters[i]["Method Parameter"]["Description"]; |
133 article.parameters.push(new WebInspector.JSArticle.Parameter(name, dataT ype, optional, description)); | 119 article.parameters.push(new WebInspector.JSArticle.Parameter(name, dataT ype, optional, description)); |
134 } | 120 } |
135 | 121 |
136 return article; | 122 return article; |
137 } | 123 } |
OLD | NEW |