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

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

Issue 8947005: Refactor dartdoc into a class. Use method overriding to extend. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Respond to review. 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
« no previous file with comments | « client/html/scripts/html_diff.dart ('k') | utils/dartdoc/comment_map.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 * A script to document the HTML library, including annotations on the mapping 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: 7 * to and from the DOM library. To use it, from utils/dartdoc, run:
8 * 8 *
9 * $ htmldoc 9 * $ htmldoc
10 * 10 *
11 * This works just like `dartdoc html`, with the additions of the DOM/HTML 11 * This works just like `dartdoc html`, with the additions of the DOM/HTML
12 * mapping documentation. 12 * mapping documentation.
13 */ 13 */
14 #library('html_doc'); 14 #library('html_doc');
15 15
16 #import('html_diff.dart'); 16 #import('html_diff.dart');
17 #import('../../../frog/lang.dart'); 17 #import('../../../frog/lang.dart');
18 #import('../../../frog/file_system_node.dart'); 18 #import('../../../frog/file_system_node.dart');
19 #import('../../../frog/file_system.dart'); 19 #import('../../../frog/file_system.dart');
20 #import('../../../utils/dartdoc/dartdoc.dart', prefix: 'doc'); 20 #import('../../../utils/dartdoc/dartdoc.dart', prefix: 'doc');
21 21
22 HtmlDiff _diff; 22 HtmlDiff _diff;
23 23
24 void main() { 24 void main() {
25 var files = new NodeFileSystem(); 25 var files = new NodeFileSystem();
26 parseOptions('../../frog', [] /* args */, files); 26 parseOptions('../../frog', [] /* args */, files);
27 initializeWorld(files); 27 initializeWorld(files);
28 doc.initializeDartDoc(); 28 final htmldoc = new Htmldoc();
29 HtmlDiff.initialize(); 29 HtmlDiff.initialize();
30 30
31 _diff = new HtmlDiff(); 31 _diff = new HtmlDiff();
32 _diff.run(); 32 _diff.run();
33 world.reset(); 33 world.reset();
34 34
35 doc.addMethodDocumenter(addMemberDoc); 35 htmldoc.document('html');
36 doc.addFieldDocumenter(addMemberDoc); 36 }
37 doc.addTypeDocumenter(addTypeDoc); 37
38 doc.document('html'); 38 class Htmldoc extends doc.Dartdoc {
39 getTypeComment(Type type) {
40 return _mergeComments(super.getTypeComment(type), getTypeDoc(type));
41 }
42
43 getMethodComment(MethodMember method) {
44 return _mergeComments(super.getMethodComment(method), getMemberDoc(method));
45 }
46
47 getFieldComment(FieldMember field) {
48 return _mergeComments(super.getFieldComment(field), getMemberDoc(field));
49 }
50
51 String _mergeComments(String comment, String extra) {
52 if (comment == null) return extra;
53 return '$comment\n\n$extra';
54 }
39 } 55 }
40 56
41 /** 57 /**
42 * Returns a Markdown-formatted link to [member], relative to a type page that 58 * Returns a Markdown-formatted link to [member], relative to a type page that
43 * may be in a different library than [member]. 59 * may be in a different library than [member].
44 */ 60 */
45 String _linkMember(Member member) { 61 String _linkMember(Member member) {
46 final typeName = member.declaringType.name; 62 final typeName = member.declaringType.name;
47 var memberName = "$typeName.${member.name}"; 63 var memberName = "$typeName.${member.name}";
48 if (member.isConstructor || member.isFactory) { 64 if (member.isConstructor || member.isFactory) {
(...skipping 25 matching lines...) Expand all
74 var getName = m.name.replaceFirst('set:', 'get:'); 90 var getName = m.name.replaceFirst('set:', 'get:');
75 return !members.some((maybeGet) => maybeGet.name == getName); 91 return !members.some((maybeGet) => maybeGet.name == getName);
76 }); 92 });
77 } 93 }
78 94
79 /** 95 /**
80 * Returns additional Markdown-formatted documentation for [member], linking it 96 * Returns additional Markdown-formatted documentation for [member], linking it
81 * to the corresponding `dart:html` or `dart:dom` [Member](s). If [member] is 97 * to the corresponding `dart:html` or `dart:dom` [Member](s). If [member] is
82 * not in `dart:html` or `dart:dom`, returns no additional documentation. 98 * not in `dart:html` or `dart:dom`, returns no additional documentation.
83 */ 99 */
84 String addMemberDoc(Member member) { 100 String getMemberDoc(Member member) {
85 if (_diff.domToHtml.containsKey(member)) { 101 if (_diff.domToHtml.containsKey(member)) {
86 final htmlMemberSet = _unifyProperties(_diff.domToHtml[member]); 102 final htmlMemberSet = _unifyProperties(_diff.domToHtml[member]);
87 final allSameName = htmlMemberSet.every((m) => _diff.sameName(member, m)); 103 final allSameName = htmlMemberSet.every((m) => _diff.sameName(member, m));
88 final phrase = allSameName ? "available as" : "renamed to"; 104 final phrase = allSameName ? "available as" : "renamed to";
89 final htmlMembers = doc.joinWithCommas(map(htmlMemberSet, _linkMember)); 105 final htmlMembers = doc.joinWithCommas(map(htmlMemberSet, _linkMember));
90 return "_This is $phrase $htmlMembers in the " + 106 return "_This is $phrase $htmlMembers in the " +
91 "[dart:html](../html.html) library._"; 107 "[dart:html](../html.html) library._";
92 } else if (_diff.htmlToDom.containsKey(member)) { 108 } else if (_diff.htmlToDom.containsKey(member)) {
93 final domMemberSet = _unifyProperties(_diff.htmlToDom[member]); 109 final domMemberSet = _unifyProperties(_diff.htmlToDom[member]);
94 final allSameName = domMemberSet.every((m) => _diff.sameName(m, member)); 110 final allSameName = domMemberSet.every((m) => _diff.sameName(m, member));
95 final phrase = allSameName ? "is the same as" : "renames"; 111 final phrase = allSameName ? "is the same as" : "renames";
96 final domMembers = doc.joinWithCommas(map(domMemberSet, _linkMember)); 112 final domMembers = doc.joinWithCommas(map(domMemberSet, _linkMember));
97 return "_This $phrase $domMembers in the [dart:dom](../dom.html) " + 113 return "_This $phrase $domMembers in the [dart:dom](../dom.html) " +
98 "library._"; 114 "library._";
99 } else { 115 } else {
100 return ""; 116 return "";
101 } 117 }
102 } 118 }
103 119
104 /** 120 /**
105 * Returns additional Markdown-formatted documentation for [type], linking it to 121 * Returns additional Markdown-formatted documentation for [type], linking it to
106 * the corresponding `dart:html` or `dart:dom` [Type](s). If [type] is not in 122 * the corresponding `dart:html` or `dart:dom` [Type](s). If [type] is not in
107 * `dart:html` or `dart:dom`, returns no additional documentation. 123 * `dart:html` or `dart:dom`, returns no additional documentation.
108 */ 124 */
109 String addTypeDoc(Type type) { 125 String getTypeDoc(Type type) {
110 if (_diff.domTypesToHtml.containsKey(type)) { 126 if (_diff.domTypesToHtml.containsKey(type)) {
111 var htmlTypes = doc.joinWithCommas( 127 var htmlTypes = doc.joinWithCommas(
112 map(_diff.domTypesToHtml[type], _linkType)); 128 map(_diff.domTypesToHtml[type], _linkType));
113 return "_This corresponds to $htmlTypes in the [dart:html](../html.html) " + 129 return "_This corresponds to $htmlTypes in the [dart:html](../html.html) " +
114 "library._"; 130 "library._";
115 } else if (_diff.htmlTypesToDom.containsKey(type)) { 131 } else if (_diff.htmlTypesToDom.containsKey(type)) {
116 var domTypes = doc.joinWithCommas( 132 var domTypes = doc.joinWithCommas(
117 map(_diff.htmlTypesToDom[type], _linkType)); 133 map(_diff.htmlTypesToDom[type], _linkType));
118 return "_This corresponds to $domTypes in the [dart:dom](../dom.html) " + 134 return "_This corresponds to $domTypes in the [dart:dom](../dom.html) " +
119 "library._"; 135 "library._";
120 } else { 136 } else {
121 return ""; 137 return "";
122 } 138 }
123 } 139 }
OLDNEW
« no previous file with comments | « client/html/scripts/html_diff.dart ('k') | utils/dartdoc/comment_map.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698