Skip to content

Commit

Permalink
Remove LanguageFeatureRenderer. (#3686)
Browse files Browse the repository at this point in the history
  • Loading branch information
kallentu authored Feb 27, 2024
1 parent d8e7f99 commit d25dfca
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 76 deletions.
6 changes: 2 additions & 4 deletions lib/src/model/container_modifiers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// BSD-style license that can be found in the LICENSE file.

import 'package:dartdoc/src/model/language_feature.dart';
import 'package:dartdoc/src/render/language_feature_renderer.dart';

/// Represents a single modifier applicable to containers.
class ContainerModifier implements Comparable<ContainerModifier> {
Expand Down Expand Up @@ -46,8 +45,7 @@ class ContainerModifier implements Comparable<ContainerModifier> {
extension BuildLanguageFeatureSet on Iterable<ContainerModifier> {
/// Transforms [ContainerModifiers] into a series of [LanguageFeature] objects
/// suitable for rendering as chips. Assumes iterable is sorted.
Iterable<LanguageFeature> asLanguageFeatureSet(
LanguageFeatureRenderer languageFeatureRenderer) =>
Iterable<LanguageFeature> get asLanguageFeatureSet =>
where((m) => !m.hideIfPresent.any(contains))
.map((m) => LanguageFeature(m.name, languageFeatureRenderer));
.map((m) => LanguageFeature(m.name));
}
5 changes: 1 addition & 4 deletions lib/src/model/inheriting_container.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import 'package:dartdoc/src/model/container_modifiers.dart';
import 'package:dartdoc/src/model/language_feature.dart';
import 'package:dartdoc/src/model/model.dart';
import 'package:dartdoc/src/model_utils.dart' as model_utils;
import 'package:dartdoc/src/render/language_feature_renderer.dart';
import 'package:meta/meta.dart';

/// A mixin to build an [InheritingContainer] capable of being constructed
Expand Down Expand Up @@ -99,9 +98,7 @@ abstract class InheritingContainer extends Container

@override
late final List<LanguageFeature> displayedLanguageFeatures =
containerModifiers
.asLanguageFeatureSet(const LanguageFeatureRendererHtml())
.toList();
containerModifiers.asLanguageFeatureSet.toList();

late final List<ModelElement> _allModelElements = () {
_inheritedElementsCache = _inheritedElements;
Expand Down
35 changes: 28 additions & 7 deletions lib/src/model/language_feature.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +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.

import 'package:dartdoc/src/render/language_feature_renderer.dart';

const Map<String, String> _featureDescriptions = {
'sealed':
'The direct subtypes of this class will be checked for exhaustiveness in switches.',
Expand Down Expand Up @@ -35,13 +33,36 @@ class LanguageFeature {
String? get featureUrl => _featureUrls[name];

/// The rendered label for this language feature.
String get featureLabel => _featureRenderer.renderLanguageFeatureLabel(this);
String get featureLabel {
final buffer = StringBuffer();
final url = featureUrl;

if (url != null) {
buffer.write('<a href="');
buffer.write(url);
buffer.write('"');
} else {
buffer.write('<span');
}

buffer.write(' class="feature feature-');
buffer.writeAll(name.toLowerCase().split(' '), '-');
buffer.write('" title="');
buffer.write(featureDescription);
buffer.write('">');
buffer.write(name);

if (url != null) {
buffer.write('</a>');
} else {
buffer.write('</span>');
}

return buffer.toString();
}

/// The name of this language feature.
final String name;

final LanguageFeatureRenderer _featureRenderer;

LanguageFeature(this.name, this._featureRenderer)
: assert(_featureDescriptions.containsKey(name));
LanguageFeature(this.name) : assert(_featureDescriptions.containsKey(name));
}
49 changes: 0 additions & 49 deletions lib/src/render/language_feature_renderer.dart

This file was deleted.

16 changes: 4 additions & 12 deletions test/container_modifiers_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,10 @@

import 'package:dartdoc/src/model/container_modifiers.dart';
import 'package:dartdoc/src/model/language_feature.dart';
import 'package:dartdoc/src/render/language_feature_renderer.dart';
import 'package:test/test.dart';

class TestChipRenderer extends LanguageFeatureRenderer {
@override
String renderLanguageFeatureLabel(LanguageFeature l) => l.name;
}

extension TestChipsRenderer on Iterable<LanguageFeature> {
String asRenderedString() => map((l) => l.featureLabel).join(' ');
String asRenderedString() => map((l) => l.name).join(' ');
}

void main() {
Expand All @@ -24,20 +18,18 @@ void main() {
ContainerModifier.interface,
ContainerModifier.abstract
]..sort();
expect(l.asLanguageFeatureSet(TestChipRenderer()).asRenderedString(),
expect(l.asLanguageFeatureSet.asRenderedString(),
equals('abstract base interface'));
});

test('hide abstract on sealed', () {
var l = [ContainerModifier.abstract, ContainerModifier.sealed]..sort();
expect(l.asLanguageFeatureSet(TestChipRenderer()).asRenderedString(),
equals('sealed'));
expect(l.asLanguageFeatureSet.asRenderedString(), equals('sealed'));
});

test('empty', () {
var l = <ContainerModifier>[];
expect(l.asLanguageFeatureSet(TestChipRenderer()).asRenderedString(),
equals(''));
expect(l.asLanguageFeatureSet.asRenderedString(), equals(''));
});
});
}

0 comments on commit d25dfca

Please sign in to comment.