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

Side by Side Diff: pkg/dartdoc/client-live-nav.dart

Issue 10829361: 'Find-as-you-type'-search in dartdoc/apidoc. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Rebased Created 8 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | pkg/dartdoc/client-shared.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 /** Provides client-side behavior for generated docs. */ 5 /** Provides client-side behavior for generated docs. */
6 #library('client-live-nav'); 6 #library('client-live-nav');
7 7
8 #import('dart:html'); 8 #import('dart:html');
9 #import('dart:json'); 9 #import('dart:json');
10 #import('../../lib/compiler/implementation/source_file.dart'); 10 #import('../../lib/compiler/implementation/source_file.dart');
11 #import('classify.dart'); 11 #import('classify.dart');
12 #import('markdown.dart', prefix: 'md'); 12 #import('markdown.dart', prefix: 'md');
13 13
14 #source('dropdown.dart');
15 #source('search.dart');
16 #source('nav.dart');
14 #source('client-shared.dart'); 17 #source('client-shared.dart');
15 18
16 // The names of the library and type that this page documents.
17 String currentLibrary = null;
18 String currentType = null;
19
20 // What we need to prefix relative URLs with to get them to work.
21 String prefix = '';
22
23 main() { 19 main() {
24 // Figure out where we are. 20 setupLocation();
25 final body = document.query('body');
26 currentLibrary = body.dataAttributes['library'];
27 currentType = body.dataAttributes['type'];
28 prefix = (currentType != null) ? '../' : '';
29 21
30 enableCodeBlocks(); 22 enableCodeBlocks();
31 23
32 // Request the navigation data so we can build the HTML for it. 24 // Request the navigation data so we can build the HTML for it.
33 new HttpRequest.get('${prefix}nav.json', (request) { 25 new HttpRequest.get('${prefix}nav.json', (request) {
34 buildNavigation(JSON.parse(request.responseText)); 26 var json = JSON.parse(request.responseText);
27 buildNavigation(json);
28 setupSearch(json);
35 }); 29 });
36 } 30 }
37 31
38 /** Turns [name] into something that's safe to use as a file name. */
39 String sanitize(String name) => name.replaceAll(':', '_').replaceAll('/', '_');
40 32
41 /** 33 /**
42 * Takes [libraries], a JSON object representing a set of libraries and builds 34 * Takes [libraries], a JSON array representing a set of libraries and builds
43 * the appropriate navigation DOM for it relative to the current library and 35 * the appropriate navigation DOM for it relative to the current library and
44 * type. 36 * type.
45 */ 37 */
46 buildNavigation(libraries) { 38 buildNavigation(List libraries) {
47 final libraryNames = libraries.getKeys();
48 libraryNames.sort((a, b) => a.compareTo(b));
49
50 final html = new StringBuffer(); 39 final html = new StringBuffer();
51 for (final libraryName in libraryNames) { 40 for (Map libraryInfo in libraries) {
41 String libraryName = libraryInfo[NAME];
52 html.add('<h2><div class="icon-library"></div>'); 42 html.add('<h2><div class="icon-library"></div>');
53 if (currentLibrary == libraryName && currentType == null) { 43 if (currentLibrary == libraryName && currentType == null) {
54 html.add('<strong>${md.escapeHtml(libraryName)}</strong>'); 44 html.add('<strong>${md.escapeHtml(libraryName)}</strong>');
55 } else { 45 } else {
56 final url = '$prefix${sanitize(libraryName)}.html'; 46 final url = getLibraryUrl(libraryName);
57 html.add('<a href="$url">${md.escapeHtml(libraryName)}</a>'); 47 html.add('<a href="$url">${md.escapeHtml(libraryName)}</a>');
58 } 48 }
59 html.add('</h2>'); 49 html.add('</h2>');
60 50
61 // Only list the types for the current library. 51 // Only list the types for the current library.
62 if (currentLibrary == libraryName) { 52 if (currentLibrary == libraryName && libraryInfo.containsKey(TYPES)) {
63 buildLibraryNavigation(html, libraries[libraryName]); 53 buildLibraryNavigation(html, libraryInfo);
64 } 54 }
65 } 55 }
66 56
67 // Insert it into the DOM. 57 // Insert it into the DOM.
68 final navElement = document.query('.nav'); 58 final navElement = document.query('.nav');
69 navElement.innerHTML = html.toString(); 59 navElement.innerHTML = html.toString();
70 } 60 }
71 61
72 /** Writes the navigation for the types contained by [library] to [html]. */ 62 /** Writes the navigation for the types contained by [library] to [html]. */
73 buildLibraryNavigation(StringBuffer html, library) { 63 buildLibraryNavigation(StringBuffer html, Map libraryInfo) {
74 // Show the exception types separately. 64 // Show the exception types separately.
75 final types = []; 65 final types = [];
76 final exceptions = []; 66 final exceptions = [];
77 67
78 for (final type in library) { 68 for (Map typeInfo in libraryInfo[TYPES]) {
79 if (type['name'].endsWith('Exception')) { 69 if (typeInfo[NAME].endsWith('Exception')) {
80 exceptions.add(type); 70 exceptions.add(typeInfo);
81 } else { 71 } else {
82 types.add(type); 72 types.add(typeInfo);
83 } 73 }
84 } 74 }
85 75
86 if (types.length == 0 && exceptions.length == 0) return; 76 if (types.length == 0 && exceptions.length == 0) return;
87 77
88 writeType(String icon, type) { 78 writeType(String icon, Map typeInfo) {
89 html.add('<li>'); 79 html.add('<li>');
90 if (currentType == type['name']) { 80 if (currentType == typeInfo[NAME]) {
91 html.add( 81 html.add(
92 '<div class="icon-$icon"></div><strong>${type["name"]}</strong>'); 82 '<div class="icon-$icon"></div><strong>${getTypeName(typeInfo)}</stron g>');
93 } else { 83 } else {
94 html.add( 84 html.add(
95 ''' 85 '''
96 <a href="$prefix${type["url"]}"> 86 <a href="${getTypeUrl(currentLibrary, typeInfo)}">
97 <div class="icon-$icon"></div>${type["name"]} 87 <div class="icon-$icon"></div>${getTypeName(typeInfo)}
98 </a> 88 </a>
99 '''); 89 ''');
100 } 90 }
101 html.add('</li>'); 91 html.add('</li>');
102 } 92 }
103 93
104 html.add('<ul class="icon">'); 94 html.add('<ul class="icon">');
105 types.forEach((type) => writeType(type['kind'], type)); 95 types.forEach((typeInfo) =>
106 exceptions.forEach((type) => writeType('exception', type)); 96 writeType(kindToString(typeInfo[KIND]), typeInfo));
97 exceptions.forEach((typeInfo) => writeType('exception', typeInfo));
107 html.add('</ul>'); 98 html.add('</ul>');
108 } 99 }
OLDNEW
« no previous file with comments | « no previous file | pkg/dartdoc/client-shared.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698