Index: utils/apidoc/apidoc.dart |
diff --git a/utils/apidoc/apidoc.dart b/utils/apidoc/apidoc.dart |
index 92f12c9445ec459705b847c88213919f393e593d..077b2b9c2a2d2d135d75bd1329081d1bec9b8d9f 100644 |
--- a/utils/apidoc/apidoc.dart |
+++ b/utils/apidoc/apidoc.dart |
@@ -104,6 +104,16 @@ void main() { |
HtmlDiff.initialize(); |
_diff = new HtmlDiff(printWarnings:false); |
_diff.run(); |
+ |
+ // Process handwritten HTML documentation. |
+ world.reset(); |
+ world.getOrAddLibrary('${doc.scriptDir}/../../lib/html/doc/html.dartdoc'); |
+ world.process(); |
+ final htmldoc = new Htmldoc(); |
+ 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
|
+ print('Processing handwritten HTML documentation...'); |
+ |
+ // Process libraries. |
world.reset(); |
// Add all of the core libraries. |
@@ -121,17 +131,119 @@ void main() { |
world.process(); |
print('Generating docs...'); |
- final apidoc = new Apidoc(mdn, outputDir, mode, generateAppCache); |
+ final apidoc = new Apidoc(mdn, htmldoc, outputDir, mode, generateAppCache); |
Futures.wait([scriptCompiled, copiedStatic, copiedApiDocStatic]).then((_) { |
apidoc.document(); |
}); |
} |
+/** |
+ * This class is purely here to scrape handwritten HTML documentation. |
+ * This scraped documentation will later be merged with the generated |
+ * 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
|
+ */ |
+class Htmldoc extends doc.Dartdoc { |
+ String libraryComment; |
+ Map<String, String> typeComments; |
+ Map<String, Map<String, String>> memberComments; |
+ |
+ Htmldoc() { |
+ typeComments = new Map<String, String>(); |
+ memberComments = new Map<String, Map<String, String>>(); |
+ } |
+ |
+ String getRecordedLibraryComment(Library library) { |
+ if (library.name == 'html') { |
+ return libraryComment; |
+ } |
+ return null; |
+ } |
+ |
+ String getRecordedTypeComment(Type type) { |
+ if (type.library.name == 'html') { |
+ if (typeComments.containsKey(type.name)) { |
+ return typeComments[type.name]; |
+ } |
+ } |
+ return null; |
+ } |
+ |
+ String getRecordedMemberComment(Member member) { |
+ if (member.library.name == 'html') { |
+ String typeName; |
+ if (member.declaringType != null) { |
+ typeName = member.declaringType.name; |
+ } |
+ if (typeName == null) { |
+ typeName = ''; |
+ } |
+ if (memberComments.containsKey(typeName)) { |
+ Map<String, String> memberMap = memberComments[typeName]; |
+ if (memberMap.containsKey(member.name)) { |
+ return memberMap[member.name]; |
+ } |
+ } |
+ } |
+ return null; |
+ } |
+ |
+ // These methods are subclassed and used for internal processing. |
+ // Do not invoke outside of this class. |
+ String getLibraryComment(Library library) { |
+ String comment = super.getLibraryComment(library); |
+ libraryComment = comment; |
+ return comment; |
+ } |
+ |
+ String getTypeComment(Type type) { |
+ String comment = super.getTypeComment(type); |
+ recordTypeComment(type, comment); |
+ return comment; |
+ } |
+ |
+ String getMethodComment(MethodMember method) { |
+ String comment = super.getMethodComment(method); |
+ recordMemberComment(method, comment); |
+ return comment; |
+ } |
+ |
+ String getFieldComment(FieldMember field) { |
+ String comment = super.getFieldComment(field); |
+ recordMemberComment(field, comment); |
+ return comment; |
+ } |
+ |
+ void recordTypeComment(Type type, String comment) { |
+ if (comment != null && comment.contains('@domName')) { |
+ // This is not a handwritten comment. |
+ return; |
+ } |
+ typeComments[type.name] = comment; |
+ } |
+ |
+ void recordMemberComment(Member member, String comment) { |
+ if (comment != null && comment.contains('@domName')) { |
+ // This is not a handwritten comment. |
+ return; |
+ } |
+ String typeName = member.declaringType.name; |
+ if (typeName == null) |
+ typeName = ''; |
+ if (!memberComments.containsKey(typeName)) { |
+ memberComments[typeName] = new Map<String, String>(); |
+ } |
+ Map<String, String> memberMap = memberComments[typeName]; |
+ memberMap[member.name] = comment; |
+ } |
+} |
+ |
class Apidoc extends doc.Dartdoc { |
/** Big ball of JSON containing the scraped MDN documentation. */ |
final Map mdn; |
+ final Htmldoc htmldoc; |
+ |
static final disqusShortname = 'dartapidocs'; |
/** |
@@ -141,7 +253,8 @@ class Apidoc extends doc.Dartdoc { |
*/ |
String mdnUrl; |
- Apidoc(this.mdn, String outputDir, int mode, bool generateAppCache) { |
+ Apidoc(this.mdn, this.htmldoc, String outputDir, int mode, |
+ bool generateAppCache) { |
this.outputDir = outputDir; |
this.mode = mode; |
this.generateAppCache = generateAppCache; |
@@ -253,24 +366,37 @@ class Apidoc extends doc.Dartdoc { |
comment.replaceAll(const RegExp("@([a-zA-Z]+) ([^;]+)(?:;|\$)"), '')); |
} |
+ String getLibraryComment(Library library) { |
+ if (library.name == 'html') { |
+ return htmldoc.libraryComment; |
+ } |
+ return super.getLibraryComment(library); |
+ } |
+ |
String getTypeComment(Type type) { |
return _mergeDocs( |
- includeMdnTypeComment(type), super.getTypeComment(type)); |
+ includeMdnTypeComment(type), super.getTypeComment(type), |
+ htmldoc.getRecordedTypeComment(type)); |
} |
String getMethodComment(MethodMember method) { |
return _mergeDocs( |
- includeMdnMemberComment(method), super.getMethodComment(method)); |
+ includeMdnMemberComment(method), super.getMethodComment(method), |
+ htmldoc.getRecordedMemberComment(method)); |
} |
String getFieldComment(FieldMember field) { |
return _mergeDocs( |
- includeMdnMemberComment(field), super.getFieldComment(field)); |
+ includeMdnMemberComment(field), super.getFieldComment(field), |
+ htmldoc.getRecordedMemberComment(field)); |
} |
bool isNonEmpty(String string) => (string != null) && (string.trim() != ''); |
- String _mergeDocs(String mdnComment, String dartComment) { |
+ String _mergeDocs(String mdnComment, String dartComment, String override) { |
+ // Prefer override first. |
+ if (isNonEmpty(override)) return override; |
+ |
// 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
|
if (isNonEmpty(dartComment)) return dartComment; |