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 |
11 * create these beautiful docs, dartdoc parses your library and every library | 11 * create these beautiful docs, dartdoc parses your library and every library |
12 * it imports (recursively). From each library, it parses all classes and | 12 * it imports (recursively). From each library, it parses all classes and |
13 * members, finds the associated doc comments and builds crosslinked docs from | 13 * members, finds the associated doc comments and builds crosslinked docs from |
14 * them. | 14 * them. |
15 */ | 15 */ |
16 #library('dartdoc'); | 16 #library('dartdoc'); |
17 | 17 |
| 18 #import('dart:io'); |
18 #import('dart:json'); | 19 #import('dart:json'); |
19 #import('../../frog/lang.dart'); | 20 #import('../../frog/lang.dart'); |
20 #import('../../frog/file_system.dart'); | 21 #import('../../frog/file_system.dart'); |
21 #import('../../frog/file_system_node.dart'); | 22 #import('../../frog/file_system_vm.dart'); |
22 #import('../../frog/lib/node/node.dart'); | |
23 #import('classify.dart'); | 23 #import('classify.dart'); |
24 #import('markdown.dart', prefix: 'md'); | 24 #import('markdown.dart', prefix: 'md'); |
25 | 25 |
26 #source('comment_map.dart'); | 26 #source('comment_map.dart'); |
27 #source('utils.dart'); | 27 #source('utils.dart'); |
28 | 28 |
29 /** Path to generate HTML files into. */ | 29 /** Path to generate HTML files into. */ |
30 final _outdir = 'docs'; | 30 final _outdir = 'docs'; |
31 | 31 |
32 /** | 32 /** |
(...skipping 14 matching lines...) Expand all Loading... |
47 * In this mode, the browser will do a XHR for nav.json which means that to | 47 * In this mode, the browser will do a XHR for nav.json which means that to |
48 * preview docs locally, you will need to enable requesting file:// links in | 48 * preview docs locally, you will need to enable requesting file:// links in |
49 * your browser or run a little local server like `python -m SimpleHTTPServer`. | 49 * your browser or run a little local server like `python -m SimpleHTTPServer`. |
50 */ | 50 */ |
51 final MODE_LIVE_NAV = 1; | 51 final MODE_LIVE_NAV = 1; |
52 | 52 |
53 /** | 53 /** |
54 * Run this from the `utils/dartdoc` directory. | 54 * Run this from the `utils/dartdoc` directory. |
55 */ | 55 */ |
56 void main() { | 56 void main() { |
| 57 final args = new Options().arguments; |
| 58 |
57 // The entrypoint of the library to generate docs for. | 59 // The entrypoint of the library to generate docs for. |
58 final entrypoint = process.argv[process.argv.length - 1]; | 60 final entrypoint = args[args.length - 1]; |
59 | 61 |
60 // Parse the dartdoc options. | 62 // Parse the dartdoc options. |
61 bool includeSource = true; | 63 bool includeSource = true; |
62 var mode = MODE_LIVE_NAV; | 64 var mode = MODE_LIVE_NAV; |
63 | 65 |
64 for (int i = 2; i < process.argv.length - 1; i++) { | 66 for (int i = 2; i < args.length - 1; i++) { |
65 final arg = process.argv[i]; | 67 final arg = args[i]; |
66 switch (arg) { | 68 switch (arg) { |
67 case '--no-code': | 69 case '--no-code': |
68 includeSource = false; | 70 includeSource = false; |
69 break; | 71 break; |
70 | 72 |
71 case '--mode=static': | 73 case '--mode=static': |
72 mode = MODE_STATIC; | 74 mode = MODE_STATIC; |
73 break; | 75 break; |
74 | 76 |
75 case '--mode=live-nav': | 77 case '--mode=live-nav': |
76 mode = MODE_LIVE_NAV; | 78 mode = MODE_LIVE_NAV; |
77 break; | 79 break; |
78 | 80 |
79 default: | 81 default: |
80 print('Unknown option: $arg'); | 82 print('Unknown option: $arg'); |
81 } | 83 } |
82 } | 84 } |
83 | 85 |
84 final files = new NodeFileSystem(); | 86 final files = new VMFileSystem(); |
85 parseOptions('../../frog', [] /* args */, files); | 87 parseOptions('../../frog', ['', '', '--libdir=../../frog/lib'], files); |
86 initializeWorld(files); | 88 initializeWorld(files); |
87 | 89 |
88 var dartdoc; | 90 var dartdoc; |
89 final elapsed = time(() { | 91 final elapsed = time(() { |
90 dartdoc = new Dartdoc(); | 92 dartdoc = new Dartdoc(); |
91 dartdoc.includeSource = includeSource; | 93 dartdoc.includeSource = includeSource; |
92 dartdoc.mode = mode; | 94 dartdoc.mode = mode; |
93 | 95 |
94 dartdoc.document(entrypoint); | 96 dartdoc.document(entrypoint); |
95 }); | 97 }); |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
230 options.dietParse = oldDietParse; | 232 options.dietParse = oldDietParse; |
231 } | 233 } |
232 } | 234 } |
233 | 235 |
234 void startFile(String path) { | 236 void startFile(String path) { |
235 _filePath = path; | 237 _filePath = path; |
236 _file = new StringBuffer(); | 238 _file = new StringBuffer(); |
237 } | 239 } |
238 | 240 |
239 void endFile() { | 241 void endFile() { |
240 String outPath = '$_outdir/$_filePath'; | 242 final outPath = '$_outdir/$_filePath'; |
241 world.files.createDirectory(dirname(outPath), recursive: true); | 243 final dir = new Directory(dirname(outPath)); |
| 244 if (!dir.existsSync()) { |
| 245 dir.createSync(); |
| 246 } |
242 | 247 |
243 world.files.writeString(outPath, _file.toString()); | 248 world.files.writeString(outPath, _file.toString()); |
244 _filePath = null; | 249 _filePath = null; |
245 _file = null; | 250 _file = null; |
246 } | 251 } |
247 | 252 |
248 void write(String s) { | 253 void write(String s) { |
249 _file.add(s); | 254 _file.add(s); |
250 } | 255 } |
251 | 256 |
(...skipping 831 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1083 return type.name; | 1088 return type.name; |
1084 } | 1089 } |
1085 | 1090 |
1086 /** | 1091 /** |
1087 * Remove leading indentation to line up with first line. | 1092 * Remove leading indentation to line up with first line. |
1088 */ | 1093 */ |
1089 unindentCode(SourceSpan span) { | 1094 unindentCode(SourceSpan span) { |
1090 final column = getSpanColumn(span); | 1095 final column = getSpanColumn(span); |
1091 final lines = span.text.split('\n'); | 1096 final lines = span.text.split('\n'); |
1092 // TODO(rnystrom): Dirty hack. | 1097 // TODO(rnystrom): Dirty hack. |
1093 for (final i = 1; i < lines.length; i++) { | 1098 for (var i = 1; i < lines.length; i++) { |
1094 lines[i] = unindent(lines[i], column); | 1099 lines[i] = unindent(lines[i], column); |
1095 } | 1100 } |
1096 | 1101 |
1097 final code = Strings.join(lines, '\n'); | 1102 final code = Strings.join(lines, '\n'); |
1098 return code; | 1103 return code; |
1099 } | 1104 } |
1100 | 1105 |
1101 /** | 1106 /** |
1102 * Takes a string of Dart code and turns it into sanitized HTML. | 1107 * Takes a string of Dart code and turns it into sanitized HTML. |
1103 */ | 1108 */ |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1201 | 1206 |
1202 return new md.Element.text('code', name); | 1207 return new md.Element.text('code', name); |
1203 } | 1208 } |
1204 | 1209 |
1205 // TODO(rnystrom): Move into SourceSpan? | 1210 // TODO(rnystrom): Move into SourceSpan? |
1206 int getSpanColumn(SourceSpan span) { | 1211 int getSpanColumn(SourceSpan span) { |
1207 final line = span.file.getLine(span.start); | 1212 final line = span.file.getLine(span.start); |
1208 return span.file.getColumn(line, span.start); | 1213 return span.file.getColumn(line, span.start); |
1209 } | 1214 } |
1210 } | 1215 } |
OLD | NEW |