summaryrefslogtreecommitdiff
path: root/platform/darwin/scripts/generate-style-code.js
diff options
context:
space:
mode:
authorMinh Nguyễn <mxn@1ec5.org>2016-08-26 22:05:48 -0700
committerMinh Nguyễn <mxn@1ec5.org>2016-08-26 22:27:55 -0700
commitf4be8260baa1e90e24ea066d0d3b28896cd138ad (patch)
tree8aaf5902637c45e0f49c0e0f7638dbe6129a5624 /platform/darwin/scripts/generate-style-code.js
parent35a1c01166f997deaa386bf30247e7cb1ed33e07 (diff)
downloadqtlocation-mapboxgl-f4be8260baa1e90e24ea066d0d3b28896cd138ad.tar.gz
[ios, macos] Specialize color properties by platform
Duplicate each color-typed property once per platform using conditional compilation macros. Let’s just hope we never have to throw CGColor into the mix.
Diffstat (limited to 'platform/darwin/scripts/generate-style-code.js')
-rw-r--r--platform/darwin/scripts/generate-style-code.js31
1 files changed, 25 insertions, 6 deletions
diff --git a/platform/darwin/scripts/generate-style-code.js b/platform/darwin/scripts/generate-style-code.js
index cd4ab94e36..29040d3c54 100644
--- a/platform/darwin/scripts/generate-style-code.js
+++ b/platform/darwin/scripts/generate-style-code.js
@@ -150,15 +150,15 @@ global.describeValue = function (value, property, layerType) {
throw new Error(`unrecognized color format in default value of ${property.name}`);
}
if (color.r === 0 && color.g === 0 && color.b === 0 && color.a === 0) {
- return '`NSColor.clearColor` or `UIColor.clearColor`';
+ return '`MGLColor.clearColor`';
}
if (color.r === 0 && color.g === 0 && color.b === 0 && color.a === 1) {
- return '`NSColor.blackColor` or `UIColor.blackColor`';
+ return '`MGLColor.blackColor`';
}
if (color.r === 1 && color.g === 1 && color.b === 1 && color.a === 1) {
- return '`NSColor.whiteColor` or `UIColor.whiteColor`';
+ return '`MGLColor.whiteColor`';
}
- return 'an `NSColor` or `UIColor`' + ` object whose RGB value is ${color.r}, ${color.g}, ${color.b} and whose alpha value is ${color.a}`;
+ return 'an `MGLColor`' + ` object whose RGB value is ${color.r}, ${color.g}, ${color.b} and whose alpha value is ${color.a}`;
case 'array':
let units = property.units || '';
if (units) {
@@ -310,8 +310,27 @@ const layers = spec.layer.type.values.map((type) => {
};
});
-for (const layer of layers) {
- fs.writeFileSync(`platform/darwin/src/${prefix}${camelize(layer.type)}${suffix}.h`, layerH(layer));
+function duplicatePlatformDecls(src) {
+ // Look for a documentation comment that contains “MGLColor” and the
+ // subsequent function, method, or property declaration. Try not to match
+ // greedily.
+ return src.replace(/(\/\*\*(?:\*[^\/]|[^*])*?\bMGLColor\b[\s\S]*?\*\/)(\s*.+?;)/g,
+ (match, comment, decl) => {
+ let iosComment = comment.replace(/\bMGLColor\b/g, 'UIColor')
+ // Use the correct indefinite article.
+ .replace(/\b(a)n(\s+`?UIColor)\b/gi, '$1$2');
+ let macosComment = comment.replace(/\bMGLColor\b/g, 'NSColor');
+ return `\
+#if TARGET_OS_IPHONE
+${iosComment}${decl}
+#else
+${macosComment}${decl}
+#endif`;
+ });
+}
+
+for (var layer of layers) {
+ fs.writeFileSync(`platform/darwin/src/${prefix}${camelize(layer.type)}${suffix}.h`, duplicatePlatformDecls(layerH(layer)));
fs.writeFileSync(`platform/darwin/src/${prefix}${camelize(layer.type)}${suffix}.mm`, layerM(layer));
fs.writeFileSync(`platform/darwin/test/${prefix}${camelize(layer.type)}${suffix}Tests.m`, testLayers(layer));
}