-
-
Notifications
You must be signed in to change notification settings - Fork 171
feat: support dartdoc generation #138
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
Changes from all commits
abb846b
13c6ec3
a1b7a18
cab8142
031488a
2da32cb
caea89a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -147,17 +147,21 @@ _Statement? _createAssetTypeStatement( | |
if (assetType.isSupportedImage) { | ||
return _Statement( | ||
type: 'AssetGenImage', | ||
filePath: assetType.path, | ||
name: name, | ||
value: 'AssetGenImage(\'${posixStyle(assetType.path)}\')', | ||
isConstConstructor: true, | ||
needDartDoc: true, | ||
); | ||
} else if (FileSystemEntity.isDirectorySync(childAssetAbsolutePath)) { | ||
final childClassName = '\$${assetType.path.camelCase().capitalize()}Gen'; | ||
return _Statement( | ||
type: childClassName, | ||
filePath: assetType.path, | ||
name: name, | ||
value: '$childClassName()', | ||
isConstConstructor: true, | ||
needDartDoc: false, | ||
); | ||
} else if (!assetType.isIgnoreFile) { | ||
final integration = integrations.firstWhereOrNull( | ||
|
@@ -166,17 +170,21 @@ _Statement? _createAssetTypeStatement( | |
if (integration == null) { | ||
return _Statement( | ||
type: 'String', | ||
filePath: assetType.path, | ||
name: name, | ||
value: '\'${posixStyle(assetType.path)}\'', | ||
isConstConstructor: false, | ||
needDartDoc: true, | ||
); | ||
} else { | ||
integration.isEnabled = true; | ||
return _Statement( | ||
type: integration.className, | ||
filePath: assetType.path, | ||
name: name, | ||
value: integration.classInstantiate(posixStyle(assetType.path)), | ||
isConstConstructor: integration.isConstConstructor, | ||
needDartDoc: true, | ||
); | ||
} | ||
} | ||
|
@@ -226,17 +234,20 @@ String _dotDelimiterStyleDefinition( | |
if (dirname(assetType.path) == '.') { | ||
assetsStaticStatements.add(_Statement( | ||
type: className, | ||
filePath: assetType.path, | ||
name: assetType.baseName.camelCase(), | ||
value: '$className()', | ||
isConstConstructor: true, | ||
needDartDoc: true, | ||
)); | ||
} | ||
} | ||
|
||
assetTypeQueue.addAll(assetType.children); | ||
} | ||
} | ||
buffer.writeln(_assetsClassDefinition(assetsStaticStatements)); | ||
buffer | ||
.writeln(_dotDelimiterStyleAssetsClassDefinition(assetsStaticStatements)); | ||
return buffer.toString(); | ||
} | ||
|
||
|
@@ -292,13 +303,24 @@ String _flatStyleDefinition( | |
) | ||
.whereType<_Statement>() | ||
.toList(); | ||
return _assetsClassDefinition(statements); | ||
return _flatStyleAssetsClassDefinition(statements); | ||
} | ||
|
||
String _assetsClassDefinition(List<_Statement> statements) { | ||
final statementsBlock = statements | ||
.map((statement) => ' ${statement.toStaticFieldString()}') | ||
.join('\n'); | ||
String _flatStyleAssetsClassDefinition(List<_Statement> statements) { | ||
final statementsBlock = | ||
statements.map((statement) => '''${statement.toDartDocString()} | ||
${statement.toStaticFieldString()} | ||
''').join('\n'); | ||
return _assetsClassDefinition(statementsBlock); | ||
} | ||
|
||
String _dotDelimiterStyleAssetsClassDefinition(List<_Statement> statements) { | ||
final statementsBlock = | ||
statements.map((statement) => statement.toStaticFieldString()).join('\n'); | ||
return _assetsClassDefinition(statementsBlock); | ||
} | ||
|
||
String _assetsClassDefinition(String statementsBlock) { | ||
return ''' | ||
class Assets { | ||
Assets._(); | ||
|
@@ -313,7 +335,11 @@ String _directoryClassGenDefinition( | |
List<_Statement> statements, | ||
) { | ||
final statementsBlock = statements | ||
.map((statement) => ' ${statement.toGetterString()}') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's unnecessary because of using DartFormatter. |
||
.map((statement) => statement.needDartDoc | ||
? '''${statement.toDartDocString()} | ||
${statement.toGetterString()} | ||
''' | ||
: statement.toGetterString()) | ||
.join('\n'); | ||
return ''' | ||
class $className { | ||
|
@@ -383,15 +409,21 @@ class AssetGenImage extends AssetImage { | |
class _Statement { | ||
const _Statement({ | ||
required this.type, | ||
required this.filePath, | ||
required this.name, | ||
required this.value, | ||
required this.isConstConstructor, | ||
required this.needDartDoc, | ||
}); | ||
|
||
final String type; | ||
final String filePath; | ||
final String name; | ||
final String value; | ||
final bool isConstConstructor; | ||
final bool needDartDoc; | ||
|
||
String toDartDocString() => '/// File path: $filePath'; | ||
|
||
String toGetterString() => | ||
'$type get $name => ${isConstConstructor ? 'const' : ''} $value;'; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,7 +29,7 @@ String generateColors( | |
buffer.writeln("import 'package:flutter/material.dart';"); | ||
buffer.writeln(); | ||
buffer.writeln('class ColorName {'); | ||
buffer.writeln(' ColorName._();'); | ||
buffer.writeln('ColorName._();'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's unnecessary because of using DartFormatter. |
||
buffer.writeln(); | ||
|
||
final colorList = <_Color>[]; | ||
|
@@ -61,8 +61,9 @@ String _colorStatement(_Color color) { | |
final buffer = StringBuffer(); | ||
if (color.isMaterial) { | ||
final swatch = swatchFromPrimaryHex(color.hex); | ||
final statement = ''' | ||
static const MaterialColor ${color.name.camelCase()} = MaterialColor( | ||
final statement = '''/// MaterialColor: | ||
${swatch.entries.map((e) => '/// ${e.key}: ${hexFromColor(e.value)}').join('\n')} | ||
static const MaterialColor ${color.name.camelCase()} = MaterialColor( | ||
${swatch[500]}, | ||
<int, Color>{ | ||
${swatch.entries.map((e) => '${e.key}: Color(${e.value}),').join('\n')} | ||
|
@@ -72,8 +73,9 @@ String _colorStatement(_Color color) { | |
} | ||
if (color.isMaterialAccent) { | ||
final accentSwatch = accentSwatchFromPrimaryHex(color.hex); | ||
final statement = ''' | ||
static const MaterialAccentColor ${color.name.camelCase()}Accent = MaterialAccentColor( | ||
final statement = '''/// MaterialAccentColor: | ||
${accentSwatch.entries.map((e) => '/// ${e.key}: ${hexFromColor(e.value)}').join('\n')} | ||
static const MaterialAccentColor ${color.name.camelCase()}Accent = MaterialAccentColor( | ||
${accentSwatch[200]}, | ||
<int, Color>{ | ||
${accentSwatch.entries.map((e) => '${e.key}: Color(${e.value}),').join('\n')} | ||
|
@@ -82,8 +84,11 @@ String _colorStatement(_Color color) { | |
buffer.writeln(statement); | ||
} | ||
if (color.isNormal) { | ||
final comment = '/// Color: ${color.hex}'; | ||
final statement = | ||
'''static const Color ${color.name.camelCase()} = Color(${colorFromHex(color.hex)});'''; | ||
|
||
buffer.writeln(comment); | ||
buffer.writeln(statement); | ||
} | ||
return buffer.toString(); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,11 +21,12 @@ String generateFonts( | |
buffer.writeln(header); | ||
buffer.writeln(ignoreAnalysis); | ||
buffer.writeln('class FontFamily {'); | ||
buffer.writeln(' FontFamily._();'); | ||
buffer.writeln('FontFamily._();'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's unnecessary because of using DartFormatter. |
||
buffer.writeln(); | ||
|
||
fonts.map((element) => element.family).distinct().sorted().forEach((family) { | ||
buffer.writeln(" static const String ${family.camelCase()} = '$family';"); | ||
buffer.writeln("""/// Font family: $family | ||
static const String ${family.camelCase()} = '$family';"""); | ||
}); | ||
|
||
buffer.writeln('}'); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's unnecessary because of using DartFormatter.