Skip to content

Commit

Permalink
Change gen-class-name for fonts colors assets
Browse files Browse the repository at this point in the history
  • Loading branch information
Cu-Toof committed Sep 3, 2022
1 parent e89daed commit 4bf74c8
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 23 deletions.
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -741,14 +741,16 @@ flutter_gen:
style: dot-delimiter
# Optional
outputs:
class_name: Assets
# Default is Assets
class_name: MyAssets
fonts:
# Optional
enabled: true
# Optional
outputs:
class_name: FontFamily
# Default is FontFamily
class_name: MyFontFamily
colors:
# Optional
Expand All @@ -757,7 +759,8 @@ flutter_gen:
inputs: []
# Optional
outputs:
class_name: ColorName
# Default is ColorName
class_name: MyColorName
flutter:
# See: https://flutter.dev/docs/development/ui/assets-and-images#specifying-assets
Expand Down
9 changes: 3 additions & 6 deletions packages/core/lib/flutter_generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,8 @@ class FlutterGenerator {
}

if (flutterGen.colors.enabled && flutterGen.colors.inputs.isNotEmpty) {
final generated = generateColors(
pubspecFile,
formatter,
flutterGen.colors,
);
final generated =
generateColors(pubspecFile, formatter, flutterGen.colors);
final colors =
File(normalize(join(pubspecFile.parent.path, output, colorsName)));
writeAsString(generated, file: colors);
Expand All @@ -81,8 +78,8 @@ class FlutterGenerator {
if (flutterGen.fonts.enabled && flutter.fonts.isNotEmpty) {
final generated = generateFonts(
formatter,
flutterGen.fonts,
flutter.fonts,
genFonts: flutterGen.fonts,
);
final fonts =
File(normalize(join(pubspecFile.parent.path, output, fontsName)));
Expand Down
16 changes: 12 additions & 4 deletions packages/core/lib/generators/assets_generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,9 @@ String _dotDelimiterStyleDefinition(

/// Generate style like Assets.fooBar
String _camelCaseStyleDefinition(
AssetsGenConfig config, List<Integration> integrations) {
AssetsGenConfig config,
List<Integration> integrations,
) {
return _flatStyleDefinition(
config,
integrations,
Expand All @@ -288,7 +290,9 @@ String _camelCaseStyleDefinition(

/// Generate style like Assets.foo_bar
String _snakeCaseStyleDefinition(
AssetsGenConfig config, List<Integration> integrations) {
AssetsGenConfig config,
List<Integration> integrations,
) {
return _flatStyleDefinition(
config,
integrations,
Expand Down Expand Up @@ -329,7 +333,9 @@ String _flatStyleDefinition(
}

String _flatStyleAssetsClassDefinition(
String? className, List<_Statement> statements) {
String? className,
List<_Statement> statements,
) {
final statementsBlock =
statements.map((statement) => '''${statement.toDartDocString()}
${statement.toStaticFieldString()}
Expand All @@ -338,7 +344,9 @@ String _flatStyleAssetsClassDefinition(
}

String _dotDelimiterStyleAssetsClassDefinition(
String? className, List<_Statement> statements) {
String? className,
List<_Statement> statements,
) {
final statementsBlock =
statements.map((statement) => statement.toStaticFieldString()).join('\n');
return _assetsClassDefinition(className, statementsBlock);
Expand Down
2 changes: 1 addition & 1 deletion packages/core/lib/generators/colors_generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ String generateColors(
}

final buffer = StringBuffer();
final className = genColors.outputs?.className ?? 'FontFamily';
final className = genColors.outputs?.className ?? 'ColorName';
buffer.writeln(header);
buffer.writeln(ignore);
buffer.writeln("import 'package:flutter/painting.dart';");
Expand Down
8 changes: 4 additions & 4 deletions packages/core/lib/generators/fonts_generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ import 'generator_helper.dart';

String generateFonts(
DartFormatter formatter,
FlutterGenFonts genFonts,
List<FlutterFonts> fonts,
) {
List<FlutterFonts> fonts, {
FlutterGenFonts? genFonts,
}) {
if (fonts.isEmpty) {
throw InvalidSettingsException(
'The value of "flutter/fonts:" is incorrect.');
}

final buffer = StringBuffer();
final className = genFonts.outputs?.className ?? 'FontFamily';
final className = genFonts?.outputs?.className ?? 'FontFamily';
buffer.writeln(header);
buffer.writeln(ignore);
buffer.writeln('class $className {');
Expand Down
7 changes: 2 additions & 5 deletions packages/runner/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,12 @@ environment:
sdk: '>=2.14.0 <3.0.0'

dependencies:
flutter_gen_core: 4.3.0
build: '>=2.0.0 <3.0.0'
collection: '>=1.15.0 <2.0.0'
crypto: '>=3.0.0 <4.0.0'
glob: '>=2.0.0 <3.0.0'
flutter_gen_core:
git:
url: https://github.com/Cu-Toof/flutter_gen.git
path: packages/core

dev_dependencies:
flutter_lints: '>=2.0.1 <3.0.0'
build_test: '>=2.0.0 <3.0.0'
build_test: '>=2.0.0 <3.0.0'

0 comments on commit 4bf74c8

Please sign in to comment.