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 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
267 doc.DocComment getTypeComment(TypeMirror type) { | 267 doc.DocComment getTypeComment(TypeMirror type) { |
268 return _mergeDocs( | 268 return _mergeDocs( |
269 includeMdnTypeComment(type), super.getTypeComment(type)); | 269 includeMdnTypeComment(type), super.getTypeComment(type)); |
270 } | 270 } |
271 | 271 |
272 doc.DocComment getMemberComment(MemberMirror member) { | 272 doc.DocComment getMemberComment(MemberMirror member) { |
273 return _mergeDocs( | 273 return _mergeDocs( |
274 includeMdnMemberComment(member), super.getMemberComment(member)); | 274 includeMdnMemberComment(member), super.getMemberComment(member)); |
275 } | 275 } |
276 | 276 |
277 doc.DocComment _mergeDocs(MdnComment mdnComment, | 277 doc.DocComment _mergeDocs(doc.MdnComment mdnComment, |
278 doc.DocComment fileComment) { | 278 doc.DocComment fileComment) { |
279 // Otherwise, prefer comment from the (possibly generated) Dart file. | 279 // Otherwise, prefer comment from the (possibly generated) Dart file. |
280 if (fileComment != null) return fileComment; | 280 if (fileComment != null) return fileComment; |
281 | 281 |
282 // Finally, fallback on MDN if available. | 282 // Finally, fallback on MDN if available. |
283 if (mdnComment != null) { | 283 if (mdnComment != null) { |
284 mdnUrl = mdnComment.mdnUrl; | 284 mdnUrl = mdnComment.mdnUrl; |
285 return mdnComment; | 285 return mdnComment; |
286 } | 286 } |
287 | 287 |
(...skipping 26 matching lines...) Expand all Loading... |
314 <a href="$CCA">Creative Commons: Attribution-Sharealike license</a>. | 314 <a href="$CCA">Creative Commons: Attribution-Sharealike license</a>. |
315 Mozilla has no other association with Dart or dartlang.org. We | 315 Mozilla has no other association with Dart or dartlang.org. We |
316 encourage you to improve the web by | 316 encourage you to improve the web by |
317 <a href="$CONTRIB">contributing</a> to | 317 <a href="$CONTRIB">contributing</a> to |
318 <a href="$MDN">The Mozilla Developer Network</a>. | 318 <a href="$MDN">The Mozilla Developer Network</a>. |
319 </p> | 319 </p> |
320 '''); | 320 '''); |
321 } | 321 } |
322 } | 322 } |
323 | 323 |
| 324 doc.MdnComment lookupMdnComment(Mirror mirror) { |
| 325 if (mirror is TypeMirror) { |
| 326 return includeMdnTypeComment(mirror); |
| 327 } else if (mirror is MemberMirror) { |
| 328 return includeMdnMemberComment(mirror); |
| 329 } else { |
| 330 return null; |
| 331 } |
| 332 } |
| 333 |
324 /** | 334 /** |
325 * Gets the MDN-scraped docs for [type], or `null` if this type isn't | 335 * Gets the MDN-scraped docs for [type], or `null` if this type isn't |
326 * scraped from MDN. | 336 * scraped from MDN. |
327 */ | 337 */ |
328 MdnComment includeMdnTypeComment(TypeMirror type) { | 338 doc.MdnComment includeMdnTypeComment(TypeMirror type) { |
329 if (_mdnTypeNamesToSkip.contains(type.simpleName)) { | 339 if (_mdnTypeNamesToSkip.contains(type.simpleName)) { |
330 print('Skipping MDN type ${type.simpleName}'); | 340 print('Skipping MDN type ${type.simpleName}'); |
331 return null; | 341 return null; |
332 } | 342 } |
333 | 343 |
334 var typeString = ''; | 344 var typeString = ''; |
335 if (HTML_LIBRARY_NAMES.contains(doc.displayName(type.library))) { | 345 if (HTML_LIBRARY_NAMES.contains(doc.displayName(type.library))) { |
336 // If it's an HTML type, try to map it to a base DOM type so we can find | 346 // If it's an HTML type, try to map it to a base DOM type so we can find |
337 // the MDN docs. | 347 // the MDN docs. |
338 final domTypes = _diff.htmlTypesToDom[type.qualifiedName]; | 348 final domTypes = _diff.htmlTypesToDom[type.qualifiedName]; |
(...skipping 13 matching lines...) Expand all Loading... |
352 return null; | 362 return null; |
353 } | 363 } |
354 | 364 |
355 final mdnType = mdn[typeString]; | 365 final mdnType = mdn[typeString]; |
356 if (mdnType == null) return null; | 366 if (mdnType == null) return null; |
357 if (mdnType['skipped'] != null) return null; | 367 if (mdnType['skipped'] != null) return null; |
358 if (mdnType['summary'] == null) return null; | 368 if (mdnType['summary'] == null) return null; |
359 if (mdnType['summary'].trim().isEmpty) return null; | 369 if (mdnType['summary'].trim().isEmpty) return null; |
360 | 370 |
361 // Remember which MDN page we're using so we can attribute it. | 371 // Remember which MDN page we're using so we can attribute it. |
362 return new MdnComment(mdnType['summary'], mdnType['srcUrl']); | 372 return new doc.MdnComment(mdnType['summary'], mdnType['srcUrl']); |
363 } | 373 } |
364 | 374 |
365 /** | 375 /** |
366 * Gets the MDN-scraped docs for [member], or `null` if this type isn't | 376 * Gets the MDN-scraped docs for [member], or `null` if this type isn't |
367 * scraped from MDN. | 377 * scraped from MDN. |
368 */ | 378 */ |
369 MdnComment includeMdnMemberComment(MemberMirror member) { | 379 MdnComment includeMdnMemberComment(MemberMirror member) { |
370 var library = findLibrary(member); | 380 var library = findLibrary(member); |
371 var memberString = ''; | 381 var memberString = ''; |
372 if (HTML_LIBRARY_NAMES.contains(doc.displayName(library))) { | 382 if (HTML_LIBRARY_NAMES.contains(doc.displayName(library))) { |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
405 break; | 415 break; |
406 } | 416 } |
407 } | 417 } |
408 } | 418 } |
409 | 419 |
410 if (mdnMember == null) return null; | 420 if (mdnMember == null) return null; |
411 if (mdnMember['help'] == null) return null; | 421 if (mdnMember['help'] == null) return null; |
412 if (mdnMember['help'].trim().isEmpty) return null; | 422 if (mdnMember['help'].trim().isEmpty) return null; |
413 | 423 |
414 // Remember which MDN page we're using so we can attribute it. | 424 // Remember which MDN page we're using so we can attribute it. |
415 return new MdnComment(mdnMember['help'], mdnType['srcUrl']); | 425 return new doc.MdnComment(mdnMember['help'], mdnType['srcUrl']); |
416 } | 426 } |
417 | 427 |
418 /** | 428 /** |
419 * Returns a link to [member], relative to a type page that may be in a | 429 * Returns a link to [member], relative to a type page that may be in a |
420 * different library than [member]. | 430 * different library than [member]. |
421 */ | 431 */ |
422 String _linkMember(MemberMirror member) { | 432 String _linkMember(MemberMirror member) { |
423 final typeName = member.owner.simpleName; | 433 final typeName = member.owner.simpleName; |
424 var memberName = '$typeName.${member.simpleName}'; | 434 var memberName = '$typeName.${member.simpleName}'; |
425 if (member is MethodMirror && (member.isConstructor || member.isFactory)) { | 435 if (member is MethodMirror && (member.isConstructor || member.isFactory)) { |
426 final separator = member.constructorName == '' ? '' : '.'; | 436 final separator = member.constructorName == '' ? '' : '.'; |
427 memberName = 'new $typeName$separator${member.constructorName}'; | 437 memberName = 'new $typeName$separator${member.constructorName}'; |
428 } | 438 } |
429 | 439 |
430 return a(memberUrl(member), memberName); | 440 return a(memberUrl(member), memberName); |
431 } | 441 } |
432 } | 442 } |
433 | |
434 class MdnComment implements doc.DocComment { | |
435 final String mdnComment; | |
436 final String mdnUrl; | |
437 | |
438 MdnComment(String this.mdnComment, String this.mdnUrl); | |
439 | |
440 String get text => mdnComment; | |
441 | |
442 ClassMirror get inheritedFrom => null; | |
443 | |
444 String get html { | |
445 // Wrap the mdn comment so we can highlight it and so we handle MDN scraped | |
446 // content that lacks a top-level block tag. | |
447 return ''' | |
448 <div class="mdn"> | |
449 $mdnComment | |
450 <div class="mdn-note"><a href="$mdnUrl">from MDN</a></div> | |
451 </div> | |
452 '''; | |
453 } | |
454 | |
455 String toString() => mdnComment; | |
456 } | |
OLD | NEW |