Skip to content

Move extendedDocLink creation to ModelElementRenderer #2085

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 3, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion lib/src/model/getter_setter_combo.dart
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ mixin GetterSetterCombo on ModelElement {
String get oneLineDoc {
if (_oneLineDoc == null) {
if (!hasAccessorsWithDocs) {
_oneLineDoc = computeOneLineDoc();
_oneLineDoc = super.oneLineDoc;
} else {
StringBuffer buffer = StringBuffer();
if (hasPublicGetter && getter.oneLineDoc.isNotEmpty) {
Expand Down
15 changes: 2 additions & 13 deletions lib/src/model/model_element.dart
Original file line number Diff line number Diff line change
Expand Up @@ -797,7 +797,7 @@ abstract class ModelElement extends Canonicalization
/// does not exist.
String get extendedDocLink {
if (hasExtendedDocumentation) {
return '<a href="${href}">[...]</a>';
return ModelElementRendererHtml().renderExtendedDocLink(this);
}
return '';
}
Expand Down Expand Up @@ -977,19 +977,8 @@ abstract class ModelElement extends Canonicalization
@override
String get name => element.name;

// TODO(jcollins-g): refactor once dartdoc will only run in a VM where mixins
// calling super is allowed (SDK constraint >= 2.1.0).
String computeOneLineDoc() =>
'${_documentation.asOneLiner}${extendedDocLink.isEmpty ? "" : " $extendedDocLink"}';
String _oneLineDoc;

@override
String get oneLineDoc {
if (_oneLineDoc == null) {
_oneLineDoc = computeOneLineDoc();
}
return _oneLineDoc;
}
String get oneLineDoc => _documentation.asOneLiner;
Copy link
Contributor

Choose a reason for hiding this comment

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

glad the no-super workaround is gone


Member get originalMember => _originalMember;

Expand Down
7 changes: 7 additions & 0 deletions lib/src/render/model_element_renderer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import 'package:dartdoc/src/model/model_element.dart';
abstract class ModelElementRenderer {
String renderLinkedName(ModelElement modelElement);

String renderExtendedDocLink(ModelElement modelElement);

String renderYoutubeUrl(String youTubeId, String aspectRatio);

String renderAnimation(
Expand All @@ -20,6 +22,11 @@ class ModelElementRendererHtml extends ModelElementRenderer {
return '<a${cssClass} href="${modelElement.href}">${modelElement.name}</a>';
}

@override
String renderExtendedDocLink(ModelElement modelElement) {
return '<a href="${modelElement.href}">[...]</a>';
}

@override
String renderYoutubeUrl(String youTubeId, String aspectRatio) {
// Blank lines before and after, and no indenting at the beginning and end
Expand Down
2 changes: 1 addition & 1 deletion lib/templates/_callable.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
{{>categorization}}
</dt>
<dd{{ #isInherited }} class="inherited"{{ /isInherited}}>
{{{ oneLineDoc }}}
{{{ oneLineDoc }}} {{{ extendedDocLink }}}
{{>features}}
</dd>
2 changes: 1 addition & 1 deletion lib/templates/_class.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
<span class="name {{#isDeprecated}}deprecated{{/isDeprecated}}">{{{linkedName}}}{{{linkedGenericParameters}}}</span> {{>categorization}}
</dt>
<dd>
{{{ oneLineDoc }}}
{{{ oneLineDoc }}} {{{ extendedDocLink }}}
</dd>
2 changes: 1 addition & 1 deletion lib/templates/_constant.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
{{>categorization}}
</dt>
<dd>
{{{ oneLineDoc }}}
{{{ oneLineDoc }}} {{{ extendedDocLink }}}
{{>features}}
<div>
<span class="signature"><code>{{{ constantValueTruncated }}}</code></span>
Expand Down
2 changes: 1 addition & 1 deletion lib/templates/_extension.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
<span class="name {{#isDeprecated}}deprecated{{/isDeprecated}}">{{{linkedName}}}</span> {{>categorization}}
</dt>
<dd>
{{{ oneLineDoc }}}
{{{ oneLineDoc }}} {{{ extendedDocLink }}}
</dd>

4 changes: 2 additions & 2 deletions lib/templates/_library.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
<span class="name">{{{ linkedName }}}</span> {{>categorization}}
</dt>
<dd>
{{#isDocumented}}{{{ oneLineDoc }}}{{/isDocumented}}
</dd>
{{#isDocumented}}{{{ oneLineDoc }}} {{{ extendedDocLink }}}{{/isDocumented}}
</dd>
2 changes: 1 addition & 1 deletion lib/templates/_mixin.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
<span class="name {{#isDeprecated}}deprecated{{/isDeprecated}}">{{{linkedName}}}{{{linkedGenericParameters}}}</span> {{>categorization}}
</dt>
<dd>
{{{ oneLineDoc }}}
{{{ oneLineDoc }}} {{{ extendedDocLink }}}
</dd>
2 changes: 1 addition & 1 deletion lib/templates/_property.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
<span class="signature">{{{ arrow }}} {{{ linkedReturnType }}}</span> {{>categorization}}
</dt>
<dd{{ #isInherited }} class="inherited"{{ /isInherited}}>
{{{ oneLineDoc }}}
{{{ oneLineDoc }}} {{{ extendedDocLink }}}
{{>features}}
</dd>
2 changes: 1 addition & 1 deletion lib/templates/class.html
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ <h2>Constructors</h2>
<span class="name">{{{linkedName}}}</span><span class="signature">({{{ linkedParams }}})</span>
</dt>
<dd>
{{{ oneLineDoc }}}
{{{ oneLineDoc }}} {{{ extendedDocLink }}}
{{#isConst}}
<div class="constructor-modifier features">const</div>
{{/isConst}}
Expand Down
2 changes: 1 addition & 1 deletion lib/templates/enum.html
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ <h2>Constructors</h2>
<span class="name">{{{linkedName}}}</span><span class="signature">({{{ linkedParams }}})</span>
</dt>
<dd>
{{{ oneLineDoc }}}
{{{ oneLineDoc }}} {{{ extendedDocLink }}}
{{#isConst}}
<div class="constructor-modifier features">const</div>
{{/isConst}}
Expand Down
2 changes: 1 addition & 1 deletion lib/templates/mixin.html
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ <h2>Constructors</h2>
<span class="name">{{{linkedName}}}</span><span class="signature">({{{ linkedParams }}})</span>
</dt>
<dd>
{{{ oneLineDoc }}}
{{{ oneLineDoc }}} {{{ extendedDocLink }}}
{{#isConst}}
<div class="constructor-modifier features">const</div>
{{/isConst}}
Expand Down
20 changes: 11 additions & 9 deletions test/model_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ import 'dart:io';
import 'package:dartdoc/dartdoc.dart';
import 'package:dartdoc/src/model/model.dart';
import 'package:dartdoc/src/render/category_renderer.dart';
import 'package:dartdoc/src/render/parameter_renderer.dart';
import 'package:dartdoc/src/render/enum_field_renderer.dart';
import 'package:dartdoc/src/render/model_element_renderer.dart';
import 'package:dartdoc/src/render/parameter_renderer.dart';
import 'package:dartdoc/src/render/typedef_renderer.dart';
import 'package:dartdoc/src/warnings.dart';
import 'package:test/test.dart';
Expand Down Expand Up @@ -584,7 +585,7 @@ void main() {
expect(
fakeLibrary.oneLineDoc,
equals(
'WOW FAKE PACKAGE IS <strong>BEST</strong> <a href="http://example.org">PACKAGE</a> <a href="fake/fake-library.html">[...]</a>'));
'WOW FAKE PACKAGE IS <strong>BEST</strong> <a href="http://example.org">PACKAGE</a>'));
});

test('has properties', () {
Expand Down Expand Up @@ -1196,7 +1197,7 @@ void main() {
expect(
add.oneLineDoc,
equals(
'Adds <code>value</code> to the end of this list,\nextending the length by one. <a href="fake/SpecialList/add.html">[...]</a>'));
'Adds <code>value</code> to the end of this list,\nextending the length by one.'));
});

test(
Expand Down Expand Up @@ -1322,8 +1323,10 @@ void main() {
});

test('bullet points work in top level variables', () {
expect(bulletDoced.oneLineDoc,
contains('<a href="fake/bulletDoced-constant.html">[...]</a>'));
expect(
bulletDoced.extendedDocLink,
equals(
ModelElementRendererHtml().renderExtendedDocLink(bulletDoced)));
expect(bulletDoced.documentationAsHtml, contains('<li>'));
});
});
Expand Down Expand Up @@ -2757,10 +2760,9 @@ String topLevelFunction(int param1, bool param2, Cool coolBeans,

test('has extended documentation', () {
expect(lengthX.hasExtendedDocumentation, isTrue);
expect(
lengthX.oneLineDoc,
equals(
'Returns a length. <a href="fake/WithGetterAndSetter/lengthX.html">[...]</a>'));
expect(lengthX.oneLineDoc, equals('Returns a length.'));
expect(lengthX.extendedDocLink,
equals(ModelElementRendererHtml().renderExtendedDocLink(lengthX)));
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should have at least one literal matching string here for the Html renderer test, especially since it is very targeted -- otherwise we're simply validating that extendedDocLink returns whatever the renderer does.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

expect(lengthX.documentation, contains('the fourth dimension'));
expect(lengthX.documentation, isNot(contains('[...]')));
});
Expand Down
4 changes: 2 additions & 2 deletions testing/test_package_custom_templates/templates/class.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ <h2>Constructors</h2>
{{{linkedName}}}({{{ linkedParams }}})
</dt>
<dd>
{{{ oneLineDoc }}}
{{{ oneLineDoc }}} {{{ extendedDocLink }}}
</dd>
{{/publicConstructors}}
</dl>
Expand All @@ -30,7 +30,7 @@ <h2>Constructors</h2>
<h2>Methods</h2>
<dl>
{{#allPublicInstanceMethods}}
{{{ oneLineDoc }}}
{{{ oneLineDoc }}} {{{ extendedDocLink }}}
{{/allPublicInstanceMethods}}
</dl>
</section>
Expand Down
4 changes: 2 additions & 2 deletions testing/test_package_custom_templates/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ <h2>{{name}}</h2>
{{/isFirstPackage}}
<dl>
{{#defaultCategory.publicLibraries}}
{{{ oneLineDoc }}}
{{{ oneLineDoc }}} {{{ extendedDocLink }}}
{{/defaultCategory.publicLibraries}}
{{#categoriesWithPublicLibraries}}
<h3>{{name}}</h3>
Expand All @@ -29,7 +29,7 @@ <h3>{{name}}</h3>
{{{ linkedName }}}
</dt>
<dd>
{{#isDocumented}}{{{ oneLineDoc }}}{{/isDocumented}}
{{#isDocumented}}{{{ oneLineDoc }}} {{{ extendedDocLink }}}{{/isDocumented}}
</dd>
{{/publicLibraries}}
{{/categoriesWithPublicLibraries}}
Expand Down
4 changes: 2 additions & 2 deletions testing/test_package_custom_templates/templates/library.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ <h2>Classes</h2>
{{{linkedName}}}{{{linkedGenericParameters}}}
</dt>
<dd>
{{{ oneLineDoc }}}
{{{ oneLineDoc }}} {{{ extendedDocLink }}}
</dd>
{{/library.publicClasses}}
</dl>
Expand All @@ -33,7 +33,7 @@ <h2>Functions</h2>
<dl>
{{#library.publicFunctions}}
{{{linkedName}}}{{{linkedGenericParameters}}}
{{{ oneLineDoc }}}
{{{ oneLineDoc }}} {{{ extendedDocLink }}}
{{/library.publicFunctions}}
</dl>
</div>
Expand Down