Skip to content
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
67 changes: 29 additions & 38 deletions lib/src/generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ class HtmlGenerator {
// The sitemap template file
static final String siteMapTemplate = '/templates/sitemap.xml';

static final String indexTemplate = '/templates/index.html';

static final String bootstrapOverrides = '''
body {
margin: 8px;
Expand Down Expand Up @@ -48,49 +50,27 @@ body {
}

void generatePackage() {
var packageName = package.name;
var packageDesc = package.description;
var packageVersion = package.version;
var data = {
'packageName': package.name,
'packageDesc': package.description,
'packageVersion': package.version,
'libraries': package.libraries.map((lib) {
return {'name': lib.name,
'filename': _getFileNameFor(lib),
'descr': getDocOneLiner(lib)};
})
};
var fileName = 'index.html';

File f = joinFile(new Directory(out.path), [fileName]);
htmlFiles.add(fileName);
print('generating ${f.path}');
html.start(
title: 'Package ${packageName}',
cssRef: css.cssHeader,
theme: css.theme,
inlineStyle: bootstrapOverrides);
html.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='col-md-3'");
html.startTag('ul', attributes: 'class="nav nav-pills nav-stacked"');
html.startTag('li', attributes: 'class="active"', newLine: false);
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();
html.startTag('div', attributes: "class='col-md-9'");
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 (Library lib in package.libraries) {
html.writeln('<a href="${_getFileNameFor(lib)}"> ${lib.name}</a><br>');
}
html.endTag();
html.endTag(); // div.container
html.generateFooter();
html.end();
f.writeAsStringSync(html.toString());

var script = new File(Platform.script.toFilePath());
File tmplFile = new File('${script.parent.parent.path}$indexTemplate');
var tmpl = tmplFile.readAsStringSync();
var content = render(tmpl, data);
f.writeAsStringSync(content);
}

void generateLibrary(Library library) {
Expand Down Expand Up @@ -365,6 +345,17 @@ body {
}
}

String getDocOneLiner(ModelElement e) {
var doc = stripComments(e.getDocumentation());
if (doc == null || doc == '') return null;
var endOfFirstSentence = doc.indexOf('.');
if (endOfFirstSentence >= 0) {
return doc.substring(0, endOfFirstSentence+1);
} else {
return doc;
}
}

String cleanupDocs(ModelElement e, String docs) {
if (docs == null) {
return '';
Expand Down
2 changes: 2 additions & 0 deletions lib/src/html_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ String ltrim(String str) {
}

String stripComments(String str) {
if (str == null) return null;

StringBuffer buf = new StringBuffer();

if (str.startsWith('///')) {
Expand Down
51 changes: 51 additions & 0 deletions templates/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<!DOCTYPE html>

<!-- generated by dartdoc -->

<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Package {{packageName}}</title>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css" rel="stylesheet" media="screen">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dbc: it would be nice to have the base for the boostrap cdn be a template var. I.e.,

https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agreed! I'll try to remember when we do the next template :)

<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap-theme.min.css" rel="stylesheet">
<style>
body {
margin: 8px;
}
</style>
</head>

<body>
<header>
</header>
<div class='container'>
<div class='row'>
<div class='col-md-3'>
<ul class="nav nav-pills nav-stacked">
<li class="active"><a href="index.html"><i class="chevron-nav icon-white icon-chevron-right"></i> {{ packageName }}-{{ packageVersion}}</a></li>
</ul>
</div>
<div class='col-md-9'>
<h1>{{ packageName }}</h1>
<hr>
<p>{{ packageDesc }}</p>
<h4>
Libraries
</h4>
<table>
<tbody>
{{ #libraries }}
<tr>
<td><a href="{{ filename }}">{{ name }}</a></td>
<td>{{ descr }}</td>
</tr>
{{ /libraries }}
</tbody>
</table>
</div>
</div>
</div>
<footer></footer>
</body>
</html>