Skip to content
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

Remove ModelElementRenderer. #3717

Merged
merged 1 commit into from
Mar 13, 2024
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
16 changes: 0 additions & 16 deletions lib/src/generator/templates.runtime_renderers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4215,20 +4215,6 @@ class _Renderer_DocumentationComment
self.renderSimpleVariable(c, remainingNames, 'bool'),
getBool: (CT_ c) => c.hasNodoc,
),
'modelElementRenderer': Property(
getValue: (CT_ c) => c.modelElementRenderer,
renderVariable: (CT_ c, Property<CT_> self,
List<String> remainingNames) =>
self.renderSimpleVariable(
c, remainingNames, 'ModelElementRenderer'),
isNullValue: (CT_ c) => false,
renderValue: (CT_ c, RendererBase<CT_> r,
List<MustachioNode> ast, StringSink sink) {
renderSimple(c.modelElementRenderer, ast, r.template, sink,
parent: r,
getters: _invisibleGetters['ModelElementRenderer']!);
},
),
'needsPrecache': Property(
getValue: (CT_ c) => c.needsPrecache,
renderVariable: (CT_ c, Property<CT_> self,
Expand Down Expand Up @@ -16140,7 +16126,6 @@ const _invisibleGetters = {
'fullyQualifiedNameWithoutLibrary',
'hasDocumentationComment',
'hasNodoc',
'modelElementRenderer',
'needsPrecache',
'pathContext',
'sourceFileName'
Expand Down Expand Up @@ -16574,7 +16559,6 @@ const _invisibleGetters = {
'runtimeType',
'superclassConstraints'
},
'ModelElementRenderer': {'hashCode', 'runtimeType'},
'ModelNode': {'hashCode', 'runtimeType', 'sourceCode'},
'PackageGraph': {
'allConstructedModelElements',
Expand Down
64 changes: 58 additions & 6 deletions lib/src/model/documentation_comment.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import 'package:dartdoc/src/model/documentation.dart';
import 'package:dartdoc/src/model/inheritable.dart';
import 'package:dartdoc/src/model/locatable.dart';
import 'package:dartdoc/src/model/source_code_mixin.dart';
import 'package:dartdoc/src/render/model_element_renderer.dart';
import 'package:dartdoc/src/utils.dart';
import 'package:dartdoc/src/warnings.dart';
import 'package:meta/meta.dart';
Expand Down Expand Up @@ -136,8 +135,6 @@ mixin DocumentationComment

p.Context get pathContext;

ModelElementRenderer get modelElementRenderer;

static const _allDirectiveNames = {
'animation',
'end-inject-html',
Expand Down Expand Up @@ -360,7 +357,29 @@ mixin DocumentationComment
}
var youTubeId = url.group(url.groupCount)!;

return modelElementRenderer.renderYoutubeUrl(youTubeId, width, height);
// Blank lines before and after, and no indenting at the beginning and end
// is needed so that Markdown doesn't confuse this with code, so be
// careful of whitespace here.
return '''

<iframe src="https://www.youtube.com/embed/$youTubeId?rel=0"
title="YouTube video player"
frameborder="0"
allow="accelerometer;
autoplay;
clipboard-write;
encrypted-media;
gyroscope;
picture-in-picture"
allowfullscreen=""
style="max-width: ${width}px;
max-height: ${height}px;
width: 100%;
height: 100%;
aspect-ratio: $width / $height;">
</iframe>

'''; // Must end at start of line, or following inline text will be indented.
});
}

Expand Down Expand Up @@ -477,8 +496,41 @@ mixin DocumentationComment
}
var overlayId = '${uniqueId}_play_button_';

return modelElementRenderer.renderAnimation(
uniqueId, width, height, movieUrl, overlayId);
return '''

<div style="position: relative;">
<div id="$overlayId"
onclick="var $uniqueId = document.getElementById('$uniqueId');
if ($uniqueId.paused) {
$uniqueId.play();
this.style.display = 'none';
} else {
$uniqueId.pause();
this.style.display = 'block';
}"
style="position:absolute;
width:${width}px;
height:${height}px;
z-index:100000;
background-position: center;
background-repeat: no-repeat;
background-image: url(static-assets/play_button.svg);">
</div>
<video id="$uniqueId"
style="width:${width}px; height:${height}px;"
onclick="var $overlayId = document.getElementById('$overlayId');
if (this.paused) {
this.play();
$overlayId.style.display = 'none';
} else {
this.pause();
$overlayId.style.display = 'block';
}" loop>
<source src="$movieUrl" type="video/mp4"/>
</video>
</div>

'''; // Must end at start of line, or following inline text will be indented.
});
}

Expand Down
18 changes: 10 additions & 8 deletions lib/src/model/model_element.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import 'package:dartdoc/src/model/feature_set.dart';
import 'package:dartdoc/src/model/model.dart';
import 'package:dartdoc/src/model/prefix.dart';
import 'package:dartdoc/src/model_utils.dart' as utils;
import 'package:dartdoc/src/render/model_element_renderer.dart';
import 'package:dartdoc/src/render/parameter_renderer.dart';
import 'package:dartdoc/src/runtime_stats.dart';
import 'package:dartdoc/src/source_linker.dart';
Expand Down Expand Up @@ -413,7 +412,14 @@ abstract class ModelElement extends Canonicalization
};
}

String get attributesAsString => modelElementRenderer.renderAttributes(this);
String get attributesAsString {
var allAttributes = attributes.toList(growable: false)
..sort(byAttributeOrdering);
return allAttributes
.map((f) =>
'<span class="${f.cssClassName}">${f.linkedNameWithParameters}</span>')
.join();
}

// True if this is a function, or if it is an type alias to a function.
bool get isCallable =>
Expand Down Expand Up @@ -677,14 +683,10 @@ abstract class ModelElement extends Canonicalization
return htmlEscape.convert(name);
}

return modelElementRenderer.renderLinkedName(this);
var cssClass = isDeprecated ? ' class="deprecated"' : '';
return '<a$cssClass href="$href">$displayName</a>';
}();

@visibleForTesting
@override
ModelElementRenderer get modelElementRenderer =>
const ModelElementRendererHtml();

ParameterRenderer get _parameterRenderer => const ParameterRendererHtml();

ParameterRenderer get _parameterRendererDetailed =>
Expand Down
104 changes: 0 additions & 104 deletions lib/src/render/model_element_renderer.dart

This file was deleted.

41 changes: 34 additions & 7 deletions test/documentation_comment_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -111,16 +111,43 @@ More text.'''));
''');

expectNoWarnings();
var rendered = libraryModel.modelElementRenderer.renderAnimation(
'barHerderAnimation',
100,
200,
Uri.parse('http://host/path/to/video.mp4'),
'barHerderAnimation_play_button_');
expect(doc, equals('''
Text.

$rendered

<div style="position: relative;">
<div id="barHerderAnimation_play_button_"
onclick="var barHerderAnimation = document.getElementById('barHerderAnimation');
if (barHerderAnimation.paused) {
barHerderAnimation.play();
this.style.display = 'none';
} else {
barHerderAnimation.pause();
this.style.display = 'block';
}"
style="position:absolute;
width:100px;
height:200px;
z-index:100000;
background-position: center;
background-repeat: no-repeat;
background-image: url(static-assets/play_button.svg);">
</div>
<video id="barHerderAnimation"
style="width:100px; height:200px;"
onclick="var barHerderAnimation_play_button_ = document.getElementById('barHerderAnimation_play_button_');
if (this.paused) {
this.play();
barHerderAnimation_play_button_.style.display = 'none';
} else {
this.pause();
barHerderAnimation_play_button_.style.display = 'block';
}" loop>
<source src="http://host/path/to/video.mp4" type="video/mp4"/>
</video>
</div>



End text.'''));
}
Expand Down
Loading