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 #634 from Parabeac/release/2.8.0
Browse files Browse the repository at this point in the history
Release/2.8.0
  • Loading branch information
mergify[bot] committed Apr 11, 2022
2 parents b326ec9 + 0fff107 commit 77b16b6
Show file tree
Hide file tree
Showing 61 changed files with 5,594 additions and 19 deletions.
3 changes: 3 additions & 0 deletions lib/generation/generators/plugins/pb_plugin_node.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ abstract class PBTag extends PBVisualIntermediateNode {
// [PBSharedMasterNode] and the [PBSharedMasterNode]'s children. That is why we are returing
// `iNode` at the end.
if (iNode is PBSharedMasterNode) {
tree.injectBetween(
parent: iNode, child: tree.childrenOf(iNode).first, insertee: tag);

return iNode;
} else if (iNode is PBSharedInstanceIntermediateNode) {
iNode.parent = parent;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class StatefulTemplateStrategy extends TemplateStrategy {
${manager.generateImports()}
class $widgetName extends StatefulWidget{
${node is PBSharedMasterNode ? 'final constraints;' : ''}
${node is PBSharedMasterNode ? 'final BoxConstraints constraints;' : ''}
$overrideVars
const $widgetName(${node is PBSharedMasterNode ? 'this.constraints,' : ''} {Key? key, $overrides}) : super(key: key);
@override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class StatelessTemplateStrategy extends TemplateStrategy {
${manager.generateImports()}
class ${widgetName.pascalCase} extends StatelessWidget{
${node is PBSharedMasterNode ? 'final constraints;' : ''}
${node is PBSharedMasterNode ? 'final BoxConstraints constraints;' : ''}
${overrideVars.isNotEmpty ? overrideVars : ''}
const ${widgetName.pascalCase}(${node is PBSharedMasterNode ? 'this.constraints,' : ''} {Key? key, ${overrides.isNotEmpty ? overrides : ''}}) : super(key : key);
${manager.generateGlobalVariables()}
Expand Down
60 changes: 48 additions & 12 deletions lib/tags/custom_tag/custom_tag.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ import 'package:parabeac_core/interpret_and_optimize/entities/interfaces/pb_inje
import 'package:parabeac_core/interpret_and_optimize/entities/subclasses/pb_intermediate_constraints.dart';
import 'package:parabeac_core/interpret_and_optimize/entities/pb_shared_instance.dart';
import 'package:parabeac_core/interpret_and_optimize/entities/pb_shared_master_node.dart';
import 'package:parabeac_core/interpret_and_optimize/entities/subclasses/pb_layout_intermediate_node.dart';
import 'package:parabeac_core/interpret_and_optimize/helpers/child_strategy.dart';
import 'package:parabeac_core/interpret_and_optimize/helpers/override_helper.dart';
import 'package:parabeac_core/interpret_and_optimize/helpers/pb_context.dart';
import 'package:parabeac_core/interpret_and_optimize/entities/subclasses/pb_intermediate_node.dart';
import 'package:parabeac_core/interpret_and_optimize/helpers/pb_intermediate_node_tree.dart';
import 'package:uuid/uuid.dart';
import 'package:recase/recase.dart';
import 'package:path/path.dart' as path;

class CustomTag extends PBTag implements PBInjectedIntermediate {
@override
Expand All @@ -30,13 +30,16 @@ class CustomTag extends PBTag implements PBInjectedIntermediate {
ParentLayoutSizing layoutCrossAxisSizing;
@override
ParentLayoutSizing layoutMainAxisSizing;

bool isComponent;
CustomTag(
String UUID,
Rectangle3D frame,
this.name, {
PBIntermediateConstraints constraints,
this.layoutCrossAxisSizing,
this.layoutMainAxisSizing,
this.isComponent,
}) : super(
UUID,
frame,
Expand Down Expand Up @@ -69,6 +72,8 @@ class CustomTag extends PBTag implements PBInjectedIntermediate {
constraints: originalRef.constraints.copyWith(),
layoutCrossAxisSizing: originalRef.layoutCrossAxisSizing,
layoutMainAxisSizing: originalRef.layoutMainAxisSizing,
isComponent: originalRef is PBSharedMasterNode &&
originalRef.componentSetName == null, //Variable used to add extra info. to custom file.
);
}
}
Expand All @@ -92,16 +97,23 @@ class CustomTagGenerator extends PBGenerator {
'$DIRECTORY_GEN/$cleanName.dart',
MainInfo().projectName,
));

context.configuration.generationConfiguration.fileStructureStrategy
.commandCreated(WriteSymbolCommand(
Uuid().v4(),
cleanName,
customBoilerPlate(
titleName, context.tree.childrenOf(source).first, context),
relativePath: '$DIRECTORY_GEN',
symbolPath: 'lib',
ownership: FileOwnership.DEV,
));
.commandCreated(
WriteSymbolCommand(
Uuid().v4(),
cleanName,
customBoilerPlate(
titleName,
context.tree.childrenOf(source).first,
context,
source,
),
relativePath: '$DIRECTORY_GEN',
symbolPath: 'lib',
ownership: FileOwnership.DEV,
),
);

if (source is CustomTag) {
return '''
Expand All @@ -114,7 +126,11 @@ class CustomTagGenerator extends PBGenerator {
}

String customBoilerPlate(
String className, PBIntermediateNode child, PBContext context) {
String className,
PBIntermediateNode child,
PBContext context,
CustomTag source,
) {
var variableList = <String>[];
if (child is PBSharedInstanceIntermediateNode) {
if (child.sharedParamValues != null) {
Expand All @@ -135,7 +151,27 @@ class CustomTagGenerator extends PBGenerator {
}
}
}

/// Import variable in case we need to import
/// component file inside custom file
var import = '';
/// Suffix to be appended after `widget.child`.
/// The '!' is for null safety. Optionally,
/// we can also add reference to the component.
var suffix = '!';
if (source.isComponent) {
var baseCompName = className.replaceAll('Custom', '');
import = FlutterImport(
path.join(WriteSymbolCommand.DEFAULT_SYMBOL_PATH, context.tree.name,
'${baseCompName.snakeCase}.g.dart'),
MainInfo().projectName,
).toString();
suffix =
'?? $baseCompName(BoxConstraints(maxWidth: ${child.parent.frame.width}, maxHeight: ${child.parent.frame.height},))';
}

return '''
$import
import 'package:flutter/material.dart';
class $className extends StatefulWidget{
Expand All @@ -150,7 +186,7 @@ class CustomTagGenerator extends PBGenerator {
class _${className}State extends State<$className> {
@override
Widget build(BuildContext context){
return widget.child!;
return widget.child $suffix;
}
}
''';
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: 2.7.0
version: 2.8.0
# homepage: https://www.example.com

environment:
Expand Down
64 changes: 64 additions & 0 deletions test/golden/auto_layout_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import 'dart:io';
import 'package:path/path.dart' as path;
import 'package:test/test.dart';

void main() {
final projectName = 'golden_auto_layout_testing_project';
final basePath = path.join(path.current, 'test', 'golden');
final runtimeFilePath = path.join(basePath, projectName, 'lib');
final goldenFilesPath = path.join(basePath, 'golden_files', 'auto_layout');
group('Auto Layout Golden Test', () {
setUp(() async {
// Run Parabeac core to generate test file
await Process.run('dart', [
'parabeac.dart',
'-f',
'9yfEiTTiE5hoyZeRTGopQd',
'-k',
'346172-e6b93eec-364f-4baa-bee8-24bf1e4d26da',
'-n',
'$projectName',
'-o',
'$basePath'
]);
});
test('Generating Auto Layout and Comparing Golden File', () async {
/// Fetch a list with all the names for Auto Layout Golden Files
final fileNames =
File(path.join(goldenFilesPath, 'auto_layout_file_names.txt'));

final goldenFiles = <File>[];
final runtimeFiles = <File>[];

var fileNamesLines = fileNames.readAsLinesSync();

/// Add all files as golden files to the list
/// Also add run time files to another list
for (var i = 0; i < fileNamesLines.length; i++) {
goldenFiles.add(
File(path.join(goldenFilesPath, '${fileNamesLines[i]}.golden')));

runtimeFiles.add(File(path.join(runtimeFilePath, 'screens',
'auto_layout_permutations', '${fileNamesLines[i]}.g.dart')));
}

/// Iterate through golden/runtime files and compare them
for (var i = 0; i < goldenFiles.length; i++) {
var goldenFile = goldenFiles[i];
var runtimeFile = runtimeFiles[i];
var goldenFileLines = goldenFile.readAsLinesSync();
var runtimeFileLines = runtimeFile.readAsLinesSync();

for (var j = 0; j < goldenFileLines.length; j++) {
expect(runtimeFileLines[j], goldenFileLines[j],
reason: 'File ${path.basename(goldenFile.path)} Line $j');
}
}
}, timeout: Timeout(Duration(minutes: 5)));

tearDown(() async {
// Remove temporary project
await Process.start('rm', ['-rf', path.join(basePath, projectName)]);
});
});
}
50 changes: 50 additions & 0 deletions test/golden/golden_files/auto_layout/auto_layout_file_names.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
col_hz_fx_vr_fx_sp_pk1
col_hz_fx_vr_fx_sp_pk2
col_hz_fx_vr_fx_sp_pk3
col_hz_fx_vr_fx_sp_pk4
col_hz_fx_vr_fx_sp_pk5
col_hz_fx_vr_fx_sp_pk6
col_hz_fx_vr_fx_sp_pk7
col_hz_fx_vr_fx_sp_pk8
col_hz_fx_vr_fx_sp_pk9
col_hz_fx_vr_fx_sp_sb147
col_hz_fx_vr_fx_sp_sb258
col_hz_fx_vr_fx_sp_sb369
col_hz_fx_vr_hg_sp_pk147
col_hz_fx_vr_hg_sp_pk258
col_hz_fx_vr_hg_sp_pk369
col_hz_hg_vr_fx_sp_pk1
col_hz_hg_vr_fx_sp_pk2
col_hz_hg_vr_fx_sp_pk3
col_hz_hg_vr_fx_sp_pk4
col_hz_hg_vr_fx_sp_pk5
col_hz_hg_vr_fx_sp_pk6
col_hz_hg_vr_fx_sp_pk7
col_hz_hg_vr_fx_sp_pk8
col_hz_hg_vr_fx_sp_pk9
col_hz_hg_vr_fx_sp_sb147
col_hz_hg_vr_fx_sp_sb258
col_hz_hg_vr_fx_sp_sb369
col_hz_hg_vr_hg_sp_pk123456789
no_space_col_hz_hg_vr_hg_sp_pk123456789
no_space_row_hz_hg_vr_hg_sp_pk123456789
row_hz_fx_vr_fx_sp_pk1
row_hz_fx_vr_fx_sp_pk2
row_hz_fx_vr_fx_sp_pk3
row_hz_fx_vr_fx_sp_pk4
row_hz_fx_vr_fx_sp_pk5
row_hz_fx_vr_fx_sp_pk6
row_hz_fx_vr_fx_sp_pk7
row_hz_fx_vr_fx_sp_pk8
row_hz_fx_vr_fx_sp_pk9
row_hz_fx_vr_fx_sp_sb123
row_hz_fx_vr_fx_sp_sb456
row_hz_fx_vr_fx_sp_sb789
row_hz_fx_vr_hg_sp_pk147
row_hz_fx_vr_hg_sp_pk258
row_hz_fx_vr_hg_sp_pk369
row_hz_fx_vr_hg_sp_sb123456789
row_hz_hg_vr_fx_sp_pk147
row_hz_hg_vr_fx_sp_pk258
row_hz_hg_vr_fx_sp_pk369
row_hz_hg_vr_hg_sp_pk123456789
110 changes: 110 additions & 0 deletions test/golden/golden_files/auto_layout/col_hz_fx_vr_fx_sp_pk1.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
// *********************************************************************************
// PARABEAC-GENERATED CODE. DO NOT MODIFY.
//
// FOR MORE INFORMATION ON HOW TO USE PARABEAC, PLEASE VISIT docs.parabeac.com
// *********************************************************************************

import 'package:flutter/material.dart';
import 'package:auto_size_text/auto_size_text.dart';

class ColHzFxVrFxSpPk1 extends StatefulWidget {
const ColHzFxVrFxSpPk1({
Key? key,
}) : super(key: key);
@override
_ColHzFxVrFxSpPk1 createState() => _ColHzFxVrFxSpPk1();
}

class _ColHzFxVrFxSpPk1 extends State<ColHzFxVrFxSpPk1> {
_ColHzFxVrFxSpPk1();

@override
Widget build(BuildContext context) {
return Material(
color: Colors.white,
child: Stack(children: [
Positioned(
left: 37.0,
width: 326.0,
top: 100.0,
height: 200.0,
child: Container(
padding: EdgeInsets.only(
left: 10.0,
right: 10.0,
top: 10.0,
bottom: 10.0,
),
width: 326.000,
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
height: 15.0,
width: 24.0,
child: Container(
width: 24.000,
height: 15.000,
child: AutoSizeText(
'Left',
style: TextStyle(
fontFamily: 'Sanchez',
fontSize: 12.0,
fontWeight: FontWeight.w400,
letterSpacing: 0.0,
color: Colors.white,
),
textAlign: TextAlign.left,
))),
SizedBox(
height: 10.0,
),
Container(
height: 15.0,
width: 39.0,
child: Container(
width: 39.000,
height: 15.000,
child: AutoSizeText(
'Middle',
style: TextStyle(
fontFamily: 'Sanchez',
fontSize: 12.0,
fontWeight: FontWeight.w400,
letterSpacing: 0.0,
color: Colors.white,
),
textAlign: TextAlign.left,
))),
SizedBox(
height: 10.0,
),
Container(
height: 15.0,
width: 31.0,
child: Container(
width: 31.000,
height: 15.000,
child: AutoSizeText(
'Right',
style: TextStyle(
fontFamily: 'Sanchez',
fontSize: 12.0,
fontWeight: FontWeight.w400,
letterSpacing: 0.0,
color: Colors.white,
),
textAlign: TextAlign.left,
))),
])),
),
]),
);
}

@override
void dispose() {
super.dispose();
}
}
Loading

0 comments on commit 77b16b6

Please sign in to comment.