| Index: pkg/docgen/bin/docgen.dart
|
| diff --git a/pkg/docgen/bin/docgen.dart b/pkg/docgen/bin/docgen.dart
|
| index c74c07fdc164b4c0659c468d957acb0d91564dc6..22c72b7626958280371564acc7f6ec0375744d08 100644
|
| --- a/pkg/docgen/bin/docgen.dart
|
| +++ b/pkg/docgen/bin/docgen.dart
|
| @@ -10,7 +10,9 @@
|
| */
|
| library docgen;
|
|
|
| +// TODO(tmandel): Use 'package:' references for imports with relative paths.
|
| import 'dart:io';
|
| +import 'dart:json';
|
| import 'dart:async';
|
| import '../lib/dart2yaml.dart';
|
| import '../lib/src/dart2js_mirrors.dart';
|
| @@ -64,6 +66,21 @@ class Docgen {
|
| /// Current member being documented to be used for comment links.
|
| MemberMirror _currentMember;
|
|
|
| + /// Should the output file type be JSON?
|
| + // TODO(tmandel): Add flag to allow for output to JSON.
|
| + bool outputToJson = false;
|
| +
|
| + /// Resolves reference links
|
| + markdown.Resolver linkResolver;
|
| +
|
| + /**
|
| + * Docgen constructor initializes the link resolver for markdown parsing.
|
| + */
|
| + Docgen() {
|
| + this.linkResolver = (name) =>
|
| + fixReference(name, _currentLibrary, _currentClass, _currentMember);
|
| + }
|
| +
|
| /**
|
| * Creates documentation for filtered libraries.
|
| */
|
| @@ -74,7 +91,11 @@ class Docgen {
|
| var result = new Library(library.qualifiedName, _getComment(library),
|
| _getVariables(library.variables), _getMethods(library.functions),
|
| _getClasses(library.classes));
|
| - _writeToFile(getYamlString(result.toMap()), "${result.name}.yaml");
|
| + if (outputToJson) {
|
| + _writeToFile(stringify(result.toMap()), "${result.name}.json");
|
| + } else {
|
| + _writeToFile(getYamlString(result.toMap()), "${result.name}.yaml");
|
| + }
|
| });
|
| }
|
|
|
| @@ -96,10 +117,18 @@ class Docgen {
|
| }
|
| }
|
| });
|
| - // TODO(tmandel): Resolve links to members in markdown using _currentClass,
|
| - // _currentMember, and _currentLibrary.
|
| return commentText == null ? "" :
|
| - markdown.markdownToHtml(commentText.trim());
|
| + markdown.markdownToHtml(commentText.trim(), linkResolver: linkResolver);
|
| + }
|
| +
|
| + /**
|
| + * Converts all [_] references in comments to <code>_</code>.
|
| + */
|
| + // TODO(tmandel): Create proper links for [_] style markdown based
|
| + // on scope once layout of viewer is finished.
|
| + markdown.Node fixReference(String name, LibraryMirror currentLibrary,
|
| + ClassMirror currentClass, MemberMirror currentMember) {
|
| + return new markdown.Element.text('code', name);
|
| }
|
|
|
| /**
|
| @@ -242,9 +271,9 @@ class Class {
|
| classMap["name"] = name;
|
| classMap["comment"] = comment;
|
| classMap["superclass"] = superclass;
|
| - classMap["abstract"] = isAbstract;
|
| - classMap["typedef"] = isTypedef;
|
| - classMap["implements"] = interfaces;
|
| + classMap["abstract"] = isAbstract.toString();
|
| + classMap["typedef"] = isTypedef.toString();
|
| + classMap["implements"] = new List.from(interfaces);
|
| classMap["variables"] = recurseMap(variables);
|
| classMap["methods"] = recurseMap(methods);
|
| return classMap;
|
| @@ -271,8 +300,8 @@ class Variable {
|
| var variableMap = {};
|
| variableMap["name"] = name;
|
| variableMap["comment"] = comment;
|
| - variableMap["final"] = isFinal;
|
| - variableMap["static"] = isStatic;
|
| + variableMap["final"] = isFinal.toString();
|
| + variableMap["static"] = isStatic.toString();
|
| variableMap["type"] = type;
|
| return variableMap;
|
| }
|
| @@ -306,9 +335,9 @@ class Method {
|
| var methodMap = {};
|
| methodMap["name"] = name;
|
| methodMap["comment"] = comment;
|
| - methodMap["type"] = isSetter ? "Setter" : isGetter ? "Getter" :
|
| - isOperator ? "Operator" : isConstructor ? "Constructor" : "Method";
|
| - methodMap["static"] = isStatic;
|
| + methodMap["type"] = isSetter ? "setter" : isGetter ? "getter" :
|
| + isOperator ? "operator" : isConstructor ? "constructor" : "method";
|
| + methodMap["static"] = isStatic.toString();
|
| methodMap["return"] = returnType;
|
| methodMap["parameters"] = recurseMap(parameters);
|
| return methodMap;
|
| @@ -334,8 +363,9 @@ class Parameter {
|
| Map toMap() {
|
| var parameterMap = {};
|
| parameterMap["name"] = name;
|
| - parameterMap["optional"] = isOptional;
|
| - parameterMap["default"] = hasDefaultValue;
|
| + parameterMap["optional"] = isOptional.toString();
|
| + parameterMap["named"] = isNamed.toString();
|
| + parameterMap["default"] = hasDefaultValue.toString();
|
| parameterMap["type"] = type;
|
| parameterMap["value"] = defaultValue;
|
| return parameterMap;
|
|
|