diff --git a/bin/dartdoc.dart b/bin/dartdoc.dart index ad63124968..126603ea2c 100644 --- a/bin/dartdoc.dart +++ b/bin/dartdoc.dart @@ -20,8 +20,9 @@ void main(List arguments) { List excludeLibraries = results['exclude'] == null ? [] : results['exclude'].split(','); + String url = results['url']; var currentDir = Directory.current; - new DartDoc(currentDir, excludeLibraries).generateDocs(); + new DartDoc(currentDir, excludeLibraries, url).generateDocs(); } /// Print help if we are passed the help option or invalid arguments. @@ -37,6 +38,10 @@ void _printUsageAndExit(ArgParser parser) { parser.addOption( 'exclude', help: 'a comma-separated list of library names to ignore'); + parser.addOption( + 'url', + help: 'the url where the docs will be hosted.' + 'Used to generate the sitemap.'); parser.addFlag('help', abbr: 'h', negatable: false, diff --git a/lib/dartdoc.dart b/lib/dartdoc.dart index 1b684d7fe1..b1a56a5717 100644 --- a/lib/dartdoc.dart +++ b/lib/dartdoc.dart @@ -27,11 +27,12 @@ class DartDoc { List _excludes; Directory _rootDir; + String _url; Directory out; Set libraries = new Set(); HtmlGenerator generator; - DartDoc(this._rootDir, this._excludes); + DartDoc(this._rootDir, this._excludes, this._url); /// Generate the documentation void generateDocs() { @@ -55,7 +56,7 @@ class DartDoc { out.createSync(recursive: true); } - generator = new HtmlGenerator(new Package(libraries, _rootDir.path), out); + generator = new HtmlGenerator(new Package(libraries, _rootDir.path), out, _url); // generate the docs generator.generate(); diff --git a/lib/src/generator.dart b/lib/src/generator.dart index 01b715b792..33e19aa872 100644 --- a/lib/src/generator.dart +++ b/lib/src/generator.dart @@ -26,8 +26,9 @@ class HtmlGenerator { CSS css = new CSS(); HtmlGeneratorHelper helper; List htmlFiles =[]; + String url; - HtmlGenerator(this.package, this.out) { + HtmlGenerator(this.package, this.out, this.url) { helper = new HtmlGeneratorHelper(package); } @@ -37,7 +38,9 @@ class HtmlGenerator { // copy the css resource into 'out' File f = joinFile(new Directory(out.path), [css.getCssName()]); f.writeAsStringSync(css.getCssContent()); - generateSiteMap(); + if (url != null) { + generateSiteMap(); + } } void generatePackage() { @@ -437,7 +440,7 @@ class HtmlGenerator { var tmpl = tmplFile.readAsStringSync(); // TODO: adjust urls List names = htmlFiles.map((f) => {'name': '$f'}).toList(); - var content = render(tmpl, {'links' : names}); + var content = render(tmpl, {'url': url, 'links' : names}); f.writeAsStringSync(content); } } diff --git a/templates/sitemap.xml b/templates/sitemap.xml index 3a35c2c402..cc334447cd 100644 --- a/templates/sitemap.xml +++ b/templates/sitemap.xml @@ -2,7 +2,7 @@ {{#links}} - {{name}} + {{url}}/{{name}} {{/links}} diff --git a/test/template_test.dart b/test/template_test.dart index f62913154d..f7a1daf603 100644 --- a/test/template_test.dart +++ b/test/template_test.dart @@ -24,7 +24,7 @@ tests() { - somefile.html + /somefile.html '''); @@ -36,14 +36,27 @@ tests() { - somefile.html + /somefile.html - asecondfile.html + /asecondfile.html '''); }); + test('url and file name', () { + expect(sitemap({'url': 'http://mydoc.com','links' : [{'name': 'somefile.html'}]}), + ''' + + + + http://mydoc.com/somefile.html + + +'''); + }); + + }); }