Skip to content

Commit

Permalink
Merge pull request #25 from keertip/package
Browse files Browse the repository at this point in the history
add a top level html file for package
  • Loading branch information
keertip committed Nov 28, 2014
2 parents 14c4007 + 873264c commit 90e705a
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 7 deletions.
59 changes: 52 additions & 7 deletions lib/dartdoc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@ import 'package:analyzer/src/generated/sdk.dart';
import 'package:analyzer/src/generated/sdk_io.dart';
import 'package:analyzer/src/generated/source_io.dart';


import 'src/css.dart';
import 'src/helpers.dart';
import 'src/html_gen.dart';
import 'src/io_utils.dart';
import 'src/model_utils.dart';
import 'src/package_utils.dart';
import 'src/utils.dart';

const String DEFAULT_OUTPUT_DIRECTORY = 'docs';
Expand Down Expand Up @@ -52,16 +54,15 @@ class DartDoc {
}
// generate the docs
html = new HtmlGenerator();
generatePackage();
libraries.forEach((lib) => generateLibrary(lib));
// copy the css resource into 'out'
File f = joinFile(new Directory(out.path), [css.getCssName()]);
f.writeAsStringSync(css.getCssContent());

double seconds = stopwatch.elapsedMilliseconds / 1000.0;
print('');
print("Documented ${libraries.length} "
"librar${libraries.length == 1 ? 'y' : 'ies'} in "
"${seconds.toStringAsFixed(1)} seconds.");
print("Documented ${libraries.length} " "librar${libraries.length == 1 ? 'y' : 'ies'} in " "${seconds.toStringAsFixed(1)} seconds.");
}

List<LibraryElement> parseLibraries(List<String> files) {
Expand Down Expand Up @@ -104,13 +105,57 @@ class DartDoc {
return new File(Platform.executable).parent.parent;
}

void generatePackage() {
var packageName = getPackageName(_rootDir.path);
var packageDesc = getPackageDescription(_rootDir.path);
if (packageName.isNotEmpty) {
File f = joinFile(new Directory(out.path), ['${packageName}_package.html']);
print('generating ${f.path}');
html = new HtmlGenerator();
html.start(title: 'Package ${packageName}', cssRef: css.getCssName());
generateHeader();

html.startTag('div', attributes: "class='container'", newLine: false);
html.writeln();
html.startTag('div', attributes: "class='row'", newLine: false);
html.writeln();
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.endTag(); //li
html.endTag(); //ul
html.endTag();
html.startTag('div', attributes: "class='span9'");
html.tag('h1', contents: packageName);
html.writeln('<hr>');
html.write(packageDesc);
html.startTag('dl');
html.startTag('h4');
html.tag('dt', contents: 'Libraries');
html.endTag();
html.startTag('dd');
for (LibraryElement lib in libraries) {
html.writeln('<a href="${getFileNameFor(lib)}"> ${lib.name}</a><br>');
}
html.endTag();
html.endTag(); // div.container
generateFooter();
html.end();
f.writeAsStringSync(html.toString());
}

}



void generateLibrary(LibraryElement library) {
File f = joinFile(new Directory(out.path), [getFileNameFor(library)]);
print('generating ${f.path}');
html = new HtmlGenerator();
html.start(title: 'Library ${library.name}', cssRef: css.getCssName());

generateHeader(library);
generateHeader();

html.startTag('div', attributes: "class='container'", newLine: false);
html.writeln();
Expand Down Expand Up @@ -195,21 +240,21 @@ class DartDoc {

html.endTag(); // div.container

generateFooter(library);
generateFooter();

html.end();

// write the file contents
f.writeAsStringSync(html.toString());
}

void generateHeader(LibraryElement library) {
void generateHeader() {
// header
html.startTag('header');
html.endTag();
}

void generateFooter(LibraryElement library) {
void generateFooter() {
// footer
html.startTag('footer');
// html.startTag('div', 'class="navbar navbar-fixed-bottom"');
Expand Down
26 changes: 26 additions & 0 deletions lib/src/package_utils.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
// 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'];
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ dependencies:
bootstrap: any
logging: any
path: any
yaml: any
executables:
dartdoc: null

0 comments on commit 90e705a

Please sign in to comment.