diff --git a/lib/src/generator.dart b/lib/src/generator.dart index 0fa39ea027..2ae3fca435 100644 --- a/lib/src/generator.dart +++ b/lib/src/generator.dart @@ -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; @@ -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( - '' ' ' '${packageName}-${packageVersion}'); - html.endTag(); //li - html.endTag(); //ul - html.endTag(); - html.startTag('div', attributes: "class='col-md-9'"); - html.tag('h1', contents: packageName); - html.writeln('
'); - 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(' ${lib.name}
'); - } - 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) { @@ -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 ''; diff --git a/lib/src/html_utils.dart b/lib/src/html_utils.dart index 65c32be629..b873c55fe2 100644 --- a/lib/src/html_utils.dart +++ b/lib/src/html_utils.dart @@ -81,6 +81,8 @@ String ltrim(String str) { } String stripComments(String str) { + if (str == null) return null; + StringBuffer buf = new StringBuffer(); if (str.startsWith('///')) { diff --git a/templates/index.html b/templates/index.html new file mode 100644 index 0000000000..e5f71cec6f --- /dev/null +++ b/templates/index.html @@ -0,0 +1,51 @@ + + + + + + + + + Package {{packageName}} + + + + + + +
+
+
+
+ +
+

{{ packageName }}

+
+

{{ packageDesc }}

+

+ Libraries +

+ + + {{ #libraries }} + + + + + {{ /libraries }} + +
{{ name }}{{ descr }}
+
+
+
+ + + \ No newline at end of file