Skip to content

pass in url for site #30

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Dec 12, 2014
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
7 changes: 6 additions & 1 deletion bin/dartdoc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ void main(List<String> arguments) {
List<String> 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.
Expand All @@ -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,
Expand Down
5 changes: 3 additions & 2 deletions lib/dartdoc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,12 @@ class DartDoc {

List<String> _excludes;
Directory _rootDir;
String _url;
Directory out;
Set<LibraryElement> libraries = new Set();
HtmlGenerator generator;

DartDoc(this._rootDir, this._excludes);
DartDoc(this._rootDir, this._excludes, this._url);
Copy link
Contributor

Choose a reason for hiding this comment

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

Should _url be optional?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Could make it optional, but then would have to check whether to pass it in or not. Don't know which is the better approach here.

Copy link
Contributor

Choose a reason for hiding this comment

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

We could say that URL is a property of the backend. From an API perspective, URL really only belongs in HtmlGenerator.

How is this DartDoc class intended to be used? I don't think DartDoc class should have a reference to HtmlGenerator. Instead:

  • Create one or more generators, and configure them
  • Give the list of generators to DartDoc

Thoughts?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, the url is for the HtmlGenerator. Like the idea of separation and configuring the generator based on user args. Will refactor next time around.


/// Generate the documentation
void generateDocs() {
Expand All @@ -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();

Expand Down
9 changes: 6 additions & 3 deletions lib/src/generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ class HtmlGenerator {
CSS css = new CSS();
HtmlGeneratorHelper helper;
List<String> htmlFiles =[];
String url;

HtmlGenerator(this.package, this.out) {
HtmlGenerator(this.package, this.out, this.url) {
helper = new HtmlGeneratorHelper(package);
}

Expand All @@ -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() {
Expand Down Expand Up @@ -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);
}
}
Expand Down
2 changes: 1 addition & 1 deletion templates/sitemap.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
{{#links}}
<url>
<loc>{{name}}</loc>
<loc>{{url}}/{{name}}</loc>
</url>
{{/links}}
</urlset>
19 changes: 16 additions & 3 deletions test/template_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ tests() {
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<url>
<loc>somefile.html</loc>
<loc>/somefile.html</loc>
Copy link
Contributor

Choose a reason for hiding this comment

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

are there tests for when URL is passed in?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yes, added one

</url>
</urlset>
''');
Expand All @@ -36,14 +36,27 @@ tests() {
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<url>
<loc>somefile.html</loc>
<loc>/somefile.html</loc>
</url>
<url>
<loc>asecondfile.html</loc>
<loc>/asecondfile.html</loc>
</url>
</urlset>
''');
});

test('url and file name', () {
expect(sitemap({'url': 'http://mydoc.com','links' : [{'name': 'somefile.html'}]}),
'''
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<url>
<loc>http://mydoc.com/somefile.html</loc>
</url>
</urlset>
''');
});


});
}