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

Side by Side Diff: Source/devtools/front_end/documentation/DocumentationView.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 * @extends {WebInspector.View} 7 * @extends {WebInspector.View}
8 */ 8 */
9 WebInspector.DocumentationView = function() 9 WebInspector.DocumentationView = function()
10 { 10 {
11 WebInspector.View.call(this); 11 WebInspector.View.call(this);
12 this.element.classList.add("documentation-view"); 12 this.element.classList.add("documentation-view");
13 this.registerRequiredCSS("documentationView.css"); 13 this.registerRequiredCSS("documentationView.css");
14 } 14 }
15 15
16 /** 16 /**
17 * @param {string} url 17 * @param {string} url
18 * @param {string} searchItem 18 * @param {string} searchItem
19 */ 19 */
20 WebInspector.DocumentationView.showDocumentationURL = function(url, searchItem) 20 WebInspector.DocumentationView.showDocumentationURL = function(url, searchItem)
21 { 21 {
22 if (!WebInspector.DocumentationView._view) 22 if (!WebInspector.DocumentationView._view)
23 WebInspector.DocumentationView._view = new WebInspector.DocumentationVie w(); 23 WebInspector.DocumentationView._view = new WebInspector.DocumentationVie w();
24 var view = WebInspector.DocumentationView._view; 24 var view = WebInspector.DocumentationView._view;
25 view.element.removeChildren();
25 WebInspector.inspectorView.showCloseableViewInDrawer("documentation", WebIns pector.UIString("Documentation"), view); 26 WebInspector.inspectorView.showCloseableViewInDrawer("documentation", WebIns pector.UIString("Documentation"), view);
26 view.showDocumentation(url, searchItem); 27 view.showDocumentation(url, searchItem);
27 } 28 }
28 29
29 WebInspector.DocumentationView._languageToMimeType = { 30 WebInspector.DocumentationView._languageToMimeType = {
30 "javascript": "text/javascript", 31 "javascript": "text/javascript",
31 "html": "text/html" 32 "html": "text/html"
32 }; 33 };
33 34
34 WebInspector.DocumentationView.prototype = { 35 WebInspector.DocumentationView.prototype = {
(...skipping 19 matching lines...) Expand all
54 _createArticle: function(searchItem, responseText) 55 _createArticle: function(searchItem, responseText)
55 { 56 {
56 var json = JSON.parse(responseText); 57 var json = JSON.parse(responseText);
57 var pages = json["query"]["pages"]; 58 var pages = json["query"]["pages"];
58 var wikiKeys = Object.keys(pages); 59 var wikiKeys = Object.keys(pages);
59 if (wikiKeys.length === 1 && wikiKeys[0] === "-1") { 60 if (wikiKeys.length === 1 && wikiKeys[0] === "-1") {
60 this._createEmptyPage(); 61 this._createEmptyPage();
61 return; 62 return;
62 } 63 }
63 var wikiMarkupText = pages[wikiKeys[0]]["revisions"]["0"]["*"]; 64 var wikiMarkupText = pages[wikiKeys[0]]["revisions"]["0"]["*"];
64 var article = WebInspector.JSArticle.parse(wikiMarkupText); 65 var article;
66 try {
67 article = WebInspector.JSArticle.parse(wikiMarkupText);
68 } catch (error) {
69 console.error("Article could not be parsed. " + error);
70 }
65 if (!article) { 71 if (!article) {
66 this._createEmptyPage(); 72 this._createEmptyPage();
67 return; 73 return;
68 } 74 }
69 75
76 this.element.removeChildren();
70 var renderer = new WebInspector.DocumentationView.Renderer(article, sear chItem); 77 var renderer = new WebInspector.DocumentationView.Renderer(article, sear chItem);
71 this.element.removeChildren();
72 this.element.appendChild(renderer.renderJSArticle()); 78 this.element.appendChild(renderer.renderJSArticle());
73 }, 79 },
74 80
75 _createEmptyPage: function() 81 _createEmptyPage: function()
76 { 82 {
77 this.element.removeChildren(); 83 this.element.removeChildren();
78 var emptyPage = this.element.createChild("div", "documentation-empty-pag e fill"); 84 var emptyPage = this.element.createChild("div", "documentation-empty-pag e fill");
79 var pageTitle = emptyPage.createChild("div", "documentation-not-found"); 85 var pageTitle = emptyPage.createChild("div", "documentation-not-found");
80 pageTitle.textContent = "No documentation found."; 86 pageTitle.textContent = "No documentation found.";
81 emptyPage.createChild("div", "documentation-empty-page-align"); 87 emptyPage.createChild("div", "documentation-empty-page-align");
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 if (!method) 170 if (!method)
165 return; 171 return;
166 var section = this._element.createChild("p", "documentation-section"); 172 var section = this._element.createChild("p", "documentation-section");
167 var signature = section.createChild("span", "documentation-method-signat ure documentation-section-content monospace"); 173 var signature = section.createChild("span", "documentation-method-signat ure documentation-section-content monospace");
168 var methodName = signature.createChild("span", "documentation-method-nam e"); 174 var methodName = signature.createChild("span", "documentation-method-nam e");
169 methodName.textContent = this._searchItem.split(".").peekLast() + "("; 175 methodName.textContent = this._searchItem.split(".").peekLast() + "(";
170 for (var i = 0; i < parameters.length; ++i) { 176 for (var i = 0; i < parameters.length; ++i) {
171 if (i > 0) 177 if (i > 0)
172 signature.createTextChild(", ") 178 signature.createTextChild(", ")
173 var parameterType = signature.createChild("span", "documentation-par ameter-data-type-value"); 179 var parameterType = signature.createChild("span", "documentation-par ameter-data-type-value");
174 parameterType.textContent = parameters[i].dataType + (parameters[i]. optional ? "=" : "");; 180 parameterType.textContent = parameters[i].dataType + (parameters[i]. optional ? "=" : "");;
apavlov 2014/09/11 10:40:26 extra trailing ;
iliia 2014/09/11 13:26:28 Done.
175 } 181 }
176 signature.createTextChild("): "); 182 signature.createTextChild("): ");
177 var returnTypeElement = signature.createChild("span", "documentation-par ameter-data-type-value"); 183 var returnTypeElement = signature.createChild("span", "documentation-par ameter-data-type-value");
178 returnTypeElement.textContent = method.returnValueName; 184 returnTypeElement.textContent = method.returnValueName;
179 }, 185 },
180 186
181 /** 187 /**
182 * @param {!Array.<!WebInspector.JSArticle.Parameter>} parameters 188 * @param {!Array.<!WebInspector.JSArticle.Parameter>} parameters
183 */ 189 */
184 _createParametersSection: function(parameters) 190 _createParametersSection: function(parameters)
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 code.textContent = examples[i].code; 257 code.textContent = examples[i].code;
252 if (!examples[i].language) 258 if (!examples[i].language)
253 continue; 259 continue;
254 var syntaxHighlighter = new WebInspector.DOMSyntaxHighlighter(WebIns pector.DocumentationView._languageToMimeType[examples[i].language.toLowerCase()] , true); 260 var syntaxHighlighter = new WebInspector.DOMSyntaxHighlighter(WebIns pector.DocumentationView._languageToMimeType[examples[i].language.toLowerCase()] , true);
255 syntaxHighlighter.syntaxHighlightNode(code); 261 syntaxHighlighter.syntaxHighlightNode(code);
256 } 262 }
257 }, 263 },
258 264
259 /** 265 /**
260 * @param {!WebInspector.WikiParser.ArticleElement} article 266 * @param {!WebInspector.WikiParser.ArticleElement} article
261 * @return {!Element} 267 * @return {?Element}
262 */ 268 */
263 _renderBlock: function(article) 269 _renderBlock: function(article)
264 { 270 {
265 var element; 271 var element = null;
266 var elementTypes = WebInspector.WikiParser.ArticleElement.Type; 272 var elementTypes = WebInspector.WikiParser.ArticleElement.Type;
267 273
268 switch (article.type()) { 274 switch (article.type()) {
269 case elementTypes.Inline: 275 case elementTypes.Inline:
270 element = document.createElement("span"); 276 element = document.createElement("span");
271 break; 277 break;
272 case elementTypes.Link: 278 case elementTypes.Link:
273 element = document.createElementWithClass("a", "documentation-link") ; 279 element = document.createElementWithClass("a", "documentation-link") ;
274 element.href = article.url(); 280 element.href = article.url();
275 if (!article.children().length) 281 if (!article.children().length)
276 element.textContent = article.url(); 282 element.textContent = article.url();
277 break; 283 break;
278 case elementTypes.Code: 284 case elementTypes.Code:
279 element = document.createElementWithClass("span", "documentation-cod e-tag"); 285 element = document.createElementWithClass("span", "documentation-cod e-tag");
280 break; 286 break;
281 case elementTypes.CodeBlock: 287 case elementTypes.CodeBlock:
282 element = document.createElementWithClass("pre", "documentation-code source-code"); 288 element = document.createElementWithClass("pre", "documentation-code source-code");
283 element.textContent = article.code(); 289 element.textContent = article.code();
284 break; 290 break;
285 case elementTypes.PlainText: 291 case elementTypes.PlainText:
286 element = document.createElement("span"); 292 element = document.createElement("span");
287 element.textContent = article.text(); 293 element.textContent = article.text();
288 if (article.isHighlighted()) 294 if (article.isHighlighted())
289 element.classList.add("documentation-highlighted-text"); 295 element.classList.add("documentation-highlighted-text");
290 break; 296 break;
291 default:
292 console.error("Unknown ArticleElement type " + article.type());
293 case elementTypes.Block: 297 case elementTypes.Block:
294 element = document.createElement(article.hasBullet() ? "li" : "p"); 298 element = document.createElement(article.hasBullet() ? "li" : "p");
295 break; 299 break;
300 default:
301 console.error("Unknown ArticleElement type " + article.type());
296 } 302 }
297 303
298 if (article instanceof WebInspector.WikiParser.Block || article instance of WebInspector.WikiParser.Inline) { 304 if (article.type() === WebInspector.WikiParser.ArticleElement.Type.Block
305 || article.type() === WebInspector.WikiParser.ArticleElement.Type.Co de
306 || article.type() === WebInspector.WikiParser.ArticleElement.Type.In line) {
299 for (var i = 0; i < article.children().length; ++i) { 307 for (var i = 0; i < article.children().length; ++i) {
300 var child = this._renderBlock(article.children()[i]); 308 var child = this._renderBlock(article.children()[i]);
301 if (child) 309 if (child)
302 element.appendChild(child); 310 element.appendChild(child);
303 } 311 }
304 } 312 }
305 313
306 return element; 314 return element;
307 } 315 }
308 } 316 }
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
370 function computeDescriptors(column) 378 function computeDescriptors(column)
371 { 379 {
372 var token = textEditor.tokenAtTextPosition(textSelection.startLine, column); 380 var token = textEditor.tokenAtTextPosition(textSelection.startLine, column);
373 if (!token) 381 if (!token)
374 return []; 382 return [];
375 var tokenText = textEditor.line(textSelection.startLine).substring(t oken.startColumn, token.endColumn); 383 var tokenText = textEditor.line(textSelection.startLine).substring(t oken.startColumn, token.endColumn);
376 return urlProvider.itemDescriptors(tokenText); 384 return urlProvider.itemDescriptors(tokenText);
377 } 385 }
378 } 386 }
379 } 387 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698