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 #700 from Parabeac/dev
Browse files Browse the repository at this point in the history
Release - 3.3.0
  • Loading branch information
mergify[bot] committed Aug 15, 2022
2 parents 59f8e01 + f0a5088 commit 42900cc
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,39 +42,44 @@ class GlobalStylingAggregator {
/// Examines [globalStyles] and adds PostGenTasks to [builder]
static void addPostGenTasks(
FlutterProjectBuilder builder, PBDLGlobalStyles globalStyles) {
if (globalStyles.colors != null && globalStyles.colors.isNotEmpty) {
/// Check whether there are theme or global colors
if ((globalStyles.colors != null && globalStyles.colors.isNotEmpty) ||
(globalStyles.themeColors != null &&
globalStyles.themeColors.isNotEmpty)) {
/// Aggregate all colors
final globalColors = globalStyles.colors
..addAll(globalStyles.themeColors);
builder.postGenTasks.add(
ColorsPostGenTask(
builder.generationConfiguration,
globalStyles.colors,
globalColors,
),
);
}

if (globalStyles.textStyles != null && globalStyles.textStyles.isNotEmpty) {
/// Check whether there are theme or global textstyles
if ((globalStyles.textStyles != null &&
globalStyles.textStyles.isNotEmpty) ||
(globalStyles.themeTextStyles != null &&
globalStyles.themeTextStyles.isNotEmpty)) {
final globalTextStyles = globalStyles.textStyles
..addAll(globalStyles.themeTextStyles);
builder.postGenTasks.add(
TextStylesPostGenTask(
builder.generationConfiguration,
globalStyles.textStyles,
globalTextStyles,
),
);
}

var themeTextStyles = <PBDLGlobalTextStyle>[];

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

if (themeTextStyles.isNotEmpty) {
if (globalStyles.themeTextStyles.isNotEmpty ||
globalStyles.themeColors.isNotEmpty) {
/// Add Theme Styles to the Theme task
builder.postGenTasks.add(
ThemingPostGenTask(
builder.generationConfiguration,
themeTextStyles,
globalStyles.themeTextStyles ?? [],
globalStyles.themeColors ?? [],
),
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,47 +18,94 @@ class ThemingPostGenTask extends PostGenTask {
ThemingPostGenTask(
this.generationConfiguration,
this.textStyles,
this.colors,
);

@override
void execute() {
final projectName = MainInfo().projectName;
var pathService = GetIt.I.get<PathService>();

/// Map the [TextStyle] attributes in the project for [TextTheme]
final textThemeAttributes = textStyles
.map((style) =>
'${style.name.camelCase}: ${projectName.pascalCase}TextStyles.${style.name.camelCase},')
.join();
final textThemeBoilerplate = 'TextTheme($textThemeAttributes)';
/// Relative path to theming folder for imports
final themingRelativePath =
pathService.themingRelativePath.replaceFirst('lib/', '');

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

final themeConstant = ConstantHolder(
'ThemeData',
'themeData',
'ThemeData(textTheme: textTheme,)',
isconst: false,
final constants = <ConstantHolder>[];
final importBuffer = StringBuffer(
'import \'package:flutter/material.dart\';',
);

var pathService = GetIt.I.get<PathService>();
if (textStyles.isNotEmpty) {
importBuffer.writeln(
'import \'package:${projectName.snakeCase}/$themingRelativePath/${projectName.snakeCase}_text_styles.g.dart\';',
);

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

constants.add(ConstantHolder(
'TextTheme',
'textTheme',
textThemeBoilerplate,
));

/// Only create a [ThemeData] here if there are no [ColorSchemes].
///
/// This is because a [ThemeData] will already be generated for each [ColorSchem]
if (colors.isEmpty) {
constants.add(ConstantHolder(
'ThemeData',
'themeData',
'ThemeData(textTheme: textTheme,)',
isconst: false,
));
}
}

if (colors.isNotEmpty) {
importBuffer.writeln(
'import \'package:${projectName.snakeCase}/$themingRelativePath/${projectName.snakeCase}_colors.g.dart\';',
);

/// Map the [ColorSchemes] by name
final colorSchemeMap = <String, List<String>>{};
for (final color in colors) {
final attributeName = color.name.split('/').last;
final colorAttribute =
'$attributeName: ${projectName.pascalCase}Colors.${color.name.camelCase}';
if (colorSchemeMap.containsKey(color.colorScheme)) {
colorSchemeMap[color.colorScheme].add(colorAttribute);
} else {
colorSchemeMap[color.colorScheme] = [colorAttribute];
}
}

/// 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';
''';
/// Create the constants for [ThemeData] and [ColorSchemes]
for (final entry in colorSchemeMap.entries) {
final attributes = entry.value.join(',');
constants.add(ConstantHolder(
'ColorScheme', entry.key, 'ColorScheme.${entry.key}($attributes)'));
constants.add(ConstantHolder(
'ThemeData',
'themeData${entry.key.pascalCase}',
'ThemeData(${textStyles.isNotEmpty ? 'textTheme: textTheme,' : ''} colorScheme: ${entry.key},)',
isconst: false,
));
}
}

generationConfiguration.fileStructureStrategy.commandCreated(
WriteConstantsCommand(
Uuid().v4(),
[themeConstant, textConstant],
constants,
filename: '${projectName.snakeCase}_theme',
ownershipPolicy: FileOwnership.PBC,
imports: imports,
imports: importBuffer.toString(),
relativePath: pathService.themingRelativePath,
),
);
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: parabeac_core
description: Continuous Design / Continuous Integration for Figma-to-Flutter

version: 3.2.0
version: 3.3.0
# homepage: https://www.example.com

environment:
Expand Down

0 comments on commit 42900cc

Please sign in to comment.