summaryrefslogtreecommitdiff
path: root/platform/darwin/scripts/generate-style-code.js
diff options
context:
space:
mode:
Diffstat (limited to 'platform/darwin/scripts/generate-style-code.js')
-rw-r--r--platform/darwin/scripts/generate-style-code.js45
1 files changed, 30 insertions, 15 deletions
diff --git a/platform/darwin/scripts/generate-style-code.js b/platform/darwin/scripts/generate-style-code.js
index de0e7d69a0..9e79d0a321 100644
--- a/platform/darwin/scripts/generate-style-code.js
+++ b/platform/darwin/scripts/generate-style-code.js
@@ -12,22 +12,33 @@ const suffix = 'StyleLayer';
// Rename properties and keep `original` for use with setters and getters
_.forOwn(cocoaConventions, function (properties, kind) {
_.forOwn(properties, function (newName, oldName) {
- spec[kind][newName] = spec[kind][oldName];
- spec[kind][newName].original = oldName;
+ let property = spec[kind][oldName];
+ if (newName.startsWith('is-')) {
+ property.getter = newName;
+ newName = newName.substr(3);
+ }
+ if (newName !== oldName) {
+ property.original = oldName;
+ }
delete spec[kind][oldName];
+ spec[kind][newName] = property;
// Update requirements in other properties.
let updateRequirements = function (property, name) {
let requires = property.requires || [];
for (let i = 0; i < requires.length; i++) {
- if (requires[i] in cocoaConventions[kind]) {
- property.requires[i] = cocoaConventions[kind][requires[i]];
+ if (requires[i] === oldName) {
+ property.requires[i] = newName;
+ }
+ if (typeof requires[i] !== 'string') {
+ let prop = name;
+ _.forOwn(requires[i], function (values, name, require) {
+ if (name === oldName) {
+ require[newName] = values;
+ delete require[name];
+ }
+ });
}
- _.forOwn(requires[i], function (values, name, require) {
- if (require in cocoaConventions[kind]) {
- require[cocoaConventions[kind][name]] = values;
- }
- });
}
};
_.forOwn(spec[kind.replace(/^layout_/, 'paint_')], updateRequirements);
@@ -51,6 +62,10 @@ global.objCName = function (property) {
return camelizeWithLeadingLowercase(property.name);
}
+global.objCGetter = function (property) {
+ return camelizeWithLeadingLowercase(property.getter || property.name);
+}
+
global.objCType = function (layerType, propertyName) {
return `${prefix}${camelize(propertyName)}`;
}
@@ -149,7 +164,7 @@ global.propertyDoc = function (propertyName, property, layerType) {
return doc.replace(/(p)ixel/gi, '$1oint').replace(/(\d)px\b/g, '$1pt');
};
-global.propertyReqs = function (property, layoutPropertiesByName, type) {
+global.propertyReqs = function (property, propertiesByName, type) {
return 'This property is only applied to the style if ' + property.requires.map(function (req) {
if (typeof req === 'string') {
return '`' + camelizeWithLeadingLowercase(req) + '` is non-`nil`';
@@ -157,7 +172,7 @@ global.propertyReqs = function (property, layoutPropertiesByName, type) {
return '`' + camelizeWithLeadingLowercase(req['!']) + '` is set to `nil`';
} else {
let name = Object.keys(req)[0];
- return '`' + camelizeWithLeadingLowercase(name) + '` is set to an `MGLStyleValue` object containing ' + describeValue(req[name], layoutPropertiesByName[name], type);
+ return '`' + camelizeWithLeadingLowercase(name) + '` is set to an `MGLStyleValue` object containing ' + describeValue(req[name], propertiesByName[name], type);
}
}).join(', and ') + '. Otherwise, it is ignored.';
};
@@ -318,11 +333,11 @@ global.setSourceLayer = function() {
}
global.mbglType = function(property) {
- let mbglType = camelize(property.name) + 'Type';
- if (/-translate-anchor$/.test(property.name)) {
+ let mbglType = camelize(originalPropertyName(property)) + 'Type';
+ if (/-translate-anchor$/.test(originalPropertyName(property))) {
mbglType = 'TranslateAnchorType';
}
- if (/-(rotation|pitch)-alignment$/.test(property.name)) {
+ if (/-(rotation|pitch)-alignment$/.test(originalPropertyName(property))) {
mbglType = 'AlignmentType';
}
return mbglType;
@@ -330,7 +345,7 @@ global.mbglType = function(property) {
const layerH = ejs.compile(fs.readFileSync('platform/darwin/src/MGLStyleLayer.h.ejs', 'utf8'), { strict: true });
const layerM = ejs.compile(fs.readFileSync('platform/darwin/src/MGLStyleLayer.mm.ejs', 'utf8'), { strict: true});
-const testLayers = ejs.compile(fs.readFileSync('platform/darwin/src/MGLRuntimeStylingTests.m.ejs', 'utf8'), { strict: true});
+const testLayers = ejs.compile(fs.readFileSync('platform/darwin/test/MGLStyleLayerTests.m.ejs', 'utf8'), { strict: true});
const categoryH = ejs.compile(fs.readFileSync('platform/darwin/src/NSValue+MGLStyleEnumAttributeAdditions.h.ejs', 'utf8'), { strict: true});
const categoryM = ejs.compile(fs.readFileSync('platform/darwin/src/NSValue+MGLStyleEnumAttributeAdditions.mm.ejs', 'utf8'), { strict: true});