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('../../frog/lang.dart'); | 18 #import('../../frog/lang.dart'); |
19 #import('../../frog/file_system.dart'); | 19 #import('../../frog/file_system.dart'); |
20 #import('../../frog/file_system_node.dart'); | 20 #import('../../frog/file_system_node.dart'); |
| 21 #import('../../frog/lib/node/node.dart'); |
21 #import('markdown.dart', prefix: 'md'); | 22 #import('markdown.dart', prefix: 'md'); |
22 | 23 |
23 #source('classify.dart'); | 24 #source('classify.dart'); |
24 #source('comment_map.dart'); | 25 #source('comment_map.dart'); |
25 #source('files.dart'); | 26 #source('files.dart'); |
26 #source('utils.dart'); | 27 #source('utils.dart'); |
27 | 28 |
28 /** | 29 /** |
29 * Run this from the `utils/dartdoc` directory. | 30 * Run this from the `utils/dartdoc` directory. |
30 */ | 31 */ |
31 void main() { | 32 void main() { |
32 // The entrypoint of the library to generate docs for. | 33 // The entrypoint of the library to generate docs for. |
33 final entrypoint = process.argv[process.argv.length - 1]; | 34 final entrypoint = process.argv[process.argv.length - 1]; |
34 | 35 |
35 // Parse the dartdoc options. | 36 // Parse the dartdoc options. |
36 bool includeSource = true; | 37 bool includeSource = true; |
37 | 38 |
38 for (int i = 2; i < process.argv.length - 1; i++) { | 39 for (int i = 2; i < process.argv.length - 1; i++) { |
39 final arg = process.argv[i]; | 40 final arg = process.argv[i]; |
40 switch (arg) { | 41 switch (arg) { |
41 case '--no-code': | 42 case '--no-code': |
42 includeSource = false; | 43 includeSource = false; |
43 break; | 44 break; |
44 | 45 |
45 default: | 46 default: |
46 print('Unknown option: $arg'); | 47 print('Unknown option: $arg'); |
47 } | 48 } |
48 } | 49 } |
49 | 50 |
50 FileSystem files = new NodeFileSystem(); | 51 final files = new NodeFileSystem(); |
51 parseOptions('../../frog', [] /* args */, files); | 52 parseOptions('../../frog', [] /* args */, files); |
52 initializeWorld(files); | 53 initializeWorld(files); |
53 | 54 |
54 var dartdoc; | 55 var dartdoc; |
55 final elapsed = time(() { | 56 final elapsed = time(() { |
56 dartdoc = new Dartdoc(); | 57 dartdoc = new Dartdoc(); |
57 dartdoc.includeSource = includeSource; | 58 dartdoc.includeSource = includeSource; |
58 dartdoc.document(entrypoint); | 59 dartdoc.document(entrypoint); |
59 }); | 60 }); |
60 | 61 |
61 print('Documented ${dartdoc._totalLibraries} libraries, ' + | 62 print('Documented ${dartdoc._totalLibraries} libraries, ' + |
62 '${dartdoc._totalTypes} types, and ' + | 63 '${dartdoc._totalTypes} types, and ' + |
63 '${dartdoc._totalMembers} members in ${elapsed}msec.'); | 64 '${dartdoc._totalMembers} members in ${elapsed}msec.'); |
64 } | 65 } |
65 | 66 |
66 class Dartdoc { | 67 class Dartdoc { |
67 /** Set to `false` to not include the source code in the generated docs. */ | 68 /** Set to `false` to not include the source code in the generated docs. */ |
68 bool includeSource = true; | 69 bool includeSource = true; |
69 | 70 |
70 /** | 71 /** |
71 * The title used for the overall generated output. Set this to change it. | 72 * The title used for the overall generated output. Set this to change it. |
72 */ | 73 */ |
73 String mainTitle = 'Dart Documentation'; | 74 String mainTitle = 'Dart Documentation'; |
74 | 75 |
| 76 /** |
| 77 * The URL that the Dart logo links to. Defaults "index.html", the main |
| 78 * page for the generated docs, but can be anything. |
| 79 */ |
| 80 String mainUrl = 'index.html'; |
| 81 |
| 82 /** Set this to add footer text to each generated page. */ |
| 83 String footerText = ''; |
| 84 |
75 CommentMap _comments; | 85 CommentMap _comments; |
76 | 86 |
77 /** The library that we're currently generating docs for. */ | 87 /** The library that we're currently generating docs for. */ |
78 Library _currentLibrary; | 88 Library _currentLibrary; |
79 | 89 |
80 /** The type that we're currently generating docs for. */ | 90 /** The type that we're currently generating docs for. */ |
81 Type _currentType; | 91 Type _currentType; |
82 | 92 |
83 /** The member that we're currently generating docs for. */ | 93 /** The member that we're currently generating docs for. */ |
84 Member _currentMember; | 94 Member _currentMember; |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 * It will output: | 165 * It will output: |
156 * | 166 * |
157 * <a href="foo.html">foo</a> › bar | 167 * <a href="foo.html">foo</a> › bar |
158 */ | 168 */ |
159 writeHeader(String title, List<String> breadcrumbs) { | 169 writeHeader(String title, List<String> breadcrumbs) { |
160 write( | 170 write( |
161 ''' | 171 ''' |
162 <!DOCTYPE html> | 172 <!DOCTYPE html> |
163 <html> | 173 <html> |
164 <head> | 174 <head> |
165 <meta charset="utf-8"> | 175 '''); |
166 <title>$title</title> | 176 writeHeadContents(title); |
167 <link rel="stylesheet" type="text/css" | 177 write( |
168 href="${relativePath('styles.css')}" /> | 178 ''' |
169 <link href="http://fonts.googleapis.com/css?family=Open+Sans:400,600,700
,800" rel="stylesheet" type="text/css"> | |
170 <script src="${relativePath('interact.js')}"></script> | |
171 </head> | 179 </head> |
172 <body> | 180 <body> |
173 <div class="page"> | 181 <div class="page"> |
174 <div class="header"> | 182 <div class="header"> |
175 ${a('index.html', '<div class="logo"></div>')} | 183 ${a(mainUrl, '<div class="logo"></div>')} |
176 ${a('index.html', mainTitle)} | 184 ${a('index.html', mainTitle)} |
177 '''); | 185 '''); |
178 | 186 |
179 // Write the breadcrumb trail. | 187 // Write the breadcrumb trail. |
180 for (int i = 0; i < breadcrumbs.length; i += 2) { | 188 for (int i = 0; i < breadcrumbs.length; i += 2) { |
181 if (breadcrumbs[i + 1] == null) { | 189 if (breadcrumbs[i + 1] == null) { |
182 write(' › ${breadcrumbs[i]}'); | 190 write(' › ${breadcrumbs[i]}'); |
183 } else { | 191 } else { |
184 write(' › ${a(breadcrumbs[i + 1], breadcrumbs[i])}'); | 192 write(' › ${a(breadcrumbs[i + 1], breadcrumbs[i])}'); |
185 } | 193 } |
186 } | 194 } |
187 writeln('</div>'); | 195 writeln('</div>'); |
188 | 196 |
189 docNavigation(); | 197 docNavigation(); |
190 writeln('<div class="content">'); | 198 writeln('<div class="content">'); |
191 } | 199 } |
192 | 200 |
| 201 writeHeadContents(String title) { |
| 202 writeln( |
| 203 ''' |
| 204 <meta charset="utf-8"> |
| 205 <title>$title</title> |
| 206 <link rel="stylesheet" type="text/css" |
| 207 href="${relativePath('styles.css')}" /> |
| 208 <link href="http://fonts.googleapis.com/css?family=Open+Sans:400,600,700
,800" rel="stylesheet" type="text/css"> |
| 209 <link rel="shortcut icon" href="${relativePath('favicon.ico')}" /> |
| 210 <script src="${relativePath('interact.js')}"></script> |
| 211 '''); |
| 212 } |
| 213 |
193 writeFooter() { | 214 writeFooter() { |
194 writeln( | 215 writeln( |
195 ''' | 216 ''' |
196 </div> | 217 </div> |
197 <div class="footer"</div> | 218 <div class="clear"></div> |
| 219 </div> |
| 220 <div class="footer">$footerText</div> |
198 </body></html> | 221 </body></html> |
199 '''); | 222 '''); |
200 } | 223 } |
201 | 224 |
202 docIndex() { | 225 docIndex() { |
203 startFile('index.html'); | 226 startFile('index.html'); |
204 | 227 |
205 writeHeader(mainTitle, []); | 228 writeHeader(mainTitle, []); |
206 | 229 |
207 writeln('<h2>$mainTitle</h2>'); | 230 writeln('<h2>$mainTitle</h2>'); |
(...skipping 610 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
818 | 841 |
819 return new md.Element.text('code', name); | 842 return new md.Element.text('code', name); |
820 } | 843 } |
821 | 844 |
822 // TODO(rnystrom): Move into SourceSpan? | 845 // TODO(rnystrom): Move into SourceSpan? |
823 int getSpanColumn(SourceSpan span) { | 846 int getSpanColumn(SourceSpan span) { |
824 final line = span.file.getLine(span.start); | 847 final line = span.file.getLine(span.start); |
825 return span.file.getColumn(line, span.start); | 848 return span.file.getColumn(line, span.start); |
826 } | 849 } |
827 } | 850 } |
OLD | NEW |