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

Side by Side 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: 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 /// **docgen** is a tool for creating machine readable representations of Dart 5 /// **docgen** is a tool for creating machine readable representations of Dart
6 /// code metadata, including: classes, members, comments and annotations. 6 /// code metadata, including: classes, members, comments and annotations.
7 /// 7 ///
8 /// docgen is run on a `.dart` file or a directory containing `.dart` files. 8 /// docgen is run on a `.dart` file or a directory containing `.dart` files.
9 /// 9 ///
10 /// $ dart docgen.dart [OPTIONS] [FILE/DIR] 10 /// $ dart docgen.dart [OPTIONS] [FILE/DIR]
(...skipping 24 matching lines...) Expand all
35 import '../../../sdk/lib/_internal/libraries.dart'; 35 import '../../../sdk/lib/_internal/libraries.dart';
36 36
37 var logger = new Logger('Docgen'); 37 var logger = new Logger('Docgen');
38 38
39 const DEFAULT_OUTPUT_DIRECTORY = 'docs'; 39 const DEFAULT_OUTPUT_DIRECTORY = 'docs';
40 40
41 var _outputDirectory; 41 var _outputDirectory;
42 42
43 const String USAGE = 'Usage: dart docgen.dart [OPTIONS] fooDir/barFile'; 43 const String USAGE = 'Usage: dart docgen.dart [OPTIONS] fooDir/barFile';
44 44
45
46 List<String> skippedAnnotations = const [ 45 List<String> skippedAnnotations = const [
47 'metadata.DocsEditable', '_js_helper.JSName', '_js_helper.Creates', 46 'metadata.DocsEditable', '_js_helper.JSName', '_js_helper.Creates',
48 '_js_helper.Returns']; 47 '_js_helper.Returns'];
49 48
49 /**
Bob Nystrom 2014/01/08 00:16:57 Use a ///-style doc comment like the rest of this
Alan Knight 2014/01/08 01:22:52 Done.
50 * If we can't find the SDK introduction text, which will happen if running
51 * from a snapshot and using --parse-sdk or --include-sdk, then use this
52 * hard-coded version. This should be updated to be consistent with the text
53 * in docgen/doc/sdk-introduction.md
54 */
55 const String DEFAULT_SDK_INTRODUCTION = """
Bob Nystrom 2014/01/08 00:16:57 You don't need to type annotate constants.
Alan Knight 2014/01/08 01:22:52 Done.
56 Welcome to the Dart API reference documentation,
57 covering the official Dart API libraries.
58 Some of the most fundamental Dart libraries include:
59
60 * [dart:core](#dart:core):
61 Core functionality such as strings, numbers, collections, errors,
62 dates, and URIs.
63 * [dart:html](#dart:html):
64 DOM manipulation for web apps.
65 * [dart:io](#dart:io):
66 I/O for command-line apps.
67
68 Except for dart:core, you must import a library before you can use it.
69 Here's an example of importing dart:html, dart:math, and a
70 third popular library called
71 [polymer.dart](http://www.dartlang.org/polymer-dart/):
72
73 import 'dart:html';
74 import 'dart:math';
75 import 'package:polymer/polymer.dart';
76
77 Polymer.dart is an example of a library that isn't
78 included in the Dart download,
79 but is easy to get and update using the _pub package manager_.
80 For information on finding, using, and publishing libraries (and more)
81 with pub, see
82 [pub.dartlang.org](http://pub.dartlang.org).
83
84 The main site for learning and using Dart is
85 [www.dartlang.org](http://www.dartlang.org).
86 Check out these pages:
87
88 * [Dart homepage](http://www.dartlang.org)
89 * [Tutorials](http://www.dartlang.org/docs/tutorials/)
90 * [Programmer's Guide](http://www.dartlang.org/docs/)
91 * [Samples](http://www.dartlang.org/samples/)
92 * [A Tour of the Dart Libraries](http://www.dartlang.org/docs/dart-up-and-runn ing/contents/ch03.html)
93
94 This API reference is automatically generated from the source code in the
95 [Dart project](https://code.google.com/p/dart/).
96 If you'd like to contribute to this documentation, see
97 [Contributing](https://code.google.com/p/dart/wiki/Contributing)
98 and
99 [Writing API Documentation](https://code.google.com/p/dart/wiki/WritingApiDocume ntation).
100 """;
101
50 /// Set of libraries declared in the SDK, so libraries that can be accessed 102 /// Set of libraries declared in the SDK, so libraries that can be accessed
51 /// when running dart by default. 103 /// when running dart by default.
52 Iterable<LibraryMirror> _sdkLibraries; 104 Iterable<LibraryMirror> _sdkLibraries;
53 105
54 /// The dart:core library, which contains all types that are always available 106 /// The dart:core library, which contains all types that are always available
55 /// without import. 107 /// without import.
56 LibraryMirror _coreLibrary; 108 LibraryMirror _coreLibrary;
57 109
58 /// Support for [:foo:]-style code comments to the markdown parser. 110 /// Support for [:foo:]-style code comments to the markdown parser.
59 List<markdown.InlineSyntax> markdownSyntaxes = 111 List<markdown.InlineSyntax> markdownSyntaxes =
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after
350 // Everything is a subclass of Object, therefore empty the list to avoid a 402 // Everything is a subclass of Object, therefore empty the list to avoid a
351 // giant list of subclasses to be printed out. 403 // giant list of subclasses to be printed out.
352 if (includeSdk) (entityMap['dart-core.Object'] as Class).subclasses.clear(); 404 if (includeSdk) (entityMap['dart-core.Object'] as Class).subclasses.clear();
353 405
354 var filteredEntities = entityMap.values.where(_isVisible); 406 var filteredEntities = entityMap.values.where(_isVisible);
355 407
356 // Outputs a JSON file with all libraries and their preview comments. 408 // Outputs a JSON file with all libraries and their preview comments.
357 // This will help the viewer know what libraries are available to read in. 409 // This will help the viewer know what libraries are available to read in.
358 var libraryMap; 410 var libraryMap;
359 var linkResolver = (name) => fixReference(name, null, null, null); 411 var linkResolver = (name) => fixReference(name, null, null, null);
412
413 String readIntro(String introFileName) {
414 var introFile = new File(introFileName);
415 var introText = introFile.existsSync() ? introFile.readAsStringSync :
416 DEFAULT_SDK_INTRODUCTION;
417 return markdown.markdownToHtml(introText,
418 linkResolver: linkResolver, inlineSyntaxes: markdownSyntaxes);
419 }
420
360 if (append) { 421 if (append) {
361 var docsDir = listDir(_outputDirectory); 422 var docsDir = listDir(_outputDirectory);
362 if (!docsDir.contains('$_outputDirectory/library_list.json')) { 423 if (!docsDir.contains('$_outputDirectory/library_list.json')) {
363 throw new StateError('No library_list.json'); 424 throw new StateError('No library_list.json');
364 } 425 }
365 libraryMap = 426 libraryMap =
366 JSON.decode(new File( 427 JSON.decode(new File(
367 '$_outputDirectory/library_list.json').readAsStringSync()); 428 '$_outputDirectory/library_list.json').readAsStringSync());
368 libraryMap['libraries'].addAll(filteredEntities 429 libraryMap['libraries'].addAll(filteredEntities
369 .where((e) => e is Library) 430 .where((e) => e is Library)
370 .map((e) => e.previewMap)); 431 .map((e) => e.previewMap));
371 if (introduction.isNotEmpty) { 432 if (introduction.isNotEmpty) {
372 var intro = libraryMap['introduction']; 433 var intro = libraryMap['introduction'];
373 if (intro.isNotEmpty) intro += '<br/><br/>'; 434 if (intro.isNotEmpty) intro += '<br/><br/>';
374 intro += markdown.markdownToHtml( 435 libraryMap['introduction'] = "$intro${readIntro(introduction)}";
375 new File(introduction).readAsStringSync(),
376 linkResolver: linkResolver, inlineSyntaxes: markdownSyntaxes);
377 libraryMap['introduction'] = intro;
378 } 436 }
379 outputToYaml = libraryMap['filetype'] == 'yaml'; 437 outputToYaml = libraryMap['filetype'] == 'yaml';
380 } else { 438 } else {
381 libraryMap = { 439 libraryMap = {
382 'libraries' : filteredEntities.where((e) => 440 'libraries' : filteredEntities.where((e) =>
383 e is Library).map((e) => e.previewMap).toList(), 441 e is Library).map((e) => e.previewMap).toList(),
384 'introduction' : introduction == '' ? 442 'introduction' : introduction.isEmpty ? '' : readIntro(introduction),
385 '' : markdown.markdownToHtml(new File(introduction)
386 .readAsStringSync(), linkResolver: linkResolver,
387 inlineSyntaxes: markdownSyntaxes),
388 'filetype' : outputToYaml ? 'yaml' : 'json' 443 'filetype' : outputToYaml ? 'yaml' : 'json'
389 }; 444 };
390 } 445 }
391 _writeToFile(JSON.encode(libraryMap), 'library_list.json'); 446 _writeToFile(JSON.encode(libraryMap), 'library_list.json');
392 447
393 // Output libraries and classes to file after all information is generated. 448 // Output libraries and classes to file after all information is generated.
394 filteredEntities.where((e) => e is Class || e is Library).forEach((output) { 449 filteredEntities.where((e) => e is Class || e is Library).forEach((output) {
395 _writeIndexableToFile(output, outputToYaml); 450 _writeIndexableToFile(output, outputToYaml);
396 }); 451 });
397 452
(...skipping 1303 matching lines...) Expand 10 before | Expand all | Expand 10 after
1701 /// Remove statics from the map of inherited items before adding them. 1756 /// Remove statics from the map of inherited items before adding them.
1702 Map _filterStatics(Map items) { 1757 Map _filterStatics(Map items) {
1703 var result = {}; 1758 var result = {};
1704 items.forEach((name, item) { 1759 items.forEach((name, item) {
1705 if (!item.isStatic) { 1760 if (!item.isStatic) {
1706 result[name] = item; 1761 result[name] = item;
1707 } 1762 }
1708 }); 1763 });
1709 return result; 1764 return result;
1710 } 1765 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698