Skip to content
This repository has been archived by the owner on Jan 25, 2024. It is now read-only.

Commit

Permalink
Merge pull request #678 from Parabeac/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
ivan-015 committed Jun 29, 2022
2 parents bc8ead7 + 25cbbc4 commit 0d720a6
Show file tree
Hide file tree
Showing 4 changed files with 154 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,9 +1,43 @@
import 'package:parabeac_core/generation/flutter_project_builder/flutter_project_builder.dart';
import 'package:parabeac_core/generation/flutter_project_builder/post_gen_tasks/global_styling/colors_post_gen_task.dart';
import 'package:parabeac_core/generation/flutter_project_builder/post_gen_tasks/global_styling/text_styles_post_gen_task.dart';
import 'package:parabeac_core/generation/flutter_project_builder/post_gen_tasks/global_styling/theming_post_gen_task.dart';
import 'package:pbdl/pbdl.dart';

class GlobalStylingAggregator {
/// List of all supported TextStyles that should be exported
/// for the deeper theming integration
static const _textStyleList = [
'bodyLarge',
'bodyMedium',
'bodySmall',
'bodyText1',
'bodyText2',
'button',
'caption',
'displayLarge',
'displayMedium',
'displaySmall',
'headline1',
'headline2',
'headline3',
'headline4',
'headline5',
'headline6',
'headlineLarge',
'headlineMedium',
'headlineSmall',
'labelLarge',
'labelMedium',
'labelSmall',
'overline',
'subtitle1',
'subtitle2',
'titleLarge',
'titleMedium',
'titleSmall',
];

/// Examines [globalStyles] and adds PostGenTasks to [builder]
static void addPostGenTasks(
FlutterProjectBuilder builder, PBDLGlobalStyles globalStyles) {
Expand All @@ -24,5 +58,24 @@ class GlobalStylingAggregator {
),
);
}

var themeTextStyles = <PBDLGlobalTextStyle>[];

for (var style in globalStyles.textStyles) {
if (_textStyleList.contains(style.name)) {
/// Add Text Style to Global theming list
themeTextStyles.add(style);
}
}

if (themeTextStyles.isNotEmpty) {
/// Add Theme Styles to the Theme task
builder.postGenTasks.add(
ThemingPostGenTask(
builder.generationConfiguration,
themeTextStyles,
),
);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import 'package:get_it/get_it.dart';
import 'package:parabeac_core/controllers/main_info.dart';
import 'package:parabeac_core/generation/flutter_project_builder/post_gen_tasks/post_gen_task.dart';
import 'package:parabeac_core/generation/generators/value_objects/file_structure_strategy/commands/add_constant_command.dart';
import 'package:parabeac_core/generation/generators/value_objects/file_structure_strategy/file_ownership_policy.dart';
import 'package:parabeac_core/generation/generators/value_objects/file_structure_strategy/path_services/path_service.dart';
import 'package:parabeac_core/generation/generators/value_objects/generation_configuration/pb_generation_configuration.dart';
import 'package:pbdl/pbdl.dart';
import 'package:recase/recase.dart';
import 'package:uuid/uuid.dart';

class ThemingPostGenTask extends PostGenTask {
GenerationConfiguration generationConfiguration;
List<PBDLGlobalTextStyle> textStyles;

List<PBDLGlobalColor> colors;

ThemingPostGenTask(
this.generationConfiguration,
this.textStyles,
);

@override
void execute() {
final projectName = MainInfo().projectName;

/// Map the [TextStyle] attributes in the project for [TextTheme]
final textThemeAttributes = textStyles
.map((style) =>
'${style.name}: ${projectName.pascalCase}TextStyles.${style.name},')
.join();
final textThemeBoilerplate = 'TextTheme($textThemeAttributes)';

final textConstant = ConstantHolder(
'TextTheme',
'textTheme',
textThemeBoilerplate,
);

final themeConstant = ConstantHolder(
'ThemeData',
'themeData',
'ThemeData(textTheme: textTheme,)',
isconst: false,
);

var pathService = GetIt.I.get<PathService>();

/// Imports for material and the [TextStyles].
var imports = '''
import 'package:flutter/material.dart';
import 'package:${projectName.snakeCase}/${pathService.themingRelativePath.replaceFirst('lib/', '')}/${projectName.snakeCase}_text_styles.g.dart';
''';

generationConfiguration.fileStructureStrategy.commandCreated(
WriteConstantsCommand(
Uuid().v4(),
[themeConstant, textConstant],
filename: '${projectName.snakeCase}_theme',
ownershipPolicy: FileOwnership.PBC,
imports: imports,
relativePath: pathService.themingRelativePath,
),
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class WriteConstantsCommand extends FileStructureCommand {
var description =
constant.description.isNotEmpty ? '/// ${constant.description}' : '';
var constStr =
'static const ${constant.type} ${constant.name} = ${constant.value};';
'static ${constant.isconst ? 'const' : ''} ${constant.type} ${constant.name} = ${constant.value};';

constBuffer.writeln('$description\n$constStr');
});
Expand Down Expand Up @@ -87,10 +87,14 @@ class ConstantHolder {
/// Optional description to put as comment above the constant
String description;

/// Whether [this] should have "const" written in it.
bool isconst; //TODO: Temporary bool in order to write theming file.

ConstantHolder(
this.type,
this.name,
this.value, {
this.isconst = true,
this.description = '',
});
}
30 changes: 30 additions & 0 deletions test/golden/golden_files/global_styling/styling_text_styles.golden
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,34 @@ static const TextStyle newStyle = TextStyle(
fontStyle: FontStyle.normal,
)
;
/// headline1 description
static const TextStyle headline1 = TextStyle(
fontSize: 12.0,
fontWeight: FontWeight.w400,
letterSpacing: 0.0,
fontFamily: 'Inter',
decoration: TextDecoration.none,
fontStyle: FontStyle.normal,
)
;

static const TextStyle mynewStyle = TextStyle(
fontSize: 12.0,
fontWeight: FontWeight.w400,
letterSpacing: 0.0,
fontFamily: 'Poppins',
decoration: TextDecoration.none,
fontStyle: FontStyle.normal,
)
;

static const TextStyle headline2 = TextStyle(
fontSize: 12.0,
fontWeight: FontWeight.w700,
letterSpacing: 6.0,
fontFamily: 'Inter',
decoration: TextDecoration.none,
fontStyle: FontStyle.italic,
)
;
}

0 comments on commit 0d720a6

Please sign in to comment.