Skip to content

add copyright headers and adjust some whitespace #31

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 1 commit into from
Dec 18, 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
4 changes: 1 addition & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@
build/
packages
.buildlog
.project
.pub
.idea
.settings/

# Or the files created by dart2js.
*.dart.js
*.dart.precompiled.js
*.js_
*.js.deps
*.js.map

Expand Down
27 changes: 27 additions & 0 deletions .project
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>dartdoc</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>com.google.dart.tools.core.dartBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>com.google.dart.tools.core.dartNature</nature>
</natures>
<filteredResources>
<filter>
<id>1418882159156</id>
<name></name>
<type>30</type>
<matcher>
<id>com.google.dart.tools.core.packagesFolderMatcher</id>
</matcher>
</filter>
</filteredResources>
</projectDescription>
10 changes: 4 additions & 6 deletions bin/dartdoc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import 'dart:io';

import 'package:args/args.dart';

import 'package:dartdoc/dartdoc.dart';

/// Analyzes Dart files and generates a representation of included libraries,
Expand All @@ -32,16 +31,15 @@ void _printUsageAndExit(ArgParser parser) {
exit(0);
}

ArgParser _createArgsParser() {
// TODO: more options to be added
ArgParser _createArgsParser() {
// TODO: more options to be added
var parser = new ArgParser();
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.');
'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: 1 addition & 4 deletions lib/dartdoc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,12 @@ class DartDoc {
libs.sort(elementCompare);
libraries.addAll(libs);


// create the out directory
out = new Directory(DEFAULT_OUTPUT_DIRECTORY);
if (!out.existsSync()) {
out.createSync(recursive: true);
}

generator = new HtmlGenerator(new Package(libraries, _rootDir.path), out, _url);
// generate the docs
generator.generate();
Expand Down Expand Up @@ -107,5 +106,3 @@ class DartDoc {
}

}


10 changes: 3 additions & 7 deletions lib/src/generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import 'model.dart';

/// Generates the HTML files
class HtmlGenerator {

// The sitemap template file
final String siteMapTemplate = '/templates/sitemap.xml';

Expand Down Expand Up @@ -436,11 +436,11 @@ class HtmlGenerator {
print('generating sitemap.xml');
File f = joinFile(new Directory(out.path), ['sitemap.xml']);
var script = new File(Platform.script.toFilePath());
File tmplFile = new File('${script.parent.parent.path}$siteMapTemplate');
File tmplFile = new File('${script.parent.parent.path}$siteMapTemplate');
var tmpl = tmplFile.readAsStringSync();
// TODO: adjust urls
List names = htmlFiles.map((f) => {'name': '$f'}).toList();
var content = render(tmpl, {'url': url, 'links' : names});
var content = render(tmpl, {'url': url, 'links' : names});
f.writeAsStringSync(content);
}
}
Expand Down Expand Up @@ -545,7 +545,6 @@ class HtmlGeneratorHelper extends Helper {
return buf.toString();
}


String createLinkedReturnTypeName(ElementType type) {
if (type.returnElement == null) {
if (type.returnTypeName != null) {
Expand All @@ -558,6 +557,3 @@ class HtmlGeneratorHelper extends Helper {
}
}
}



21 changes: 10 additions & 11 deletions lib/src/html_gen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,17 @@ class HtmlHelper {
}

void generateHeader() {
// header
startTag('header');
endTag();
}
// header
startTag('header');
endTag();
}

void generateFooter() {
// footer
startTag('footer');
endTag();
}

void generateFooter() {
// footer
startTag('footer');
endTag();
}


void start({String title, String cssRef}) {
startTag('html', newLine: false);
writeln();
Expand Down
2 changes: 0 additions & 2 deletions lib/src/html_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -155,5 +155,3 @@ String replaceAll(String str, List<String> matchChars, {String htmlEntity, var r
}
return buf.toString();
}


21 changes: 9 additions & 12 deletions lib/src/model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.


/// The models used to represent Dart code
library dartdoc.models;

Expand All @@ -12,7 +11,6 @@ import 'html_utils.dart';
import 'model_utils.dart';
import 'package_utils.dart';


abstract class ModelElement {

Element element;
Expand Down Expand Up @@ -123,9 +121,9 @@ abstract class ModelElement {
ExecutableElement ex = (element as ExecutableElement);
String retType = generator.createLinkedReturnTypeName(new ElementType(ex.type, library));

return '${generator.createLinkedName(this)}'
'(${generator.printParams(ex.parameters.map((f)=>
new Parameter(f, library)))})'
return '${generator.createLinkedName(this)}'
'(${generator.printParams(ex.parameters.map((f)=>
new Parameter(f, library)))})'
'${retType.isEmpty ? '' : ': $retType'}';
}
if (isPropertyInducer) {
Expand Down Expand Up @@ -354,8 +352,8 @@ class Fnction extends ModelElement {
String createLinkedSummary(Helper generator) {
String retType = generator.createLinkedReturnTypeName(new ElementType(_func.type, library));

return '${generator.createLinkedName(this)}'
'(${generator.printParams(_func.parameters.map((f)=> new Parameter(f, library)))})'
return '${generator.createLinkedName(this)}'
'(${generator.printParams(_func.parameters.map((f)=> new Parameter(f, library)))})'
'${retType.isEmpty ? '' : ': $retType'}';
}

Expand Down Expand Up @@ -452,7 +450,7 @@ class Constructor extends ModelElement {
if (_constructor.isFactory) {
buf.write('factory ');
}
buf.write('${_constructor.type.returnType.name}${_constructor.name.isEmpty?'':'.'}'
buf.write('${_constructor.type.returnType.name}${_constructor.name.isEmpty?'':'.'}'
'${_constructor.name}'
'(${generator.printParams(
_constructor.parameters.map((f)=> new Parameter(f, library)))})');
Expand Down Expand Up @@ -496,11 +494,11 @@ class Accessor extends ModelElement {
buf.write(generator.createLinkedName(this));
buf.write(': ');
buf.write(generator.createLinkedReturnTypeName(
new ElementType(_accessor.type,
new ElementType(_accessor.type,
new ModelElement.from(_accessor.type.element, library))));
} else {
buf.write('${generator.createLinkedName(this)}('
'${generator.printParams(_accessor.parameters.map((f)=>
buf.write('${generator.createLinkedName(this)}('
'${generator.printParams(_accessor.parameters.map((f)=>
new Parameter(f,library)))})');
}
return buf.toString();
Expand Down Expand Up @@ -580,4 +578,3 @@ abstract class Helper {
String printParams(List<Parameter> params);
String createHrefFor(ModelElement e);
}

3 changes: 1 addition & 2 deletions lib/src/model_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@

library model_utils;

import 'package:analyzer/src/generated/element.dart';
import 'package:analyzer/src/generated/constant.dart';

import 'package:analyzer/src/generated/element.dart';

Object getConstantValue(PropertyInducingElement element) {
if (element is ConstFieldElementImpl) {
Expand Down
4 changes: 4 additions & 0 deletions test/all.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

library dartdoc.all_tests;

import 'template_test.dart' as template_tests;
Expand Down
35 changes: 18 additions & 17 deletions test/template_test.dart
Original file line number Diff line number Diff line change
@@ -1,25 +1,28 @@
// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

library dartdoc.template_test;

import 'dart:io';

import 'package:mustache4dart/mustache4dart.dart';
import 'package:unittest/unittest.dart';


tests() {
group('template', () {
var script = new File(Platform.script.toFilePath());
File tmplFile = new File('${script.parent.parent.path}/templates/sitemap.xml');

test('sitemap template exists', () {
tmplFile.exists().then((t) => expect(t, true));
});

var siteMapTmpl = tmplFile.readAsStringSync();
var sitemap = compile(siteMapTmpl);

test('render', () {
expect(sitemap({'links' : [{'name': 'somefile.html'}]}),
expect(sitemap({'links' : [{'name': 'somefile.html'}]}),
'''
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
Expand All @@ -28,10 +31,10 @@ tests() {
</url>
</urlset>
''');
});
test('substitute multiple links', () {
expect(sitemap({'links' : [{'name': 'somefile.html'}, {'name': 'asecondfile.html'}]}),
});

test('substitute multiple links', () {
expect(sitemap({'links' : [{'name': 'somefile.html'}, {'name': 'asecondfile.html'}]}),
'''
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
Expand All @@ -43,10 +46,10 @@ tests() {
</url>
</urlset>
''');
});
test('url and file name', () {
expect(sitemap({'url': 'http://mydoc.com','links' : [{'name': 'somefile.html'}]}),
});

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">
Expand All @@ -55,8 +58,6 @@ tests() {
</url>
</urlset>
''');
});


});
});
});
}