Skip to content

Commit

Permalink
Remove @image directive. (#3568)
Browse files Browse the repository at this point in the history
* Remove @image directive.

* Change README to have quotes.

* Remove quotes.
  • Loading branch information
kallentu committed Nov 6, 2023
1 parent 85cfcc0 commit 339efa3
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 53 deletions.
9 changes: 3 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -215,16 +215,14 @@ library my_library;

A file `categories.json` will be generated at the top level of the documentation tree with
information about categories collected from objects in the source tree. The directives
`@category`, `@subCategory`, and `@image` are understood and saved into this json.
Future versions of dartdoc may make direct use of the image tags.
`@category`, and `@subCategory` are understood and saved into this json.

As an example, if we document the class Icon in flutter using the following:

```dart
/// {@category Basics}
/// {@category Assets, Images, and Icons}
/// {@category Assets and Icons}
/// {@subCategory Information displays}
/// {@image <image alt='' src='/images/catalog-widget-placeholder.png'>}
class Icon extends StatelessWidget {}
```

Expand All @@ -237,13 +235,12 @@ that will result in the following json:
"href": "widgets/Icon-class.html",
"type": "class",
"categories": [
"Assets, Images, and Icons",
"Assets and Icons",
"Basics"
],
"subcategories": [
"Information displays"
],
"image": "<image alt='' src='/images/catalog-widget-placeholder.png'>"
}
```

Expand Down
1 change: 0 additions & 1 deletion lib/src/generator/generator_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ String generateCategoryJson(Iterable<Categorization> categories, bool pretty) {
'categories': categorization.categoryNames,
if (categorization.hasSubCategoryNames)
'subcategories': categorization.subCategoryNames,
if (categorization.hasImage) 'image': categorization.image,
}
];

Expand Down
28 changes: 0 additions & 28 deletions lib/src/generator/templates.runtime_renderers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -966,41 +966,13 @@ class _Renderer_Categorization extends RendererBase<Categorization> {
self.renderSimpleVariable(c, remainingNames, 'bool'),
getBool: (CT_ c) => c.hasCategoryNames == true,
),
'hasImage': Property(
getValue: (CT_ c) => c.hasImage,
renderVariable: (CT_ c, Property<CT_> self,
List<String> remainingNames) =>
self.renderSimpleVariable(c, remainingNames, 'bool'),
getBool: (CT_ c) => c.hasImage == true,
),
'hasSubCategoryNames': Property(
getValue: (CT_ c) => c.hasSubCategoryNames,
renderVariable: (CT_ c, Property<CT_> self,
List<String> remainingNames) =>
self.renderSimpleVariable(c, remainingNames, 'bool'),
getBool: (CT_ c) => c.hasSubCategoryNames == true,
),
'image': Property(
getValue: (CT_ c) => c.image,
renderVariable:
(CT_ c, Property<CT_> self, List<String> remainingNames) {
if (remainingNames.isEmpty) {
return self.getValue(c).toString();
}
var name = remainingNames.first;
var nextProperty =
_Renderer_String.propertyMap().getValue(name);
return nextProperty.renderVariable(
self.getValue(c) as String,
nextProperty,
[...remainingNames.skip(1)]);
},
isNullValue: (CT_ c) => c.image == null,
renderValue: (CT_ c, RendererBase<CT_> r,
List<MustachioNode> ast, StringSink sink) {
_render_String(c.image!, ast, r.template, sink, parent: r);
},
),
'subCategoryNames': Property(
getValue: (CT_ c) => c.subCategoryNames,
renderVariable: (CT_ c, Property<CT_> self,
Expand Down
19 changes: 2 additions & 17 deletions lib/src/model/directives/categorization.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ import 'package:collection/collection.dart';
import 'package:dartdoc/src/model/model.dart';
import 'package:meta/meta.dart';

final RegExp _categoryRegExp = RegExp(
r'[ ]*{@(category|subCategory|image) (.+?)}[ ]*\n?',
multiLine: true);
final RegExp _categoryRegExp =
RegExp(r'[ ]*{@(category|subCategory) (.+?)}[ ]*\n?', multiLine: true);

/// Mixin parsing the `@category` directive for ModelElements.
mixin Categorization on DocumentationComment implements Indexable {
Expand All @@ -31,15 +30,12 @@ mixin Categorization on DocumentationComment implements Indexable {
categorySet.add(match[2]!.trim());
case 'subCategory':
subCategorySet.add(match[2]!.trim());
case 'image':
_image = match[2]!.trim();
}
return '';
});

_categoryNames = categorySet.toList(growable: false)..sort();
_subCategoryNames = subCategorySet.toList(growable: false)..sort();
_image ??= '';
return rawDocs;
}

Expand All @@ -65,17 +61,6 @@ mixin Categorization on DocumentationComment implements Indexable {
return _categoryNames;
}

bool get hasImage => image!.isNotEmpty;
String? _image;

/// Either a URI to a defined image,
/// or 'null' if one was not declared.
String? get image {
// TODO(jcollins-g): avoid side-effect dependency
if (_image == null) documentationLocal;
return _image;
}

@visibleForTesting
List<Category> get categories => [
...?categoryNames?.map((n) => package.nameToCategory[n]).whereNotNull()
Expand Down
1 change: 0 additions & 1 deletion lib/src/model/documentation_comment.dart
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,6 @@ mixin DocumentationComment
'canonicalFor',
'category',
'hideConstantImplementations',
'image',
'subCategory',

// Common Dart annotations which may decorate named parameters:
Expand Down

0 comments on commit 339efa3

Please sign in to comment.