summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMinh Nguyễn <mxn@1ec5.org>2016-08-18 10:38:44 -0700
committerMinh Nguyễn <mxn@1ec5.org>2016-08-19 14:20:27 -0700
commit98787b37bfd334a4f921de46ac3d2320a3c8c49a (patch)
tree807ae6ea4a4c2fc0592588c9562e9de51c4a3580
parentcb32f604446df4fafc1843c5664b942dcde4b50e (diff)
downloadqtlocation-mapboxgl-98787b37bfd334a4f921de46ac3d2320a3c8c49a.tar.gz
[ios, macos] Refactored array type conversion
Key the array subtype on the last part of the property name. Don’t assume one of the unaccounted-for properties is an offset.
-rw-r--r--platform/darwin/scripts/generate-style-code.js53
1 files changed, 33 insertions, 20 deletions
diff --git a/platform/darwin/scripts/generate-style-code.js b/platform/darwin/scripts/generate-style-code.js
index 4597eeda24..08b358b798 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}`);
}
}