Skip to content

Commit 12b799b

Browse files
committed
Improve docs generation
1 parent a57d37d commit 12b799b

File tree

1 file changed

+28
-5
lines changed

1 file changed

+28
-5
lines changed

forui_internal_gen/lib/src/source/transformations_extension.dart

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,36 @@ class TransformationsExtension {
4040
// Copy the documentation comments from the fields.
4141
final docs = [
4242
'/// ## Parameters',
43-
for (final field in fields)
44-
if (field.documentationComment?.split('.').firstOrNull case final comment?)
45-
'/// * [${element.name3}.${field.name3}] - ${comment.replaceFirst('/// ', '')}.'
46-
else
47-
'/// * [${element.name3}.${field.name3}]',
43+
// for (final field in fields)
44+
// if (field.documentationComment?.split(RegExp(r'(\. )|\n')).firstOrNull case final comment?)
45+
// '/// * [${element.name3}.${field.name3}] - ${comment.replaceFirst('/// ', '')}.'
46+
// else
47+
// '/// * [${element.name3}.${field.name3}]',
4848
];
4949

50+
for (final field in fields) {
51+
final prefix = '/// * [${element.name3}.${field.name3}]';
52+
final lines = field.documentationComment?.split('\n') ?? const <String>[];
53+
54+
switch (lines.firstOrNull) {
55+
case final comment? when comment.startsWith('/// {@macro'):
56+
docs.add('$prefix - \n$comment');
57+
continue;
58+
59+
case final comment? when comment.startsWith('/// {@template'):
60+
final summary = lines.skip(1).join('\n').replaceFirst('/// ', '').split('.').firstOrNull;
61+
final suffix = summary == null ? '' : ' - $summary.';
62+
docs.add('$prefix$suffix');
63+
continue;
64+
65+
default:
66+
final summary = field.documentationComment?.replaceFirst('/// ', '').split('.').firstOrNull;
67+
final suffix = summary == null ? '' : ' - $summary.';
68+
docs.add('$prefix$suffix');
69+
continue;
70+
}
71+
}
72+
5073
// Generate assignments for the copyWith method body
5174
final assignments = fields.map((f) {
5275
if (nestedMotion(f.type) || nestedStyle(f.type)) {

0 commit comments

Comments
 (0)