Skip to content

Commit 90e705a

Browse files
committed
Merge pull request #25 from keertip/package
add a top level html file for package
2 parents 14c4007 + 873264c commit 90e705a

File tree

3 files changed

+79
-7
lines changed

3 files changed

+79
-7
lines changed

lib/dartdoc.dart

+52-7
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,13 @@ import 'package:analyzer/src/generated/sdk.dart';
1414
import 'package:analyzer/src/generated/sdk_io.dart';
1515
import 'package:analyzer/src/generated/source_io.dart';
1616

17+
1718
import 'src/css.dart';
1819
import 'src/helpers.dart';
1920
import 'src/html_gen.dart';
2021
import 'src/io_utils.dart';
2122
import 'src/model_utils.dart';
23+
import 'src/package_utils.dart';
2224
import 'src/utils.dart';
2325

2426
const String DEFAULT_OUTPUT_DIRECTORY = 'docs';
@@ -52,16 +54,15 @@ class DartDoc {
5254
}
5355
// generate the docs
5456
html = new HtmlGenerator();
57+
generatePackage();
5558
libraries.forEach((lib) => generateLibrary(lib));
5659
// copy the css resource into 'out'
5760
File f = joinFile(new Directory(out.path), [css.getCssName()]);
5861
f.writeAsStringSync(css.getCssContent());
5962

6063
double seconds = stopwatch.elapsedMilliseconds / 1000.0;
6164
print('');
62-
print("Documented ${libraries.length} "
63-
"librar${libraries.length == 1 ? 'y' : 'ies'} in "
64-
"${seconds.toStringAsFixed(1)} seconds.");
65+
print("Documented ${libraries.length} " "librar${libraries.length == 1 ? 'y' : 'ies'} in " "${seconds.toStringAsFixed(1)} seconds.");
6566
}
6667

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

108+
void generatePackage() {
109+
var packageName = getPackageName(_rootDir.path);
110+
var packageDesc = getPackageDescription(_rootDir.path);
111+
if (packageName.isNotEmpty) {
112+
File f = joinFile(new Directory(out.path), ['${packageName}_package.html']);
113+
print('generating ${f.path}');
114+
html = new HtmlGenerator();
115+
html.start(title: 'Package ${packageName}', cssRef: css.getCssName());
116+
generateHeader();
117+
118+
html.startTag('div', attributes: "class='container'", newLine: false);
119+
html.writeln();
120+
html.startTag('div', attributes: "class='row'", newLine: false);
121+
html.writeln();
122+
html.startTag('div', attributes: "class='span3'");
123+
html.startTag('ul', attributes: 'class="nav nav-tabs nav-stacked left-nav"');
124+
html.startTag('li', attributes: 'class="active"', newLine: false);
125+
html.write('<a href="${packageName}">' '<i class="chevron-nav icon-white icon-chevron-right"></i> ' '${packageName}</a>');
126+
html.endTag(); //li
127+
html.endTag(); //ul
128+
html.endTag();
129+
html.startTag('div', attributes: "class='span9'");
130+
html.tag('h1', contents: packageName);
131+
html.writeln('<hr>');
132+
html.write(packageDesc);
133+
html.startTag('dl');
134+
html.startTag('h4');
135+
html.tag('dt', contents: 'Libraries');
136+
html.endTag();
137+
html.startTag('dd');
138+
for (LibraryElement lib in libraries) {
139+
html.writeln('<a href="${getFileNameFor(lib)}"> ${lib.name}</a><br>');
140+
}
141+
html.endTag();
142+
html.endTag(); // div.container
143+
generateFooter();
144+
html.end();
145+
f.writeAsStringSync(html.toString());
146+
}
147+
148+
}
149+
150+
151+
107152
void generateLibrary(LibraryElement library) {
108153
File f = joinFile(new Directory(out.path), [getFileNameFor(library)]);
109154
print('generating ${f.path}');
110155
html = new HtmlGenerator();
111156
html.start(title: 'Library ${library.name}', cssRef: css.getCssName());
112157

113-
generateHeader(library);
158+
generateHeader();
114159

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

196241
html.endTag(); // div.container
197242

198-
generateFooter(library);
243+
generateFooter();
199244

200245
html.end();
201246

202247
// write the file contents
203248
f.writeAsStringSync(html.toString());
204249
}
205250

206-
void generateHeader(LibraryElement library) {
251+
void generateHeader() {
207252
// header
208253
html.startTag('header');
209254
html.endTag();
210255
}
211256

212-
void generateFooter(LibraryElement library) {
257+
void generateFooter() {
213258
// footer
214259
html.startTag('footer');
215260
// html.startTag('div', 'class="navbar navbar-fixed-bottom"');

lib/src/package_utils.dart

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
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.
4+
5+
6+
library dartdoc.package_utils;
7+
8+
import 'dart:io';
9+
10+
import 'package:path/path.dart' as path;
11+
import 'package:yaml/yaml.dart';
12+
13+
14+
String getPackageName(String directoryName) =>
15+
_getPubspec(directoryName)['name'];
16+
17+
Map _getPubspec(String directoryName) {
18+
var pubspecName = path.join(directoryName, 'pubspec.yaml');
19+
File pubspec = new File(pubspecName);
20+
if (!pubspec.existsSync()) return {'name': ''};
21+
var contents = pubspec.readAsStringSync();
22+
return loadYaml(contents);
23+
}
24+
25+
String getPackageDescription(String directoryName) =>
26+
_getPubspec(directoryName)['description'];

pubspec.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@ dependencies:
99
bootstrap: any
1010
logging: any
1111
path: any
12+
yaml: any
1213
executables:
1314
dartdoc: null

0 commit comments

Comments
 (0)