Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(215)

Side by Side Diff: client/html/scripts/html_doc.dart

Issue 8771054: Add a script to generate HTML and DOM docs with cross-links to one another. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: More code review changes. Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 /**
6 * A script to document the HTML library, including annotations on the mapping
7 * to and from the DOM library. To use it, from utils/dartdoc, run:
8 *
9 * $ htmldoc
10 *
11 * This works just like `dartdoc html`, with the additions of the DOM/HTML
12 * mapping documentation.
13 */
14 #library('html_doc');
15
16 #import('html_diff.dart');
17 #import('../../../frog/lang.dart');
18 #import('../../../frog/file_system_node.dart');
19 #import('../../../frog/file_system.dart');
20 #import('../../../utils/dartdoc/dartdoc.dart', prefix: 'doc');
21
22 HtmlDiff _diff;
23
24 void main() {
25 var files = new NodeFileSystem();
26 parseOptions('../../frog', [] /* args */, files);
27 initializeWorld(files);
28 doc.initializeDartDoc();
29 HtmlDiff.initialize();
30
31 _diff = new HtmlDiff();
32 _diff.run();
33 world.reset();
34
35 doc.addMethodDocumenter(addMemberDoc);
36 doc.addFieldDocumenter(addMemberDoc);
37 doc.addTypeDocumenter(addTypeDoc);
38 doc.document('html');
39 }
40
41 // TODO(nweiz): document this file
42
43 String _linkMember(Member member) {
44 final typeName = member.declaringType.name;
45 var memberName = "$typeName.${member.name}";
46 if (member.isConstructor || member.isFactory) {
47 final separator = member.constructorName == '' ? '' : '.';
48 memberName = 'new $typeName$separator${member.constructorName}';
49 } else if (member.name.startsWith('get:')) {
50 memberName = "$typeName.${member.name.substring(4)}";
51 }
52
53 return "[$memberName](../${doc.memberUrl(member)})";
54 }
55
56 String _linkType(Type type) => "[${type.name}](../${doc.typeUrl(type)})";
57
58 /**
59 * Unify getters and setters of the same property. We only want to print
60 * explicit setters if no getter exists.
61 */
62 Set<Member> _unifyProperties(Set<Member> members) {
63 // Only print setters if the getter doesn't exist.
64 return members.filter((m) {
65 if (!m.name.startsWith('set:')) return true;
66 var getName = m.name.replaceFirst('set:', 'get:');
67 return !members.some((maybeGet) => maybeGet.name == getName);
68 });
69 }
70
71 String addMemberDoc(Member member) {
72 if (_diff.domToHtml.containsKey(member)) {
73 final htmlMemberSet = _unifyProperties(_diff.domToHtml[member]);
74 final allSameName = htmlMemberSet.every((m) => _diff.sameName(member, m));
75 final phrase = allSameName ? "available as" : "renamed to";
76 final htmlMembers = doc.joinWithCommas(map(htmlMemberSet, _linkMember));
77 return "_This is $phrase $htmlMembers in the " +
78 "[dart:html](../html.html) library._";
79 } else if (_diff.htmlToDom.containsKey(member)) {
80 final domMemberSet = _unifyProperties(_diff.htmlToDom[member]);
81 final allSameName = domMemberSet.every((m) => _diff.sameName(m, member));
82 final phrase = allSameName ? "is the same as" : "renames";
83 final domMembers = doc.joinWithCommas(map(domMemberSet, _linkMember));
84 return "_This $phrase $domMembers in the [dart:dom](../dom.html) " +
85 "library._";
86 } else {
87 return "";
88 }
89 }
90
91 String addTypeDoc(Type type) {
92 if (_diff.domTypesToHtml.containsKey(type)) {
93 var htmlTypes = doc.joinWithCommas(
94 map(_diff.domTypesToHtml[type], _linkType));
95 return "_This corresponds to $htmlTypes in the [dart:html](../html.html) " +
96 "library._";
97 } else if (_diff.htmlTypesToDom.containsKey(type)) {
98 var domTypes = doc.joinWithCommas(
99 map(_diff.htmlTypesToDom[type], _linkType));
100 return "_This corresponds to $domTypes in the [dart:dom](../dom.html) " +
101 "library._";
102 } else {
103 return "";
104 }
105 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698