Line data Source code
1 : import 'package:enum_assist/src/enum_field.dart'; 2 : import 'package:enum_assist/src/templates/map_template.dart'; 3 : 4 : /// {@template enum_assist.description_template} 5 : /// Returns the description from the enum field. 6 : /// {@endtemplate} 7 : class DescriptionTemplate extends MapTemplate { 8 : /// {@macro enum_assist.description_template} 9 0 : DescriptionTemplate(String enumName, Iterable<EnumField> fields) 10 0 : : super( 11 : enumName, 12 : fields, 13 0 : getValue: (field) => field.getDescription, 14 : methodName: 'description', 15 0 : typeAsString: '$String?', 16 : docComment: ''' 17 : /// Returns the description of the enum field. 18 : /// 19 : /// If the description is null, the doc comment of the enum field is returned.''', 20 : ); 21 : 22 0 : @override 23 : String? prepValueForGen(String? value) { 24 : if (value == null) return null; 25 : final description = value 26 0 : .replaceAll(RegExp('{@(template|endtemplate|macro)*(?:[^}]*)}'), '') 27 0 : .replaceAll(RegExp('^\n*'), ''); 28 : 29 : return ''' 30 : \'\'\' 31 0 : $description\'\'\''''; 32 : } 33 : }