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 /** | 5 /** |
6 * To generate docs for a library, run this script with the path to an | 6 * To generate docs for a library, run this script with the path to an |
7 * entrypoint .dart file, like: | 7 * entrypoint .dart file, like: |
8 * | 8 * |
9 * $ dart dartdoc.dart foo.dart | 9 * $ dart dartdoc.dart foo.dart |
10 * | 10 * |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
222 } | 222 } |
223 | 223 |
224 /** | 224 /** |
225 * Gets the full path to the directory containing the entrypoint of the current | 225 * Gets the full path to the directory containing the entrypoint of the current |
226 * script. In other words, if you invoked dartdoc, directly, it will be the | 226 * script. In other words, if you invoked dartdoc, directly, it will be the |
227 * path to the directory containing `dartdoc.dart`. If you're running a script | 227 * path to the directory containing `dartdoc.dart`. If you're running a script |
228 * that imports dartdoc, it will be the path to that script. | 228 * that imports dartdoc, it will be the path to that script. |
229 */ | 229 */ |
230 // TODO(johnniwinther): Convert to final (lazily initialized) variables when | 230 // TODO(johnniwinther): Convert to final (lazily initialized) variables when |
231 // the feature is supported. | 231 // the feature is supported. |
232 Path get scriptDir() => | 232 Path get scriptDir => |
233 new Path.fromNative(new Options().script).directoryPath; | 233 new Path.fromNative(new Options().script).directoryPath; |
234 | 234 |
235 // TODO(johnniwinther): Trailing slashes matter due to the use of [libPath] as | 235 // TODO(johnniwinther): Trailing slashes matter due to the use of [libPath] as |
236 // a base URI with [Uri.resolve]. | 236 // a base URI with [Uri.resolve]. |
237 /// Relative path to the library in which dart2js resides. | 237 /// Relative path to the library in which dart2js resides. |
238 Path get libPath() => IN_SDK | 238 Path get libPath => IN_SDK |
239 ? scriptDir.append('../../lib/dart2js/') | 239 ? scriptDir.append('../../lib/dart2js/') |
240 : scriptDir.append('../../'); | 240 : scriptDir.append('../../'); |
241 | 241 |
242 /** | 242 /** |
243 * Deletes and recreates the output directory at [path] if it exists. | 243 * Deletes and recreates the output directory at [path] if it exists. |
244 */ | 244 */ |
245 void cleanOutputDirectory(Path path) { | 245 void cleanOutputDirectory(Path path) { |
246 final outputDir = new Directory.fromPath(path); | 246 final outputDir = new Directory.fromPath(path); |
247 if (outputDir.existsSync()) { | 247 if (outputDir.existsSync()) { |
248 outputDir.deleteRecursivelySync(); | 248 outputDir.deleteRecursivelySync(); |
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
444 String suffix = libraryName.substring('dart:'.length); | 444 String suffix = libraryName.substring('dart:'.length); |
445 LibraryInfo info = LIBRARIES[suffix]; | 445 LibraryInfo info = LIBRARIES[suffix]; |
446 if (info != null) { | 446 if (info != null) { |
447 return info.documented; | 447 return info.documented; |
448 } | 448 } |
449 } | 449 } |
450 } | 450 } |
451 return false; | 451 return false; |
452 } | 452 } |
453 | 453 |
454 String get footerContent(){ | 454 String get footerContent{ |
455 var footerItems = []; | 455 var footerItems = []; |
456 if (!omitGenerationTime) { | 456 if (!omitGenerationTime) { |
457 footerItems.add("This page was generated at ${new Date.now()}"); | 457 footerItems.add("This page was generated at ${new Date.now()}"); |
458 } | 458 } |
459 if (footerText != null) { | 459 if (footerText != null) { |
460 footerItems.add(footerText); | 460 footerItems.add(footerText); |
461 } | 461 } |
462 var content = ''; | 462 var content = ''; |
463 for (int i = 0; i < footerItems.length; i++) { | 463 for (int i = 0; i < footerItems.length; i++) { |
464 if (i > 0) { | 464 if (i > 0) { |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
616 writeln( | 616 writeln( |
617 ''' | 617 ''' |
618 </div> | 618 </div> |
619 <div class="drop-down" id="drop-down"></div> | 619 <div class="drop-down" id="drop-down"></div> |
620 '''); | 620 '''); |
621 | 621 |
622 docNavigation(); | 622 docNavigation(); |
623 writeln('<div class="content">'); | 623 writeln('<div class="content">'); |
624 } | 624 } |
625 | 625 |
626 String get clientScript() { | 626 String get clientScript { |
627 switch (mode) { | 627 switch (mode) { |
628 case MODE_STATIC: return 'client-static'; | 628 case MODE_STATIC: return 'client-static'; |
629 case MODE_LIVE_NAV: return 'client-live-nav'; | 629 case MODE_LIVE_NAV: return 'client-live-nav'; |
630 default: throw 'Unknown mode $mode.'; | 630 default: throw 'Unknown mode $mode.'; |
631 } | 631 } |
632 } | 632 } |
633 | 633 |
634 void writeHeadContents(String title) { | 634 void writeHeadContents(String title) { |
635 writeln( | 635 writeln( |
636 ''' | 636 ''' |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
697 try { | 697 try { |
698 dir.createSync(); | 698 dir.createSync(); |
699 } on DirectoryIOException catch (e) { | 699 } on DirectoryIOException catch (e) { |
700 // Ignore. | 700 // Ignore. |
701 } | 701 } |
702 } | 702 } |
703 String jsonString = JSON.stringify(createNavigationInfo()); | 703 String jsonString = JSON.stringify(createNavigationInfo()); |
704 String dartString = jsonString.replaceAll(@"$", @"\$"); | 704 String dartString = jsonString.replaceAll(@"$", @"\$"); |
705 final filePath = tmpPath.append('nav.dart'); | 705 final filePath = tmpPath.append('nav.dart'); |
706 writeString(new File.fromPath(filePath), | 706 writeString(new File.fromPath(filePath), |
707 'get json() => $dartString;'); | 707 'get json => $dartString;'); |
708 } | 708 } |
709 | 709 |
710 Path get tmpPath() => dartdocPath.append('tmp'); | 710 Path get tmpPath => dartdocPath.append('tmp'); |
711 | 711 |
712 void cleanup() { | 712 void cleanup() { |
713 final dir = new Directory.fromPath(tmpPath); | 713 final dir = new Directory.fromPath(tmpPath); |
714 if (dir.existsSync()) { | 714 if (dir.existsSync()) { |
715 dir.deleteRecursivelySync(); | 715 dir.deleteRecursivelySync(); |
716 } | 716 } |
717 } | 717 } |
718 | 718 |
719 List createNavigationInfo() { | 719 List createNavigationInfo() { |
720 final libraryList = []; | 720 final libraryList = []; |
(...skipping 999 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1720 } | 1720 } |
1721 | 1721 |
1722 /** | 1722 /** |
1723 * Returns [:true:] if [type] should be regarded as an exception. | 1723 * Returns [:true:] if [type] should be regarded as an exception. |
1724 */ | 1724 */ |
1725 bool isException(TypeMirror type) { | 1725 bool isException(TypeMirror type) { |
1726 return type.simpleName.endsWith('Exception'); | 1726 return type.simpleName.endsWith('Exception'); |
1727 } | 1727 } |
1728 } | 1728 } |
1729 | 1729 |
OLD | NEW |