| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 /** | 5 /** |
| 6 * To use it, from this directory, run: | 6 * To use it, from this directory, run: |
| 7 * | 7 * |
| 8 * $ ./dartdoc <path to .dart file> | 8 * $ ./dartdoc <path to .dart file> |
| 9 * | 9 * |
| 10 * This will create a "docs" directory with the docs for your libraries. To | 10 * This will create a "docs" directory with the docs for your libraries. To |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 * this is `null` then no search box will be shown. | 126 * this is `null` then no search box will be shown. |
| 127 */ | 127 */ |
| 128 String searchEngineId = null; | 128 String searchEngineId = null; |
| 129 | 129 |
| 130 /* The URL that the embedded search results should be displayed on. */ | 130 /* The URL that the embedded search results should be displayed on. */ |
| 131 String searchResultsUrl = 'results.html'; | 131 String searchResultsUrl = 'results.html'; |
| 132 | 132 |
| 133 /** Set this to add footer text to each generated page. */ | 133 /** Set this to add footer text to each generated page. */ |
| 134 String footerText = ''; | 134 String footerText = ''; |
| 135 | 135 |
| 136 /** |
| 137 * From exposes the set of libraries in `world.libraries`. That maps library |
| 138 * *keys* to [Library] objects. The keys are *not* exactly the same as their |
| 139 * names. This means if we order by key, we won't actually have them sorted |
| 140 * correctly. This list contains the libraries in correct order by their |
| 141 * *name*. |
| 142 */ |
| 143 List<Library> _sortedLibraries; |
| 144 |
| 136 CommentMap _comments; | 145 CommentMap _comments; |
| 137 | 146 |
| 138 /** The library that we're currently generating docs for. */ | 147 /** The library that we're currently generating docs for. */ |
| 139 Library _currentLibrary; | 148 Library _currentLibrary; |
| 140 | 149 |
| 141 /** The type that we're currently generating docs for. */ | 150 /** The type that we're currently generating docs for. */ |
| 142 Type _currentType; | 151 Type _currentType; |
| 143 | 152 |
| 144 /** The member that we're currently generating docs for. */ | 153 /** The member that we're currently generating docs for. */ |
| 145 Member _currentMember; | 154 Member _currentMember; |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 world.process(); | 206 world.process(); |
| 198 break; | 207 break; |
| 199 | 208 |
| 200 default: | 209 default: |
| 201 // Normal entrypoint script. | 210 // Normal entrypoint script. |
| 202 world.processDartScript(entrypoint); | 211 world.processDartScript(entrypoint); |
| 203 } | 212 } |
| 204 | 213 |
| 205 world.resolveAll(); | 214 world.resolveAll(); |
| 206 | 215 |
| 216 // Sort the libraries by name (not key). |
| 217 _sortedLibraries = world.libraries.getValues(); |
| 218 _sortedLibraries.sort((a, b) { |
| 219 return a.name.toUpperCase().compareTo(b.name.toUpperCase()); |
| 220 }); |
| 221 |
| 207 // Generate the docs. | 222 // Generate the docs. |
| 208 if (mode == MODE_LIVE_NAV) docNavigationJson(); | 223 if (mode == MODE_LIVE_NAV) docNavigationJson(); |
| 209 | 224 |
| 210 docIndex(); | 225 docIndex(); |
| 211 for (final library in world.libraries.getValues()) { | 226 for (final library in _sortedLibraries) { |
| 212 docLibrary(library); | 227 docLibrary(library); |
| 213 } | 228 } |
| 214 } finally { | 229 } finally { |
| 215 options.dietParse = oldDietParse; | 230 options.dietParse = oldDietParse; |
| 216 } | 231 } |
| 217 } | 232 } |
| 218 | 233 |
| 219 void startFile(String path) { | 234 void startFile(String path) { |
| 220 _filePath = path; | 235 _filePath = path; |
| 221 _file = new StringBuffer(); | 236 _file = new StringBuffer(); |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 340 } | 355 } |
| 341 | 356 |
| 342 void docIndex() { | 357 void docIndex() { |
| 343 startFile('index.html'); | 358 startFile('index.html'); |
| 344 | 359 |
| 345 writeHeader(mainTitle, []); | 360 writeHeader(mainTitle, []); |
| 346 | 361 |
| 347 writeln('<h2>$mainTitle</h2>'); | 362 writeln('<h2>$mainTitle</h2>'); |
| 348 writeln('<h3>Libraries</h3>'); | 363 writeln('<h3>Libraries</h3>'); |
| 349 | 364 |
| 350 for (final library in orderByName(world.libraries)) { | 365 for (final library in _sortedLibraries) { |
| 351 docIndexLibrary(library); | 366 docIndexLibrary(library); |
| 352 } | 367 } |
| 353 | 368 |
| 354 writeFooter(); | 369 writeFooter(); |
| 355 endFile(); | 370 endFile(); |
| 356 } | 371 } |
| 357 | 372 |
| 358 void docIndexLibrary(Library library) { | 373 void docIndexLibrary(Library library) { |
| 359 writeln('<h4>${a(libraryUrl(library), library.name)}</h4>'); | 374 writeln('<h4>${a(libraryUrl(library), library.name)}</h4>'); |
| 360 } | 375 } |
| 361 | 376 |
| 362 /** | 377 /** |
| 363 * Walks the libraries and creates a JSON object containing the data needed | 378 * Walks the libraries and creates a JSON object containing the data needed |
| 364 * to generate navigation for them. | 379 * to generate navigation for them. |
| 365 */ | 380 */ |
| 366 void docNavigationJson() { | 381 void docNavigationJson() { |
| 367 startFile('nav.json'); | 382 startFile('nav.json'); |
| 368 | 383 |
| 369 final libraries = {}; | 384 final libraries = {}; |
| 370 | 385 |
| 371 for (final library in orderByName(world.libraries)) { | 386 for (final library in _sortedLibraries) { |
| 372 docLibraryNavigationJson(library, libraries); | 387 docLibraryNavigationJson(library, libraries); |
| 373 } | 388 } |
| 374 | 389 |
| 375 writeln(JSON.stringify(libraries)); | 390 writeln(JSON.stringify(libraries)); |
| 376 endFile(); | 391 endFile(); |
| 377 } | 392 } |
| 378 | 393 |
| 379 void docLibraryNavigationJson(Library library, Map libraries) { | 394 void docLibraryNavigationJson(Library library, Map libraries) { |
| 380 final types = []; | 395 final types = []; |
| 381 | 396 |
| 382 for (final type in orderByName(library.types)) { | 397 for (final type in orderByName(library.types)) { |
| 383 if (type.isTop) continue; | 398 if (type.isTop) continue; |
| 384 if (type.name.startsWith('_')) continue; | 399 if (type.name.startsWith('_')) continue; |
| 385 | 400 |
| 386 final kind = type.isClass ? 'class' : 'interface'; | 401 final kind = type.isClass ? 'class' : 'interface'; |
| 387 final url = typeUrl(type); | 402 final url = typeUrl(type); |
| 388 types.add({ 'name': typeName(type), 'kind': kind, 'url': url }); | 403 types.add({ 'name': typeName(type), 'kind': kind, 'url': url }); |
| 389 } | 404 } |
| 390 | 405 |
| 391 libraries[library.name] = types; | 406 libraries[library.name] = types; |
| 392 } | 407 } |
| 393 | 408 |
| 394 void docNavigation() { | 409 void docNavigation() { |
| 395 writeln( | 410 writeln( |
| 396 ''' | 411 ''' |
| 397 <div class="nav"> | 412 <div class="nav"> |
| 398 '''); | 413 '''); |
| 399 | 414 |
| 400 if (mode == MODE_STATIC) { | 415 if (mode == MODE_STATIC) { |
| 401 for (final library in orderByName(world.libraries)) { | 416 for (final library in _sortedLibraries) { |
| 402 write('<h2><div class="icon-library"></div>'); | 417 write('<h2><div class="icon-library"></div>'); |
| 403 | 418 |
| 404 if ((_currentLibrary == library) && (_currentType == null)) { | 419 if ((_currentLibrary == library) && (_currentType == null)) { |
| 405 write('<strong>${library.name}</strong>'); | 420 write('<strong>${library.name}</strong>'); |
| 406 } else { | 421 } else { |
| 407 write('${a(libraryUrl(library), library.name)}'); | 422 write('${a(libraryUrl(library), library.name)}'); |
| 408 } | 423 } |
| 409 write('</h2>'); | 424 write('</h2>'); |
| 410 | 425 |
| 411 // Only expand classes in navigation for current library. | 426 // Only expand classes in navigation for current library. |
| (...skipping 774 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1186 | 1201 |
| 1187 return new md.Element.text('code', name); | 1202 return new md.Element.text('code', name); |
| 1188 } | 1203 } |
| 1189 | 1204 |
| 1190 // TODO(rnystrom): Move into SourceSpan? | 1205 // TODO(rnystrom): Move into SourceSpan? |
| 1191 int getSpanColumn(SourceSpan span) { | 1206 int getSpanColumn(SourceSpan span) { |
| 1192 final line = span.file.getLine(span.start); | 1207 final line = span.file.getLine(span.start); |
| 1193 return span.file.getColumn(line, span.start); | 1208 return span.file.getColumn(line, span.start); |
| 1194 } | 1209 } |
| 1195 } | 1210 } |
| OLD | NEW |