summaryrefslogtreecommitdiff
path: root/platform/darwin/scripts/generate-style-code.js
diff options
context:
space:
mode:
authorMinh Nguyễn <mxn@1ec5.org>2016-12-16 08:09:42 -0800
committerGitHub <noreply@github.com>2016-12-16 08:09:42 -0800
commit3f26e88c49d3afeb3754a877b8473deb4bf2cded (patch)
treebc1dc3211623211302201d07219c46fdaf055487 /platform/darwin/scripts/generate-style-code.js
parentb8466946e5eac5a4359206c19fe6e659ae9cf6c1 (diff)
downloadqtlocation-mapboxgl-3f26e88c49d3afeb3754a877b8473deb4bf2cded.tar.gz
Use appropriate part of speech for properties (#7457)
* [ios, macos] Use appropriate part of speech for properties Fixed overridden property references in requirements lists. Boolean-typed properties can now have getters beginning with “is”. Renamed a number of layout properties according to the following rules: Boolean-typed properties should include a verb; other properties must be noun phrases; all properties must be grammatical. * [ios, macos] Added style spec names as unavailable aliases Renamed properties now have aliases based on their style specification names, marked unavailable, for wayfinding purposes. * [ios, macos] Fixed autosynthesis warnings * [ios, macos] Moved style layer test template to test folder * [ios, macos] Customized iconOptional getter * [ios, macos] Avoid autosynthesis of aliases * [ios, macos] Test that property names are grammatical Run property getter names through a basic battery of tests to see if they’re grammatical. Most part-of-speech tagging tests are guarded by a compile-time flag, off by default, because NSLinguisticTagger does a poor job of telling nouns from verbs, and we’ve intentionally kept many words in property names that could be read as either verbs or nouns (like “transform” or “scale”).
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});