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 * This generates the reference documentation for the core libraries that come | 6 * This generates the reference documentation for the core libraries that come |
7 * with dart. It is built on top of dartdoc, which is a general-purpose library | 7 * with dart. It is built on top of dartdoc, which is a general-purpose library |
8 * for generating docs from any Dart code. This library extends that to include | 8 * for generating docs from any Dart code. This library extends that to include |
9 * additional information and styling specific to our standard library. | 9 * additional information and styling specific to our standard library. |
10 * | 10 * |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
97 initializeWorld(files); | 97 initializeWorld(files); |
98 | 98 |
99 print('Parsing MDN data...'); | 99 print('Parsing MDN data...'); |
100 final mdnFile = new File('${doc.scriptDir}/mdn/database.json'); | 100 final mdnFile = new File('${doc.scriptDir}/mdn/database.json'); |
101 final mdn = JSON.parse(mdnFile.readAsTextSync()); | 101 final mdn = JSON.parse(mdnFile.readAsTextSync()); |
102 | 102 |
103 print('Cross-referencing dart:html...'); | 103 print('Cross-referencing dart:html...'); |
104 HtmlDiff.initialize(); | 104 HtmlDiff.initialize(); |
105 _diff = new HtmlDiff(printWarnings:false); | 105 _diff = new HtmlDiff(printWarnings:false); |
106 _diff.run(); | 106 _diff.run(); |
107 | |
108 // Process handwritten HTML documentation. | |
109 world.reset(); | |
110 world.getOrAddLibrary('${doc.scriptDir}/../../lib/html/doc/html.dartdoc'); | |
111 world.process(); | |
112 final htmldoc = new Htmldoc(); | |
113 htmldoc.document(); | |
Bob Nystrom
2012/06/11 19:31:19
This still generates the output files, doesn't it?
vsm
2012/06/11 20:51:01
Thanks - done.
On 2012/06/11 19:31:19, Bob Nystro
| |
114 print('Processing handwritten HTML documentation...'); | |
115 | |
116 // Process libraries. | |
107 world.reset(); | 117 world.reset(); |
108 | 118 |
109 // Add all of the core libraries. | 119 // Add all of the core libraries. |
110 world.getOrAddLibrary('dart:core'); | 120 world.getOrAddLibrary('dart:core'); |
111 world.getOrAddLibrary('dart:coreimpl'); | 121 world.getOrAddLibrary('dart:coreimpl'); |
112 world.getOrAddLibrary('dart:crypto'); | 122 world.getOrAddLibrary('dart:crypto'); |
113 world.getOrAddLibrary('dart:html'); | 123 world.getOrAddLibrary('dart:html'); |
114 world.getOrAddLibrary('dart:io'); | 124 world.getOrAddLibrary('dart:io'); |
115 world.getOrAddLibrary('dart:isolate'); | 125 world.getOrAddLibrary('dart:isolate'); |
116 world.getOrAddLibrary('dart:json'); | 126 world.getOrAddLibrary('dart:json'); |
117 world.getOrAddLibrary('${doc.scriptDir}/../../lib/math/math.dart'); | 127 world.getOrAddLibrary('${doc.scriptDir}/../../lib/math/math.dart'); |
118 world.getOrAddLibrary('${doc.scriptDir}/../../lib/unittest/unittest.dart'); | 128 world.getOrAddLibrary('${doc.scriptDir}/../../lib/unittest/unittest.dart'); |
119 world.getOrAddLibrary('dart:uri'); | 129 world.getOrAddLibrary('dart:uri'); |
120 world.getOrAddLibrary('dart:utf'); | 130 world.getOrAddLibrary('dart:utf'); |
121 world.process(); | 131 world.process(); |
122 | 132 |
123 print('Generating docs...'); | 133 print('Generating docs...'); |
124 final apidoc = new Apidoc(mdn, outputDir, mode, generateAppCache); | 134 final apidoc = new Apidoc(mdn, htmldoc, outputDir, mode, generateAppCache); |
125 | 135 |
126 Futures.wait([scriptCompiled, copiedStatic, copiedApiDocStatic]).then((_) { | 136 Futures.wait([scriptCompiled, copiedStatic, copiedApiDocStatic]).then((_) { |
127 apidoc.document(); | 137 apidoc.document(); |
128 }); | 138 }); |
129 } | 139 } |
130 | 140 |
141 /** | |
142 * This class is purely here to scrape handwritten HTML documentation. | |
143 * This scraped documentation will later be merged with the generated | |
144 * HTML library. | |
Bob Nystrom
2012/06/11 19:31:19
Hackish, but works.
I would leave a comment expla
vsm
2012/06/11 20:51:01
Comment added at the reset above.
On 2012/06/11 1
| |
145 */ | |
146 class Htmldoc extends doc.Dartdoc { | |
147 String libraryComment; | |
148 Map<String, String> typeComments; | |
149 Map<String, Map<String, String>> memberComments; | |
150 | |
151 Htmldoc() { | |
152 typeComments = new Map<String, String>(); | |
153 memberComments = new Map<String, Map<String, String>>(); | |
154 } | |
155 | |
156 String getRecordedLibraryComment(Library library) { | |
157 if (library.name == 'html') { | |
158 return libraryComment; | |
159 } | |
160 return null; | |
161 } | |
162 | |
163 String getRecordedTypeComment(Type type) { | |
164 if (type.library.name == 'html') { | |
165 if (typeComments.containsKey(type.name)) { | |
166 return typeComments[type.name]; | |
167 } | |
168 } | |
169 return null; | |
170 } | |
171 | |
172 String getRecordedMemberComment(Member member) { | |
173 if (member.library.name == 'html') { | |
174 String typeName; | |
175 if (member.declaringType != null) { | |
176 typeName = member.declaringType.name; | |
177 } | |
178 if (typeName == null) { | |
179 typeName = ''; | |
180 } | |
181 if (memberComments.containsKey(typeName)) { | |
182 Map<String, String> memberMap = memberComments[typeName]; | |
183 if (memberMap.containsKey(member.name)) { | |
184 return memberMap[member.name]; | |
185 } | |
186 } | |
187 } | |
188 return null; | |
189 } | |
190 | |
191 // These methods are subclassed and used for internal processing. | |
192 // Do not invoke outside of this class. | |
193 String getLibraryComment(Library library) { | |
194 String comment = super.getLibraryComment(library); | |
195 libraryComment = comment; | |
196 return comment; | |
197 } | |
198 | |
199 String getTypeComment(Type type) { | |
200 String comment = super.getTypeComment(type); | |
201 recordTypeComment(type, comment); | |
202 return comment; | |
203 } | |
204 | |
205 String getMethodComment(MethodMember method) { | |
206 String comment = super.getMethodComment(method); | |
207 recordMemberComment(method, comment); | |
208 return comment; | |
209 } | |
210 | |
211 String getFieldComment(FieldMember field) { | |
212 String comment = super.getFieldComment(field); | |
213 recordMemberComment(field, comment); | |
214 return comment; | |
215 } | |
216 | |
217 void recordTypeComment(Type type, String comment) { | |
218 if (comment != null && comment.contains('@domName')) { | |
219 // This is not a handwritten comment. | |
220 return; | |
221 } | |
222 typeComments[type.name] = comment; | |
223 } | |
224 | |
225 void recordMemberComment(Member member, String comment) { | |
226 if (comment != null && comment.contains('@domName')) { | |
227 // This is not a handwritten comment. | |
228 return; | |
229 } | |
230 String typeName = member.declaringType.name; | |
231 if (typeName == null) | |
232 typeName = ''; | |
233 if (!memberComments.containsKey(typeName)) { | |
234 memberComments[typeName] = new Map<String, String>(); | |
235 } | |
236 Map<String, String> memberMap = memberComments[typeName]; | |
237 memberMap[member.name] = comment; | |
238 } | |
239 } | |
240 | |
131 class Apidoc extends doc.Dartdoc { | 241 class Apidoc extends doc.Dartdoc { |
132 /** Big ball of JSON containing the scraped MDN documentation. */ | 242 /** Big ball of JSON containing the scraped MDN documentation. */ |
133 final Map mdn; | 243 final Map mdn; |
134 | 244 |
245 final Htmldoc htmldoc; | |
246 | |
135 static final disqusShortname = 'dartapidocs'; | 247 static final disqusShortname = 'dartapidocs'; |
136 | 248 |
137 /** | 249 /** |
138 * The URL to the page on MDN that content was pulled from for the current | 250 * The URL to the page on MDN that content was pulled from for the current |
139 * type being documented. Will be `null` if the type doesn't use any MDN | 251 * type being documented. Will be `null` if the type doesn't use any MDN |
140 * content. | 252 * content. |
141 */ | 253 */ |
142 String mdnUrl; | 254 String mdnUrl; |
143 | 255 |
144 Apidoc(this.mdn, String outputDir, int mode, bool generateAppCache) { | 256 Apidoc(this.mdn, this.htmldoc, String outputDir, int mode, |
257 bool generateAppCache) { | |
145 this.outputDir = outputDir; | 258 this.outputDir = outputDir; |
146 this.mode = mode; | 259 this.mode = mode; |
147 this.generateAppCache = generateAppCache; | 260 this.generateAppCache = generateAppCache; |
148 | 261 |
149 mainTitle = 'Dart API Reference'; | 262 mainTitle = 'Dart API Reference'; |
150 mainUrl = 'http://dartlang.org'; | 263 mainUrl = 'http://dartlang.org'; |
151 | 264 |
152 final note = 'http://code.google.com/policies.html#restrictions'; | 265 final note = 'http://code.google.com/policies.html#restrictions'; |
153 final cca = 'http://creativecommons.org/licenses/by/3.0/'; | 266 final cca = 'http://creativecommons.org/licenses/by/3.0/'; |
154 final bsd = 'http://code.google.com/google_bsd_license.html'; | 267 final bsd = 'http://code.google.com/google_bsd_license.html'; |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
246 if (library.name == 'dart:nativewrappers') return; | 359 if (library.name == 'dart:nativewrappers') return; |
247 super.docLibrary(library); | 360 super.docLibrary(library); |
248 } | 361 } |
249 | 362 |
250 /** Override definition from parent class to strip out annotation tags. */ | 363 /** Override definition from parent class to strip out annotation tags. */ |
251 String commentToHtml(String comment) { | 364 String commentToHtml(String comment) { |
252 return super.commentToHtml( | 365 return super.commentToHtml( |
253 comment.replaceAll(const RegExp("@([a-zA-Z]+) ([^;]+)(?:;|\$)"), '')); | 366 comment.replaceAll(const RegExp("@([a-zA-Z]+) ([^;]+)(?:;|\$)"), '')); |
254 } | 367 } |
255 | 368 |
369 String getLibraryComment(Library library) { | |
370 if (library.name == 'html') { | |
371 return htmldoc.libraryComment; | |
372 } | |
373 return super.getLibraryComment(library); | |
374 } | |
375 | |
256 String getTypeComment(Type type) { | 376 String getTypeComment(Type type) { |
257 return _mergeDocs( | 377 return _mergeDocs( |
258 includeMdnTypeComment(type), super.getTypeComment(type)); | 378 includeMdnTypeComment(type), super.getTypeComment(type), |
379 htmldoc.getRecordedTypeComment(type)); | |
259 } | 380 } |
260 | 381 |
261 String getMethodComment(MethodMember method) { | 382 String getMethodComment(MethodMember method) { |
262 return _mergeDocs( | 383 return _mergeDocs( |
263 includeMdnMemberComment(method), super.getMethodComment(method)); | 384 includeMdnMemberComment(method), super.getMethodComment(method), |
385 htmldoc.getRecordedMemberComment(method)); | |
264 } | 386 } |
265 | 387 |
266 String getFieldComment(FieldMember field) { | 388 String getFieldComment(FieldMember field) { |
267 return _mergeDocs( | 389 return _mergeDocs( |
268 includeMdnMemberComment(field), super.getFieldComment(field)); | 390 includeMdnMemberComment(field), super.getFieldComment(field), |
391 htmldoc.getRecordedMemberComment(field)); | |
269 } | 392 } |
270 | 393 |
271 bool isNonEmpty(String string) => (string != null) && (string.trim() != ''); | 394 bool isNonEmpty(String string) => (string != null) && (string.trim() != ''); |
272 | 395 |
273 String _mergeDocs(String mdnComment, String dartComment) { | 396 String _mergeDocs(String mdnComment, String dartComment, String override) { |
397 // Prefer override first. | |
398 if (isNonEmpty(override)) return override; | |
399 | |
274 // Prefer hand-written Dart comments over stuff from MDN. | 400 // Prefer hand-written Dart comments over stuff from MDN. |
Bob Nystrom
2012/06/11 19:31:19
This comment is confusing now. How about changing
vsm
2012/06/11 20:51:01
Done. I used "fileComment" instead of "generatedC
| |
275 if (isNonEmpty(dartComment)) return dartComment; | 401 if (isNonEmpty(dartComment)) return dartComment; |
276 | 402 |
277 if (isNonEmpty(mdnComment)) { | 403 if (isNonEmpty(mdnComment)) { |
278 // Wrap it so we can highlight it and so we handle MDN scraped content | 404 // Wrap it so we can highlight it and so we handle MDN scraped content |
279 // that lacks a top-level block tag. | 405 // that lacks a top-level block tag. |
280 return ''' | 406 return ''' |
281 <div class="mdn"> | 407 <div class="mdn"> |
282 $mdnComment | 408 $mdnComment |
283 <div class="mdn-note"><a href="$mdnUrl">from MDN</a></div> | 409 <div class="mdn-note"><a href="$mdnUrl">from MDN</a></div> |
284 </div> | 410 </div> |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
408 if (member.isConstructor || member.isFactory) { | 534 if (member.isConstructor || member.isFactory) { |
409 final separator = member.constructorName == '' ? '' : '.'; | 535 final separator = member.constructorName == '' ? '' : '.'; |
410 memberName = 'new $typeName$separator${member.constructorName}'; | 536 memberName = 'new $typeName$separator${member.constructorName}'; |
411 } else if (member.name.startsWith(GET_PREFIX)) { | 537 } else if (member.name.startsWith(GET_PREFIX)) { |
412 memberName = '$typeName.${member.name.substring(GET_PREFIX.length)}'; | 538 memberName = '$typeName.${member.name.substring(GET_PREFIX.length)}'; |
413 } | 539 } |
414 | 540 |
415 return a(memberUrl(member), memberName); | 541 return a(memberUrl(member), memberName); |
416 } | 542 } |
417 } | 543 } |
OLD | NEW |