Skip to content

Commit

Permalink
Appending working for library_list.json
Browse files Browse the repository at this point in the history
R=rnystrom@google.com

Review URL: https://codereview.chromium.org//23003010

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@26294 260f80e4-7a28-3924-810f-c04153c831b5
  • Loading branch information
janicejl committed Aug 16, 2013
1 parent 682785d commit 83ae491
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 21 deletions.
8 changes: 5 additions & 3 deletions pkg/docgen/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,21 @@ Run `dart docgen.dart [OPTIONS] <path to directory or file>`

- `-h`, `--help` Prints help and usage information.
- `-v`, `--verbose` Output more logging information.
- `-j`, `--[no-]json` Outputs to JSON. Files are outputted to YAML by default.
- `-j`, `--[no-]json` Outputs to JSON. Files are outputted to YAML by default.
If `--append` is used, it takes the file-format of the previous run stated in
library_list.json ignoring the flag.
- `--include-private` Flag to include private declarations.
- `--include-sdk` Flag to parse SDK Library files imported.
- `--parse-sdk` Parses the SDK libraries only. (Ignores the path passed in.)
- `--package-root` Sets the package root of the library being analyzed.
- `--append` Appends to the docs folder, library_list.txt, and index.txt.
- `--append` Appends to the docs folder, library_list.json, and index.txt.
- `--introduction` Adds the provided markdown text file as the introduction
for the outputted documentation.


###### Output Directory
Documented libraries will be located at bin/docs in either YAML or JSON format
depending on options specified. There will also be a library_list.txt,
depending on options specified. There will also be a library_list.json,
containing a list of all the libraries inside the docs folder.

To get more information on how to use the outputted documentation with
Expand Down
6 changes: 4 additions & 2 deletions pkg/docgen/bin/docgen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ ArgParser _initArgParser() {
if (verbose) Logger.root.level = Level.FINEST;
});
parser.addFlag('json', abbr: 'j',
help: 'Outputs to JSON. Files are outputted to YAML by default.',
help: 'Outputs to JSON. Files are outputted to YAML by default. '
'If --append is used, it takes the file-format of the previous '
'run stated in library_list.json ignoring the flag.',
negatable: true);
parser.addFlag('include-private',
help: 'Flag to include private declarations.', negatable: false);
Expand All @@ -61,7 +63,7 @@ ArgParser _initArgParser() {
parser.addOption('package-root',
help: 'Sets the package root of the library being analyzed.');
parser.addFlag('append',
help: 'Append to the docs folder, library_list.txt and index.txt',
help: 'Append to the docs folder, library_list.json and index.txt',
defaultsTo: false, negatable: false);
parser.addOption('introduction',
help: 'Adds the provided markdown text file as the introduction'
Expand Down
50 changes: 34 additions & 16 deletions pkg/docgen/lib/docgen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -244,26 +244,44 @@ void _documentLibraries(List<LibraryMirror> libs, {bool includeSdk: false,
if (parseSdk) entityMap['dart.core.Object'].subclasses.clear();

var filteredEntities = entityMap.values.where(_isVisible);

// Outputs a JSON file with all libraries and their preview comments.
// This will help the viewer know what libraries are available to read in.
var libraryMap;
if (append) {
var docsDir = listDir('docs');
if (!docsDir.contains('docs/library_list.json')) {
throw new StateError('No library_list.json');
}
libraryMap = parse(new File('docs/library_list.json').readAsStringSync());
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;
}
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),
'filetype' : outputToYaml ? 'yaml' : 'json'
};
}
_writeToFile(stringify(libraryMap), 'library_list.json');
// Output libraries and classes to file after all information is generated.
filteredEntities.where((e) => e is Class || e is Library).forEach((output) {
_writeIndexableToFile(output, outputToYaml);
});
// Outputs a YAML or JSON file with all libraries and their preview comments
// after creating all libraries. This will help the viewer know what
// libraries are available to read in.
var 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)
};
if (outputToYaml) {
_writeToFile(getYamlString(libraryMap), 'library_list.yaml',
append: append);
} else {
_writeToFile(stringify(libraryMap), 'library_list.json', append: append);
}
// Outputs all the qualified names documented with their type.
// This will help generate search results.
_writeToFile(filteredEntities.map((e) =>
Expand Down

0 comments on commit 83ae491

Please sign in to comment.