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

Unified Diff: pkg/docgen/lib/docgen.dart

Issue 116043013: Add a snapshot for docgen and use it in the build (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Previous version could pass the default text as markdown instead of converting to html Created 6 years, 11 months 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 side-by-side diff with in-line comments
Download patch
Index: pkg/docgen/lib/docgen.dart
diff --git a/pkg/docgen/lib/docgen.dart b/pkg/docgen/lib/docgen.dart
index d75b60f6910434507e801f508b942d694a4d4623..46e280a075b6b0943e6915a67dcae16e0672e513 100644
--- a/pkg/docgen/lib/docgen.dart
+++ b/pkg/docgen/lib/docgen.dart
@@ -42,11 +42,61 @@ var _outputDirectory;
const String USAGE = 'Usage: dart docgen.dart [OPTIONS] fooDir/barFile';
-
List<String> skippedAnnotations = const [
'metadata.DocsEditable', '_js_helper.JSName', '_js_helper.Creates',
'_js_helper.Returns'];
+/// If we can't find the SDK introduction text, which will happen if running
+/// from a snapshot and using --parse-sdk or --include-sdk, then use this
+/// hard-coded version. This should be updated to be consistent with the text
+/// in docgen/doc/sdk-introduction.md
+const DEFAULT_SDK_INTRODUCTION = """
+Welcome to the Dart API reference documentation,
+covering the official Dart API libraries.
+Some of the most fundamental Dart libraries include:
+
+* [dart:core](#dart:core):
+ Core functionality such as strings, numbers, collections, errors,
+ dates, and URIs.
+* [dart:html](#dart:html):
+ DOM manipulation for web apps.
+* [dart:io](#dart:io):
+ I/O for command-line apps.
+
+Except for dart:core, you must import a library before you can use it.
+Here's an example of importing dart:html, dart:math, and a
+third popular library called
+[polymer.dart](http://www.dartlang.org/polymer-dart/):
+
+ import 'dart:html';
+ import 'dart:math';
+ import 'package:polymer/polymer.dart';
+
+Polymer.dart is an example of a library that isn't
+included in the Dart download,
+but is easy to get and update using the _pub package manager_.
+For information on finding, using, and publishing libraries (and more)
+with pub, see
+[pub.dartlang.org](http://pub.dartlang.org).
+
+The main site for learning and using Dart is
+[www.dartlang.org](http://www.dartlang.org).
+Check out these pages:
+
+ * [Dart homepage](http://www.dartlang.org)
+ * [Tutorials](http://www.dartlang.org/docs/tutorials/)
+ * [Programmer's Guide](http://www.dartlang.org/docs/)
+ * [Samples](http://www.dartlang.org/samples/)
+ * [A Tour of the Dart Libraries](http://www.dartlang.org/docs/dart-up-and-running/contents/ch03.html)
+
+This API reference is automatically generated from the source code in the
+[Dart project](https://code.google.com/p/dart/).
+If you'd like to contribute to this documentation, see
+[Contributing](https://code.google.com/p/dart/wiki/Contributing)
+and
+[Writing API Documentation](https://code.google.com/p/dart/wiki/WritingApiDocumentation).
+""";
+
/// Set of libraries declared in the SDK, so libraries that can be accessed
/// when running dart by default.
Iterable<LibraryMirror> _sdkLibraries;
@@ -92,7 +142,7 @@ Map _mdn;
/// Returned Future completes with true if document generation is successful.
Future<bool> docgen(List<String> files, {String packageRoot,
bool outputToYaml: true, bool includePrivate: false, bool includeSdk: false,
- bool parseSdk: false, bool append: false, String introduction: '',
+ bool parseSdk: false, bool append: false, String introFileName: '',
out: DEFAULT_OUTPUT_DIRECTORY, List<String> excludeLibraries,
bool includeDependentPackages}) {
_excluded = excludeLibraries;
@@ -145,7 +195,7 @@ Future<bool> docgen(List<String> files, {String packageRoot,
librariesToDocument.removeWhere((x) => _excluded.contains(x.simpleName));
_documentLibraries(librariesToDocument, includeSdk: includeSdk,
outputToYaml: outputToYaml, append: append, parseSdk: parseSdk,
- introduction: introduction);
+ introFileName: introFileName);
ricow1 2014/01/13 13:14:20 do we ever read this from a file now? if not just
Alan Knight 2014/01/13 17:36:04 We don't in the SDK, but if we're using this to ge
return true;
});
}
@@ -258,7 +308,7 @@ String _findPackageRoot(String directory) {
if (packageRoot != '') {
packageRoot = path.join(path.dirname(packageRoot), 'packages');
}
- return packageRoot;
+ return path.normalize(path.absolute(packageRoot));
}
/// Read a pubspec and return the library name.
@@ -334,7 +384,7 @@ Future<MirrorSystem> _analyzeLibraries(List<Uri> libraries,
/// Creates documentation for filtered libraries.
void _documentLibraries(List<LibraryMirror> libs, {bool includeSdk: false,
bool outputToYaml: true, bool append: false, bool parseSdk: false,
- String introduction: ''}) {
+ String introFileName: ''}) {
libs.forEach((lib) {
// Files belonging to the SDK have a uri that begins with 'dart:'.
if (includeSdk || !lib.uri.toString().startsWith('dart:')) {
@@ -357,6 +407,19 @@ void _documentLibraries(List<LibraryMirror> libs, {bool includeSdk: false,
// This will help the viewer know what libraries are available to read in.
var libraryMap;
var linkResolver = (name) => fixReference(name, null, null, null);
+
+ String readIntroductionFile(String fileName, includeSdk) {
+ var defaultText = includeSdk ? DEFAULT_SDK_INTRODUCTION : '';
+ var introText = defaultText;
+ if (fileName.isNotEmpty) {
+ var introFile = new File(fileName);
+ introText = introFile.existsSync() ? introFile.readAsStringSync() :
+ defaultText;
+ }
+ return markdown.markdownToHtml(introText,
+ linkResolver: linkResolver, inlineSyntaxes: markdownSyntaxes);
+ }
+
if (append) {
var docsDir = listDir(_outputDirectory);
if (!docsDir.contains('$_outputDirectory/library_list.json')) {
@@ -368,23 +431,16 @@ void _documentLibraries(List<LibraryMirror> libs, {bool includeSdk: false,
libraryMap['libraries'].addAll(filteredEntities
.where((e) => e is Library)
.map((e) => e.previewMap));
- if (introduction.isNotEmpty) {
- var intro = libraryMap['introduction'];
- if (intro.isNotEmpty) intro += '<br/><br/>';
- intro += markdown.markdownToHtml(
- new File(introduction).readAsStringSync(),
- linkResolver: linkResolver, inlineSyntaxes: markdownSyntaxes);
- libraryMap['introduction'] = intro;
- }
+ var intro = libraryMap['introduction'];
+ var spacing = intro.isEmpty ? '' : '<br/><br/>';
+ libraryMap['introduction'] =
+ "$intro$spacing${readIntroductionFile(introFileName, includeSdk)}";
outputToYaml = libraryMap['filetype'] == 'yaml';
} else {
libraryMap = {
'libraries' : filteredEntities.where((e) =>
e is Library).map((e) => e.previewMap).toList(),
- 'introduction' : introduction == '' ?
- '' : markdown.markdownToHtml(new File(introduction)
- .readAsStringSync(), linkResolver: linkResolver,
- inlineSyntaxes: markdownSyntaxes),
+ 'introduction' : readIntroductionFile(introFileName, includeSdk),
'filetype' : outputToYaml ? 'yaml' : 'json'
};
}
« no previous file with comments | « pkg/docgen/doc/sdk-introduction.md ('k') | sdk/bin/docgen » ('j') | sdk/bin/docgen.bat » ('J')

Powered by Google App Engine
This is Rietveld 408576698