Skip to content

add version info, process excludes #26

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Dec 1, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 18 additions & 15 deletions lib/dartdoc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ const String DEFAULT_OUTPUT_DIRECTORY = 'docs';
/// directory.
class DartDoc {

//TODO(keertip): implement excludes
List<String> _excludes;
Directory _rootDir;
final CSS css = new CSS();
Expand All @@ -45,7 +44,16 @@ class DartDoc {
Stopwatch stopwatch = new Stopwatch();
stopwatch.start();
var files = findFilesToDocumentInPackage(_rootDir.path);
libraries.addAll(parseLibraries(files));
List<LibraryElement> libs = [];
libs.addAll(parseLibraries(files));
// remove excluded libraries
_excludes.forEach(
(pattern) => libs.removeWhere((l) => l.name.startsWith(pattern)));
libs.removeWhere(
(LibraryElement library) => _excludes.contains(library.name));
libs.sort(elementCompare);
libraries.addAll(libs);

generator = new GeneratorHelper(libraries);
// create the out directory
out = new Directory(DEFAULT_OUTPUT_DIRECTORY);
Expand Down Expand Up @@ -79,6 +87,7 @@ class DartDoc {
context.sourceFactory = sourceFactory;

files.forEach((String filePath) {
print('parsing ${filePath}...');
Source source = new FileBasedSource.con1(new JavaFile(filePath));
if (context.computeKindOf(source) == SourceKind.LIBRARY) {
LibraryElement library = context.computeLibraryElement(source);
Expand Down Expand Up @@ -108,6 +117,7 @@ class DartDoc {
void generatePackage() {
var packageName = getPackageName(_rootDir.path);
var packageDesc = getPackageDescription(_rootDir.path);
var packageVersion = getPackageVersion(_rootDir.path);
if (packageName.isNotEmpty) {
File f = joinFile(new Directory(out.path), ['${packageName}_package.html']);
print('generating ${f.path}');
Expand All @@ -122,7 +132,9 @@ class DartDoc {
html.startTag('div', attributes: "class='span3'");
html.startTag('ul', attributes: 'class="nav nav-tabs nav-stacked left-nav"');
html.startTag('li', attributes: 'class="active"', newLine: false);
html.write('<a href="${packageName}">' '<i class="chevron-nav icon-white icon-chevron-right"></i> ' '${packageName}</a>');
html.write('<a href="${packageName}">'
'<i class="chevron-nav icon-white icon-chevron-right"></i> '
'${packageName}-${packageVersion}</a>');
html.endTag(); //li
html.endTag(); //ul
html.endTag();
Expand All @@ -147,8 +159,6 @@ class DartDoc {

}



void generateLibrary(LibraryElement library) {
File f = joinFile(new Directory(out.path), [getFileNameFor(library)]);
print('generating ${f.path}');
Expand All @@ -165,18 +175,11 @@ class DartDoc {
// left nav
html.startTag('div', attributes: "class='span3'");
html.startTag('ul', attributes: 'class="nav nav-tabs nav-stacked left-nav"');
// for (LibraryElement lib in libraries) {
// if (lib == library) {
html.startTag('li', attributes: 'class="active"', newLine: false);
html.write('<a href="${getFileNameFor(library)}">' '<i class="chevron-nav icon-white icon-chevron-right"></i> ' '${library.name}</a>');
// } else {
// html.startTag('li', newLine: false);
// html.write('<a href="${getFileNameFor(lib)}">'
// '<i class="chevron-nav icon-chevron-right"></i> '
// '${lib.name}</a>');
// }
html.write('<a href="${getFileNameFor(library)}">'
'<i class="chevron-nav icon-white icon-chevron-right"></i> '
'${library.name}</a>');
html.endTag(); // li
// }
html.endTag(); // ul.nav
html.endTag(); // div.span3

Expand Down
25 changes: 13 additions & 12 deletions lib/src/package_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,26 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.


library dartdoc.package_utils;

import 'dart:io';

import 'package:path/path.dart' as path;
import 'package:yaml/yaml.dart';


String getPackageName(String directoryName) =>
_getPubspec(directoryName)['name'];

Map _getPubspec(String directoryName) {
var pubspecName = path.join(directoryName, 'pubspec.yaml');
File pubspec = new File(pubspecName);
if (!pubspec.existsSync()) return {'name': ''};
var contents = pubspec.readAsStringSync();
return loadYaml(contents);
}

String getPackageDescription(String directoryName) =>
_getPubspec(directoryName)['description'];
Map _getPubspec(String directoryName) {
var pubspecName = path.join(directoryName, 'pubspec.yaml');
File pubspec = new File(pubspecName);
if (!pubspec.existsSync()) return {'name': ''};
var contents = pubspec.readAsStringSync();
return loadYaml(contents);
}

String getPackageDescription(String directoryName) =>
_getPubspec(directoryName)['description'];

String getPackageVersion(String directoryName) =>
_getPubspec(directoryName)['version'];