Chromium Code Reviews| 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 /** An awesome documentation generator. */ | 5 /** An awesome documentation generator. */ |
| 6 #library('dartdoc'); | 6 #library('dartdoc'); |
| 7 | 7 |
| 8 #import('../../frog/lang.dart'); | 8 #import('../../frog/lang.dart'); |
| 9 #import('../../frog/file_system.dart'); | |
| 9 #import('../../frog/file_system_node.dart'); | 10 #import('../../frog/file_system_node.dart'); |
| 10 | 11 |
| 11 #source('classify.dart'); | 12 #source('classify.dart'); |
| 12 | 13 |
| 13 /** Path to corePath library. */ | 14 /** Path to corePath library. */ |
| 14 final corePath = 'lib'; | 15 final corePath = 'lib'; |
| 15 | 16 |
| 16 /** Path to generate html files into. */ | 17 /** Path to generate html files into. */ |
| 17 final outdir = 'docs'; | 18 final outdir = 'docs'; |
| 18 | 19 |
| 19 /** Special comment position used to store the library-level doc comment. */ | 20 /** Special comment position used to store the library-level doc comment. */ |
| 20 final _libraryDoc = -1; | 21 final _libraryDoc = -1; |
| 21 | 22 |
| 22 /** The file currently being written to. */ | 23 /** The file currently being written to. */ |
| 23 StringBuffer _file; | 24 StringBuffer _file; |
| 24 | 25 |
| 25 /** | 26 /** |
| 26 * The cached lookup-table to associate doc comments with spans. The outer map | 27 * The cached lookup-table to associate doc comments with spans. The outer map |
| 27 * is from filenames to doc comments in that file. The inner map maps from the | 28 * is from filenames to doc comments in that file. The inner map maps from the |
| 28 * token positions to doc comments. Each position is the starting offset of the | 29 * token positions to doc comments. Each position is the starting offset of the |
| 29 * next non-comment token *following* the doc comment. For example, the position | 30 * next non-comment token *following* the doc comment. For example, the position |
| 30 * for this comment would be the position of the "Map" token below. | 31 * for this comment would be the position of the "Map" token below. |
| 31 */ | 32 */ |
| 32 Map<String, Map<int, String>> _comments; | 33 Map<String, Map<int, String>> _comments; |
| 33 | 34 |
| 34 int _totalLibraries = 0; | 35 int _totalLibraries = 0; |
| 35 int _totalTypes = 0; | 36 int _totalTypes = 0; |
| 36 int _totalMembers = 0; | 37 int _totalMembers = 0; |
| 37 | 38 |
| 39 FileSystem files; | |
| 40 | |
| 38 /** | 41 /** |
| 39 * Run this from the frog/samples directory. Before running, you need | 42 * Run this from the frog/samples directory. Before running, you need |
| 40 * to create a docs dir with 'mkdir docs' - since Dart currently doesn't | 43 * to create a docs dir with 'mkdir docs' - since Dart currently doesn't |
| 41 * support creating new directories. | 44 * support creating new directories. |
| 42 */ | 45 */ |
| 43 void main() { | 46 void main() { |
| 44 // The entrypoint of the library to generate docs for. | 47 // The entrypoint of the library to generate docs for. |
| 45 final libPath = process.argv[2]; | 48 final libPath = process.argv[2]; |
| 46 | 49 |
| 47 // TODO(rnystrom): Get options and homedir like frog.dart does. | 50 files = new NodeFileSystem(); |
| 48 final files = new NodeFileSystem(); | |
| 49 parseOptions('../../frog', [] /* args */, files); | 51 parseOptions('../../frog', [] /* args */, files); |
| 50 | 52 |
| 51 final elapsed = time(() { | 53 final elapsed = time(() { |
| 54 _comments = <String, Map<int, String>>{}; | |
| 55 | |
| 52 initializeWorld(files); | 56 initializeWorld(files); |
| 53 | 57 |
| 54 world.processScript(libPath); | 58 world.processScript(libPath); |
| 55 world.resolveAll(); | 59 world.resolveAll(); |
| 56 | 60 |
| 57 _comments = <String, Map<int, String>>{}; | 61 // Clean the output directory. |
| 62 if (files.fileExists(outdir)) { | |
| 63 files.removeDirectory(outdir, recursive: true); | |
| 64 } | |
| 65 files.createDirectory(outdir, recursive: true); | |
| 58 | 66 |
| 67 // Copy over the static files. | |
| 68 for (final file in ['interact.js', 'styles.css']) { | |
| 69 copyStatic(file); | |
| 70 } | |
| 71 | |
| 72 // Generate the docs. | |
| 59 for (var library in world.libraries.getValues()) { | 73 for (var library in world.libraries.getValues()) { |
| 60 docLibrary(library); | 74 docLibrary(library); |
| 61 } | 75 } |
| 62 | 76 |
| 63 docIndex(world.libraries.getValues()); | 77 docIndex(world.libraries.getValues()); |
| 64 }); | 78 }); |
| 65 | 79 |
| 66 print('Documented $_totalLibraries libraries, $_totalTypes types, and ' + | 80 print('Documented $_totalLibraries libraries, $_totalTypes types, and ' + |
| 67 '$_totalMembers members in ${elapsed}msec.'); | 81 '$_totalMembers members in ${elapsed}msec.'); |
| 68 } | 82 } |
| 69 | 83 |
| 84 /** Copies the static file at 'static/file' to the output directory. */ | |
| 85 copyStatic(String file) { | |
| 86 var contents = files.readAll(joinPaths('static', file)); | |
|
Jacob
2011/11/16 19:59:30
why not use final for this and other local vars th
jimhug
2011/11/17 16:59:44
This is a good topic. I've found myself not doing
Bob Nystrom
2011/11/17 20:44:21
I do the same thing. Lately, my habit has been to
Jacob
2011/11/17 20:54:08
using final for everything at first has worked wel
| |
| 87 files.writeString(joinPaths(outdir, file), contents); | |
| 88 } | |
| 89 | |
| 70 num time(callback()) { | 90 num time(callback()) { |
| 71 // Unlike world.withTiming, returns the elapsed time. | 91 // Unlike world.withTiming, returns the elapsed time. |
| 72 final watch = new Stopwatch(); | 92 final watch = new Stopwatch(); |
| 73 watch.start(); | 93 watch.start(); |
| 74 callback(); | 94 callback(); |
| 75 watch.stop(); | 95 watch.stop(); |
| 76 return watch.elapsedInMs(); | 96 return watch.elapsedInMs(); |
| 77 } | 97 } |
| 78 | 98 |
| 79 startFile() { | 99 startFile() { |
| (...skipping 462 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 542 if (line.endsWith('*/')) line = line.substring(0, line.length-2); | 562 if (line.endsWith('*/')) line = line.substring(0, line.length-2); |
| 543 line = line.trim(); | 563 line = line.trim(); |
| 544 while (line.startsWith('*')) line = line.substring(1, line.length); | 564 while (line.startsWith('*')) line = line.substring(1, line.length); |
| 545 line = line.trim(); | 565 line = line.trim(); |
| 546 buf.add(line); | 566 buf.add(line); |
| 547 buf.add(' '); | 567 buf.add(' '); |
| 548 } | 568 } |
| 549 | 569 |
| 550 return buf.toString(); | 570 return buf.toString(); |
| 551 } | 571 } |
| OLD | NEW |