From 98787b37bfd334a4f921de46ac3d2320a3c8c49a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Minh=20Nguye=CC=82=CC=83n?= Date: Thu, 18 Aug 2016 10:38:44 -0700 Subject: [PATCH] [ios, macos] Refactored array type conversion MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Key the array subtype on the last part of the property name. Don’t assume one of the unaccounted-for properties is an offset. --- .../darwin/scripts/generate-style-code.js | 53 ++++++++++++------- 1 file changed, 33 insertions(+), 20 deletions(-) diff --git a/platform/darwin/scripts/generate-style-code.js b/platform/darwin/scripts/generate-style-code.js index 4597eeda2..08b358b79 100644 --- a/platform/darwin/scripts/generate-style-code.js +++ b/platform/darwin/scripts/generate-style-code.js @@ -21,6 +21,10 @@ global.camelizeWithLeadingLowercase = function (str) { global.objCName = function (property) { return camelizeWithLeadingLowercase(property.name); } +global.arrayType = function (property) { + return property.type === 'array' ? property.name.split('-').pop() : false; +}; + global.testImplementation = function (property, layerType) { switch (property.type) { case 'boolean': @@ -62,28 +66,34 @@ global.testGetterImplementation = function (property, layerType) { } global.testGetterArrayImplementation = function (property) { - switch (property.name) { - case 'icon-text-fit-padding': - return `XCTAssertEqualObjects(gLayer.${objCName(property)}, MGLRuntimeStylingHelper.testPadding);`; - case 'line-dasharray': + switch (arrayType(property)) { + case 'dasharray': return `XCTAssertEqualObjects(gLayer.${objCName(property)}, MGLRuntimeStylingHelper.testDashArray);`; - case 'text-font': + case 'font': return `XCTAssertEqualObjects(gLayer.${objCName(property)}, MGLRuntimeStylingHelper.testFont);`; - default: + case 'padding': + return `XCTAssertEqualObjects(gLayer.${objCName(property)}, MGLRuntimeStylingHelper.testPadding);`; + case 'offset': + case 'translate': return `XCTAssertEqualObjects(gLayer.${objCName(property)}, MGLRuntimeStylingHelper.testOffset);`; // Default offset (dx, dy) + default: + throw new Error(`unknown array type for ${property.name}`); } }; global.testArrayImplementation = function (property) { - switch (property.name) { - case 'icon-text-fit-padding': - return `layer.${objCName(property)} = MGLRuntimeStylingHelper.testPadding;`; - case 'line-dasharray': + switch (arrayType(property)) { + case 'dasharray': return `layer.${objCName(property)} = MGLRuntimeStylingHelper.testDashArray;`; - case 'text-font': + case 'font': return `layer.${objCName(property)} = MGLRuntimeStylingHelper.testFont;`; - default: + case 'padding': + return `layer.${objCName(property)} = MGLRuntimeStylingHelper.testPadding;`; + case 'offset': + case 'translate': return `layer.${objCName(property)} = MGLRuntimeStylingHelper.testOffset;`; // Default offset (dx, dy) + default: + throw new Error(`unknown array type for ${property.name}`); } }; @@ -264,15 +274,18 @@ global.arrayGetterImplementation = function(property) { } global.convertedType = function(property) { - switch (property.name) { - case 'icon-text-fit-padding': - return "padding"; - case 'line-dasharray': - return "numberArray"; - case 'text-font': - return "stringArray"; + switch (arrayType(property)) { + case 'dasharray': + return 'numberArray'; + case 'font': + return 'stringArray'; + case 'padding': + return 'padding'; + case 'offset': + case 'translate': + return 'offset'; default: - return "offset"; + throw new Error(`unknown array type for ${property.name}`); } }