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