OLD | NEW |
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; | 6 library client; |
7 | 7 |
8 import 'dart:html'; | 8 import 'dart:html'; |
9 import 'dart:json' as jsonlib; | 9 import 'dart:json' as jsonlib; |
10 import '../../../../compiler/implementation/source_file.dart'; | 10 import '../../../../compiler/implementation/source_file.dart'; |
(...skipping 19 matching lines...) Expand all Loading... |
30 | 30 |
31 /** | 31 /** |
32 * Takes [libraries], a JSON array representing a set of libraries and builds | 32 * Takes [libraries], a JSON array representing a set of libraries and builds |
33 * the appropriate navigation DOM for it relative to the current library and | 33 * the appropriate navigation DOM for it relative to the current library and |
34 * type. | 34 * type. |
35 */ | 35 */ |
36 buildNavigation(List libraries) { | 36 buildNavigation(List libraries) { |
37 final html = new StringBuffer(); | 37 final html = new StringBuffer(); |
38 for (Map libraryInfo in libraries) { | 38 for (Map libraryInfo in libraries) { |
39 String libraryName = libraryInfo[NAME]; | 39 String libraryName = libraryInfo[NAME]; |
40 html.add('<h2><div class="icon-library"></div>'); | 40 html.write('<h2><div class="icon-library"></div>'); |
41 if (currentLibrary == libraryName && currentType == null) { | 41 if (currentLibrary == libraryName && currentType == null) { |
42 html.add('<strong>${md.escapeHtml(libraryName)}</strong>'); | 42 html.write('<strong>${md.escapeHtml(libraryName)}</strong>'); |
43 } else { | 43 } else { |
44 final url = getLibraryUrl(libraryName); | 44 final url = getLibraryUrl(libraryName); |
45 html.add('<a href="$url">${md.escapeHtml(libraryName)}</a>'); | 45 html.write('<a href="$url">${md.escapeHtml(libraryName)}</a>'); |
46 } | 46 } |
47 html.add('</h2>'); | 47 html.write('</h2>'); |
48 | 48 |
49 // Only list the types for the current library. | 49 // Only list the types for the current library. |
50 if (currentLibrary == libraryName && libraryInfo.containsKey(TYPES)) { | 50 if (currentLibrary == libraryName && libraryInfo.containsKey(TYPES)) { |
51 buildLibraryNavigation(html, libraryInfo); | 51 buildLibraryNavigation(html, libraryInfo); |
52 } | 52 } |
53 } | 53 } |
54 | 54 |
55 // Insert it into the DOM. | 55 // Insert it into the DOM. |
56 final navElement = document.query('.nav'); | 56 final navElement = document.query('.nav'); |
57 navElement.innerHtml = html.toString(); | 57 navElement.innerHtml = html.toString(); |
(...skipping 10 matching lines...) Expand all Loading... |
68 if (name.endsWith('Exception') || name.endsWith('Error')) { | 68 if (name.endsWith('Exception') || name.endsWith('Error')) { |
69 exceptions.add(typeInfo); | 69 exceptions.add(typeInfo); |
70 } else { | 70 } else { |
71 types.add(typeInfo); | 71 types.add(typeInfo); |
72 } | 72 } |
73 } | 73 } |
74 | 74 |
75 if (types.length == 0 && exceptions.length == 0) return; | 75 if (types.length == 0 && exceptions.length == 0) return; |
76 | 76 |
77 writeType(String icon, Map typeInfo) { | 77 writeType(String icon, Map typeInfo) { |
78 html.add('<li>'); | 78 html.write('<li>'); |
79 if (currentType == typeInfo[NAME]) { | 79 if (currentType == typeInfo[NAME]) { |
80 html.add( | 80 html.write( |
81 '<div class="icon-$icon"></div><strong>${getTypeName(typeInfo)}</stron
g>'); | 81 '<div class="icon-$icon"></div><strong>${getTypeName(typeInfo)}</stron
g>'); |
82 } else { | 82 } else { |
83 html.add( | 83 html.write( |
84 ''' | 84 ''' |
85 <a href="${getTypeUrl(currentLibrary, typeInfo)}"> | 85 <a href="${getTypeUrl(currentLibrary, typeInfo)}"> |
86 <div class="icon-$icon"></div>${getTypeName(typeInfo)} | 86 <div class="icon-$icon"></div>${getTypeName(typeInfo)} |
87 </a> | 87 </a> |
88 '''); | 88 '''); |
89 } | 89 } |
90 html.add('</li>'); | 90 html.write('</li>'); |
91 } | 91 } |
92 | 92 |
93 html.add('<ul class="icon">'); | 93 html.write('<ul class="icon">'); |
94 types.forEach((typeInfo) => | 94 types.forEach((typeInfo) => |
95 writeType(kindToString(typeInfo[KIND]), typeInfo)); | 95 writeType(kindToString(typeInfo[KIND]), typeInfo)); |
96 exceptions.forEach((typeInfo) => writeType('exception', typeInfo)); | 96 exceptions.forEach((typeInfo) => writeType('exception', typeInfo)); |
97 html.add('</ul>'); | 97 html.write('</ul>'); |
98 } | 98 } |
OLD | NEW |