Skip to content

add ellipsis when there's more than one liner #849

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

Closed
wants to merge 3 commits into from
Closed
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
3 changes: 3 additions & 0 deletions lib/markdown_processor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ String _linkDocReference(String reference, ModelElement element,
}
}

// TODO: this is in the wrong place
class Documentation {
final ModelElement element;
String _asHtml;
Expand All @@ -65,6 +66,8 @@ class Documentation {

String get asOneLiner => _asOneLiner;

bool get hasMoreThanOneLineDocs => _asHtmlDocument.body.children.length > 1;

void _processDocsAsMarkdown() {
String tempHtml = renderMarkdownToHtml(raw, element);
_asHtmlDocument = parse(tempHtml);
Expand Down
5 changes: 4 additions & 1 deletion lib/src/html_generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ class Templates {
topLevelPropertyTemplate = await _loadTemplate('top_level_property.html');
typeDefTemplate = await _loadTemplate('typedef.html');

// TODO: if we can ever enumerate the contents of a package, we
// won't need this.
List<String> partials = [
'callable',
'callable_multiline',
Expand All @@ -94,7 +96,8 @@ class Templates {
'sidebar_for_class',
'source_code',
'sidebar_for_library',
'name_link'
'name_link',
'has_more_docs'
];

for (String partial in partials) {
Expand Down
50 changes: 36 additions & 14 deletions lib/src/model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,23 @@ abstract class Nameable {
String get name;
}

abstract class ModelElement implements Comparable, Nameable {
/// Bridges the gap between model elements and packages,
/// both of which have documentation.
abstract class Documentable {
String get oneLineDoc;
String get documentation;
String get documentationAsHtml;
bool get hasMoreThanOneLineDocs;
bool get hasDocumentation;
}

abstract class ModelElement implements Comparable, Nameable, Documentable {
final Element element;
final Library library;

ElementType _modelType;
String _rawDocs;
Documentation _documentation;
Documentation __documentation;
Copy link
Member

Choose a reason for hiding this comment

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

the rare double underscore

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I'm not proud of that one. :(

List _parameters;

// WARNING: putting anything into the body of this seems
Expand Down Expand Up @@ -150,20 +160,24 @@ abstract class ModelElement implements Comparable, Nameable {
return _rawDocs;
}

Documentation get _documentation {
if (__documentation != null) return __documentation;
__documentation = new Documentation(this);
return __documentation;
}

@override
bool get hasDocumentation =>
documentation != null && documentation.isNotEmpty;

String get documentationAsHtml {
if (_documentation != null) return _documentation.asHtml;
_documentation = new Documentation(this);
return _documentation.asHtml;
}
@override
String get documentationAsHtml => _documentation.asHtml;

String get oneLineDoc {
if (_documentation != null) return _documentation.asOneLiner;
_documentation = new Documentation(this);
return _documentation.asOneLiner;
}
@override
String get oneLineDoc => _documentation.asOneLiner;

@override
bool get hasMoreThanOneLineDocs => _documentation.hasMoreThanOneLineDocs;

String get htmlId => name;

Expand Down Expand Up @@ -392,7 +406,7 @@ class Dynamic extends ModelElement {
String get kind => 'dynamic';
}

class Package implements Nameable {
class Package implements Nameable, Documentable {
final List<Library> _libraries = [];
final PackageMeta packageMeta;
String _docsAsHtml;
Expand Down Expand Up @@ -425,6 +439,9 @@ class Package implements Nameable {
return _docsAsHtml;
}

// TODO: make this work
bool get hasMoreThanOneLineDocs => true;

List<Library> get libraries => _libraries;

Package(Iterable<LibraryElement> libraryElements, this.packageMeta) {
Expand Down Expand Up @@ -1307,7 +1324,7 @@ class Typedef extends ModelElement implements EnclosedElement {
String get _href => '${library.dirName}/$fileName';
}

// TODO: rename this to property
// TODO: rename this to Property
class Field extends ModelElement
with GetterSetterCombo
implements EnclosedElement {
Expand Down Expand Up @@ -1618,8 +1635,13 @@ abstract class GetterSetterCombo {
if (buffer.isNotEmpty) return buffer.toString();

// TODO: check that we'd ever get here. Doesn't seem like we would.
// This is old.
return computeDocumentationComment();
}

String get getterDocsAsHtml => '';

String get setterDocsAsHtml => '';
}

/// Top-level variables. But also picks up getters and setters?
Expand Down
2 changes: 1 addition & 1 deletion lib/templates/_callable.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
{{#isInherited}}
<div class="features">inherited</div>
{{/isInherited}}
<p>{{{ oneLineDoc }}}</p>
<p>{{{ oneLineDoc }}}{{^isInherited}}{{>has_more_docs}}{{/isInherited}}</p>
</dd>
2 changes: 1 addition & 1 deletion lib/templates/_constant.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
</dt>
<dd>
<div class="features">const</div>
<p>{{{ oneLineDoc }}}</p>
<p>{{{ oneLineDoc }}}{{>has_more_docs}}</p>
</dd>
3 changes: 3 additions & 0 deletions lib/templates/_has_more_docs.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{{#hasMoreThanOneLineDocs}}
<a href="{{href}}">&hellip;</a>
Copy link
Member

Choose a reason for hiding this comment

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

Interesting - did the … char not make it through the various file encodings?

You could also remove the a href. If just the line is long and gets truncated by the browser, it'll show an ellipses from the text-overflow css style. So, a plain ellipses char from a 2nd paragraph would match that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

… char not make it through the various file encodings?

What is the ... char?

You could also remove the a href.

And still show the hellip ?

{{/hasMoreThanOneLineDocs}}
2 changes: 1 addition & 1 deletion lib/templates/_property.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
</dt>
<dd>
{{>readable_writable}}
<p>{{{ oneLineDoc }}}</p>
<p>{{{ oneLineDoc }}}{{^isInherited}}{{>has_more_docs}}{{/isInherited}}</p>
</dd>
2 changes: 1 addition & 1 deletion lib/templates/class.html
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ <h2>Constructors</h2>
const
</div>
{{/isConst}}
<p>{{{ oneLineDoc }}}</p>
<p>{{{ oneLineDoc }}}{{>has_more_docs}}</p>
</dd>
{{/clazz.constructors}}
</dl>
Expand Down
5 changes: 4 additions & 1 deletion lib/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ <h2>Libraries</h2>
</dt>
<dd>
{{#isNotDocumented}}<span class="undocumented">Library not documented.</span>{{/isNotDocumented}}
<p>{{{ oneLineDoc }}}</p>
<p>
{{{ oneLineDoc }}}
{{>has_more_docs}}
</p>
</dd>
{{/package.libraries}}
</dl>
Expand Down
6 changes: 3 additions & 3 deletions lib/templates/library.html
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ <h2>Enums</h2>
{{{linkedName}}}
</dt>
<dd>
<p>{{{ oneLineDoc }}}</p>
<p>{{{ oneLineDoc }}}{{>has_more_docs}}</p>
</dd>
{{/library.enums}}
</dl>
Expand All @@ -94,7 +94,7 @@ <h2>Classes</h2>
<span class="name {{#isDeprecated}}deprecated{{/isDeprecated}}">{{{linkedName}}}</span>
</dt>
<dd>
<p>{{{ oneLineDoc }}}</p>
<p>{{{ oneLineDoc }}}{{>has_more_docs}}</p>
</dd>
{{/library.classes}}
</dl>
Expand All @@ -111,7 +111,7 @@ <h2>Exceptions / Errors</h2>
<span class="name {{#isDeprecated}}deprecated{{/isDeprecated}}">{{{linkedName}}}</span>
</dt>
<dd>
<p>{{{ oneLineDoc }}}</p>
<p>{{{ oneLineDoc }}}{{>has_more_docs}}</p>
</dd>
{{/library.exceptions}}
</dl>
Expand Down
18 changes: 15 additions & 3 deletions test/model_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -116,21 +116,33 @@ void main() {
expect(dartAsyncLib.name, 'dart:async');
});

test('name', () {
test('has a name', () {
expect(exLibrary.name, 'ex');
});

test('sdk library names', () {
test('sdk library have formatted names', () {
expect(dartAsyncLib.name, 'dart:async');
expect(dartAsyncLib.dirName, 'dart-async');
expect(dartAsyncLib.href, 'dart-async/dart-async-library.html');
});

test('documentation', () {
test('has documentation', () {
expect(exLibrary.documentation,
'a library. testing string escaping: `var s = \'a string\'` <cool>');
});

test('has one line docs', () {
expect(
fakeLibrary.oneLineDoc,
equals(
'WOW FAKE PACKAGE IS <strong>BEST</strong> <a href="http://example.org">PACKAGE</a>'));
});

test('has more than one line docs (or not)', () {
expect(fakeLibrary.hasMoreThanOneLineDocs, true);
expect(exLibrary.hasMoreThanOneLineDocs, false);
});

test('has properties', () {
expect(exLibrary.hasProperties, isTrue);
});
Expand Down