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 #262 from Parabeac/release-1.3.3
Browse files Browse the repository at this point in the history
Release 1.3.3
  • Loading branch information
mergify[bot] authored Feb 17, 2021
2 parents 4b915c6 + 7f01c9b commit 469d5d7
Show file tree
Hide file tree
Showing 18 changed files with 137 additions and 115 deletions.
28 changes: 28 additions & 0 deletions lib/controllers/figma_controller.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:parabeac_core/controllers/controller.dart';
import 'package:parabeac_core/controllers/main_info.dart';
import 'package:parabeac_core/input/figma/entities/layers/component.dart';
import 'package:parabeac_core/input/figma/entities/layers/frame.dart';
import 'package:parabeac_core/input/figma/helper/figma_project.dart';
import 'package:parabeac_core/input/helper/asset_processing_service.dart';
Expand Down Expand Up @@ -29,6 +30,8 @@ class FigmaController extends Controller {

figmaProject = declareScaffolds(figmaProject);

_sortPages(figmaProject);

await super.convertFile(
jsonFigma,
outputPath,
Expand Down Expand Up @@ -65,4 +68,29 @@ class FigmaController extends Controller {
}
return tree;
}

/// Sorts project's pages so that Components are processed last
void _sortPages(FigmaProject project) {
// Sort pages so that pages containing components are last
project.pages.sort((a, b) {
if (a.screens.any((screen) => screen.designNode is Component)) {
return 1;
} else if (b.screens.any((screen) => screen.designNode is Component)) {
return -1;
}
return 0;
});

// Within each page, ensure screens that are components go last
project.pages.forEach((page) {
page.screens.sort((a, b) {
if (a.designNode is Component) {
return 1;
} else if (b.designNode is Component) {
return -1;
}
return 0;
});
});
}
}
5 changes: 5 additions & 0 deletions lib/generation/generators/middleware/middleware.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:parabeac_core/generation/generators/pb_generation_manager.dart';
import 'package:parabeac_core/interpret_and_optimize/entities/subclasses/pb_intermediate_node.dart';
import 'package:parabeac_core/interpret_and_optimize/helpers/pb_gen_cache.dart';
import 'package:recase/recase.dart';

abstract class Middleware {
Expand All @@ -19,4 +20,8 @@ abstract class Middleware {

Future<PBIntermediateNode> applyMiddleware(PBIntermediateNode node) =>
Future.value(node);

void addImportToCache(String id, String path) {
PBGenCache().addToCache(id, path);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:parabeac_core/generation/generators/value_objects/generator_adap
import 'package:parabeac_core/generation/generators/value_objects/template_strategy/bloc_state_template_strategy.dart';
import 'package:parabeac_core/interpret_and_optimize/entities/pb_shared_instance.dart';
import 'package:parabeac_core/interpret_and_optimize/entities/subclasses/pb_intermediate_node.dart';
import 'package:parabeac_core/interpret_and_optimize/helpers/pb_symbol_storage.dart';
import 'package:recase/recase.dart';
import '../../pb_generation_manager.dart';
import '../middleware.dart';
Expand All @@ -28,15 +29,12 @@ class BLoCMiddleware extends Middleware {
if (node is PBSharedInstanceIntermediateNode) {
var generalStateName = node.functionCallName
.substring(0, node.functionCallName.lastIndexOf('/'));
var importName = node.functionCallName.snakeCase;
var generalName = generalStateName.snakeCase;
var parentDirectory = generalName + '_bloc';

var globalVariableName = node.name.snakeCase;
managerData.addGlobalVariable(PBVariable(globalVariableName, 'var ', true,
'${generalStateName.pascalCase}Bloc()'));

await managerData.replaceImport(
importName, '${parentDirectory}/${generalName}_bloc.dart');
addImportToCache(node.SYMBOL_ID, getImportPath(node, fileStrategy));

managerData.addToDispose('${globalVariableName}.close()');
node.generator = StringGeneratorAdapter('''
Expand Down Expand Up @@ -127,4 +125,14 @@ class BLoCMiddleware extends Middleware {
abstract class ${pascalName}Event {}
''';
}

String getImportPath(PBSharedInstanceIntermediateNode node, fileStrategy) {
var generalStateName = node.functionCallName
.substring(0, node.functionCallName.lastIndexOf('/'));
var symbolMaster =
PBSymbolStorage().getSharedMasterNodeBySymbolID(node.SYMBOL_ID);
return fileStrategy.GENERATED_PROJECT_PATH +
fileStrategy.RELATIVE_VIEW_PATH +
'${generalStateName.snakeCase}_bloc/${getName(symbolMaster.name).snakeCase}_bloc.dart';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'package:parabeac_core/generation/generators/pb_variable.dart';
import 'package:parabeac_core/generation/generators/value_objects/file_structure_strategy.dart/provider_file_structure_strategy.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/helpers/pb_symbol_storage.dart';
import 'package:recase/recase.dart';
import 'package:parabeac_core/generation/generators/value_objects/generator_adapter.dart';
import 'package:parabeac_core/interpret_and_optimize/entities/subclasses/pb_intermediate_node.dart';
Expand All @@ -27,12 +28,13 @@ class ProviderMiddleware extends Middleware {
node.currentContext.project.genProjectData
.addDependencies(PACKAGE_NAME, PACKAGE_VERSION);
managerData.addImport('package:provider/provider.dart');
watcherName = node.functionCallName.snakeCase;
watcherName = node.name.snakeCase + '_notifier';
var watcher = PBVariable(watcherName, 'final ', true,
'context.watch<${getName(node.functionCallName).pascalCase}>().defaultWidget');
managerData.addMethodVariable(watcher);
await managerData.replaceImport(
watcherName, 'models/${getName(node.name).snakeCase}.dart');

addImportToCache(node.SYMBOL_ID, getImportPath(node, fileStrategy));

node.generator = StringGeneratorAdapter(watcherName);
return node;
}
Expand Down Expand Up @@ -78,4 +80,12 @@ class ProviderMiddleware extends Middleware {
GeneratorContext(sizingContext: SizingValueContext.PointValue)) +
';';
}

String getImportPath(PBSharedInstanceIntermediateNode node, fileStrategy) {
var symbolMaster =
PBSymbolStorage().getSharedMasterNodeBySymbolID(node.SYMBOL_ID);
return fileStrategy.GENERATED_PROJECT_PATH +
fileStrategy.RELATIVE_MODEL_PATH +
'${getName(symbolMaster.name).snakeCase}.dart';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'package:parabeac_core/generation/generators/value_objects/file_structure
import 'package:parabeac_core/generation/generators/value_objects/generator_adapter.dart';
import 'package:parabeac_core/interpret_and_optimize/entities/pb_shared_instance.dart';
import 'package:parabeac_core/interpret_and_optimize/entities/subclasses/pb_intermediate_node.dart';
import 'package:parabeac_core/interpret_and_optimize/helpers/pb_symbol_storage.dart';
import '../../pb_generation_manager.dart';
import '../../pb_variable.dart';
import '../middleware.dart';
Expand Down Expand Up @@ -31,8 +32,9 @@ class RiverpodMiddleware extends Middleware {
'ChangeNotifierProvider((ref) => ${getName(node.functionCallName).pascalCase}())');

managerData.addMethodVariable(watcher);
await managerData.replaceImport(
watcherName, 'models/${watcherName}.dart');

addImportToCache(node.SYMBOL_ID, getImportPath(node, fileStrategy));

node.generator = StringGeneratorAdapter(getConsumer(watcherName));
return node;
}
Expand Down Expand Up @@ -86,4 +88,12 @@ class RiverpodMiddleware extends Middleware {
)
''';
}

String getImportPath(PBSharedInstanceIntermediateNode node, fileStrategy) {
var symbolMaster =
PBSymbolStorage().getSharedMasterNodeBySymbolID(node.SYMBOL_ID);
return fileStrategy.GENERATED_PROJECT_PATH +
fileStrategy.RELATIVE_MODEL_PATH +
'${getName(symbolMaster.name).snakeCase}.dart';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@ class StatefulMiddleware extends Middleware {
as FlutterFileStructureStrategy;

if (node is PBSharedInstanceIntermediateNode) {
managerData.addAllMethodVariable(await _getVariables(node));
node.generator = StringGeneratorAdapter(await _generateInstance(node));
managerData.addGlobalVariable(await _getVariables(node));
node.generator = StringGeneratorAdapter(node.name.snakeCase);
addImportToCache(node.SYMBOL_ID, getImportPath(node, fileStrategy));
return node;
}
var states = <PBIntermediateNode>[node];
var parentDirectory = node.name.snakeCase;
var parentDirectory = getName(node.name).snakeCase;

await node?.auxiliaryData?.stateGraph?.states?.forEach((state) {
states.add(state.variation.node);
Expand All @@ -43,35 +44,28 @@ class StatefulMiddleware extends Middleware {
return node;
}

Future<List<PBVariable>> _getVariables(PBIntermediateNode node) async {
List<PBVariable> variables = [];
var symbolMaster;
if (node is PBSharedInstanceIntermediateNode) {
symbolMaster =
PBSymbolStorage().getSharedMasterNodeBySymbolID(node.SYMBOL_ID);
} else if (node is PBSharedMasterNode) {
symbolMaster = node;
}
var states = <PBIntermediateNode>[symbolMaster];
await symbolMaster?.auxiliaryData?.stateGraph?.states?.forEach((state) {
states.add(state.variation.node);
});
await states.forEach((state) {
var tempNode = state;
var tempVar = PBVariable(
tempNode.name.snakeCase,
'final ',
true,
tempNode.name == symbolMaster.name
? '${tempNode.name.pascalCase}()'
: null,
);
variables.add(tempVar);
});
return variables;
Future<PBVariable> _getVariables(
PBSharedInstanceIntermediateNode node) async {
var symbolMaster =
PBSymbolStorage().getSharedMasterNodeBySymbolID(node.SYMBOL_ID);

var tempVar = PBVariable(
node.name.snakeCase,
'var ',
true,
node.functionCallName == symbolMaster.name
? '${symbolMaster.name.pascalCase}()'
: null,
);

return tempVar;
}

String _generateInstance(PBSharedInstanceIntermediateNode node) {
return node.functionCallName.snakeCase;
String getImportPath(PBSharedInstanceIntermediateNode node, fileStrategy) {
var symbolMaster =
PBSymbolStorage().getSharedMasterNodeBySymbolID(node.SYMBOL_ID);
return fileStrategy.GENERATED_PROJECT_PATH +
fileStrategy.RELATIVE_VIEW_PATH +
'${getName(symbolMaster.name).snakeCase}/${node.functionCallName.snakeCase}.dart';
}
}
53 changes: 12 additions & 41 deletions lib/generation/generators/util/pb_generation_view_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -77,54 +77,25 @@ class PBGenerationViewData {
_globalVariables.addAll(variable);

void addMethodVariable(PBVariable variable) {
if (!_isDataLocked && variable != null) {
if (!_isDataLocked && variable != null && !_contains(variable)) {
_methodVariables.add(variable);
}
}

void addAllMethodVariable(Iterable<PBVariable> variables) {
if (!_isDataLocked && variables != null) {
_methodVariables.addAll(variables);
}
}

Future<String> removeImportThatContains(String pattern) async {
for (var import in _imports) {
if (import is String && import.contains(pattern)) {
_imports.remove(import);
return import;
bool _contains(PBVariable variable) {
var result = false;
_methodVariables.forEach((element) {
if (element.variableName == variable.variableName) {
result = true;
return result;
}
}
return '';
});
return result;
}

Future<void> replaceImport(String oldImport, String newImport) async {
if (!_isDataLocked) {
var oldVersion = await removeImportThatContains(oldImport);
if (oldVersion == '') {
return null;
}
var tempList = oldVersion.split('/');
tempList.removeLast();
tempList.add(newImport);
var tempList2 = tempList;
_imports.add(await _makeImport(tempList2));
}
}

Future<String> _makeImport(List<String> tempList) async {
var tempString = tempList.removeAt(0);
for (var item in tempList) {
if (item == 'view') {
var tempLast = tempList.removeLast();
if (!tempLast.contains('models')) {
tempString += '/${item}';
}
tempString += '/${tempLast}';
break;
}
tempString += '/${item}';
void addAllMethodVariable(Iterable<PBVariable> variables) {
if (!_isDataLocked && variables != null) {
_methodVariables.addAll(variables);
}
return tempString;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,10 @@ abstract class GenerationConfiguration {
await _setMainScreen(
tree.rootNode, '${tree.name.snakeCase}/${fileName}.dart');
}
_commitImports(tree.rootNode, tree.name.snakeCase, fileName);

await _iterateNode(tree.rootNode);

_commitImports(tree.rootNode, tree.name.snakeCase, fileName);

await _generateNode(tree.rootNode, '${tree.name.snakeCase}/${fileName}');
}
await _commitDependencies(pb_project.projectName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class ProviderGenerationConfiguration extends GenerationConfiguration {
runApp(
MultiProvider(
providers: [
$providers
${providers.join(', ')}
],
child: MyApp(),
),
Expand Down
2 changes: 1 addition & 1 deletion lib/input/figma/helper/figma_asset_processor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class FigmaAssetProcessor extends AssetProcessingService {
// Call Figma API to get Image link
return Future(() async {
var response = await APICallService.makeAPICall(
'https://api.figma.com/v1/images/${MainInfo().figmaProjectID}?ids=${uuids.join(',')}',
'https://api.figma.com/v1/images/${MainInfo().figmaProjectID}?ids=${uuids.join(',')}&use_absolute_bounds=true',
MainInfo().figmaKey);

if (response != null &&
Expand Down
4 changes: 2 additions & 2 deletions lib/input/helper/design_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class DesignPage implements DesignNodeFactory {
String id;
String imageURI;
String name;
bool convert;
bool convert = true;
List<DesignScreen> screens = [];

DesignPage({
Expand Down Expand Up @@ -57,7 +57,7 @@ class DesignPage implements DesignNodeFactory {
var page = DesignPage(name: json['name'], id: json['id']);
if (json.containsKey('screens')) {
(json['screens'] as List)?.forEach((value) {
if (value != null) {
if (value != null && (value['convert'] ?? true)) {
page.screens
.add(DesignScreen.fromPBDF(value as Map<String, dynamic>));
}
Expand Down
4 changes: 2 additions & 2 deletions lib/input/helper/design_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import 'package:parabeac_core/design_logic/design_node.dart';
class DesignScreen implements DesignNodeFactory {
String id;
String name;
bool convert;
bool convert = true;
String imageURI;
String type;
DesignNode designNode;
Expand Down Expand Up @@ -48,7 +48,7 @@ class DesignScreen implements DesignNodeFactory {

factory DesignScreen.fromPBDF(Map<String, dynamic> json) {
var screen = DesignScreen(name: json['name'], id: json['id']);
if (json.containsKey('designNode')) {
if (json.containsKey('designNode') && (json['convert'] ?? true)) {
screen.designNode = DesignNode.fromPBDF(json['designNode']);
}
return screen;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class PBStateManagementLinker {
if (node is PBSharedMasterNode) {
var tempSym =
PBSymbolStorage().getSharedInstanceNodeBySymbolID(node.SYMBOL_ID);
tempSym?.isMasterState = true;
tempSym?.forEach((element) => element.isMasterState = true);
}
stateQueue.add(_interpretVariationNode(node).then((processedNode) {
var intermediateState =
Expand Down
Loading

0 comments on commit 469d5d7

Please sign in to comment.