Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
[ios, macos] Omit unwieldy units from struct descriptions
Browse files Browse the repository at this point in the history
  • Loading branch information
1ec5 committed Jan 6, 2018
1 parent 41c7b4d commit 5374da2
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 17 deletions.
26 changes: 19 additions & 7 deletions platform/darwin/scripts/generate-style-code.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ _.forOwn(cocoaConventions, function (properties, kind) {
// Update cross-references to this property in other properties'
// documentation and requirements.
let renameCrossReferences = function (property, name) {
property.doc = property.doc.replace(new RegExp('`' + oldName + '`', 'g'), '`' + newName + '`');
let oldNameRe = new RegExp('`' + oldName + '`', 'g');
property.doc = property.doc.replace(oldNameRe, '`' + newName + '`');
if (property.units) {
property.units = property.units.replace(oldNameRe, '`' + newName + '`');
}
let requires = property.requires || [];
for (let i = 0; i < requires.length; i++) {
if (requires[i] === oldName) {
Expand Down Expand Up @@ -265,10 +269,7 @@ global.propertyDoc = function (propertyName, property, layerType, kind) {
});
// Format references to units.
if ('units' in property) {
if (!property.units.match(/s$/)) {
property.units += 's';
}
doc += `\n\nThis property is measured in ${property.units}.`;
doc += `\n\nThis property is measured in ${describeUnit(property.units, property, layerType)}.`;
}
doc = doc.replace(/(p)ixel/gi, '$1oint').replace(/(\d)px\b/g, '$1pt');
if (kind !== 'enum') {
Expand Down Expand Up @@ -344,6 +345,13 @@ global.parseColor = function (str) {
};
};

global.describeUnit = function (unit, property, layerType) {
if (!unit.match(/s$|s /)) {
unit += 's';
}
return unit.replace(/pixel/, 'point');
};

global.describeValue = function (value, property, layerType) {
switch (property.type) {
case 'boolean':
Expand Down Expand Up @@ -389,9 +397,13 @@ global.describeValue = function (value, property, layerType) {
}
return 'a `UIColor`' + ` object whose RGB value is ${color.r}, ${color.g}, ${color.b} and whose alpha value is ${color.a}`;
case 'array':
let units = property.units || '';
let units = property.units;
if (units) {
units = ` ${units}`.replace(/pixel/, 'point');
units = ` ${describeUnit(units, property, layerType)}`;
// Omit unwieldy phrases that occur as units.
if (units.split(' ').length > 2) {
units = '';
}
}
switch (arrayType(property)) {
case 'padding':
Expand Down
16 changes: 6 additions & 10 deletions platform/darwin/src/MGLSymbolStyleLayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -479,13 +479,11 @@ MGL_EXPORT
/**
Offset distance of icon from its anchor.
This property is measured in points multiplied by the value of "icon-size"s.
This property is measured in points multiplied by the value of "icon-size".
The default value of this property is an `MGLStyleValue` object containing an
`NSValue` object containing a `CGVector` struct set to 0 points multiplied by
the value of "icon-size"s rightward and 0 points multiplied by the value of
"icon-size"s downward. Set this property to `nil` to reset it to the default
value.
`NSValue` object containing a `CGVector` struct set to 0 rightward and 0
downward. Set this property to `nil` to reset it to the default value.
This property is only applied to the style if `iconImageName` is non-`nil`.
Otherwise, it is ignored.
Expand All @@ -511,13 +509,11 @@ MGL_EXPORT
/**
Offset distance of icon from its anchor.
This property is measured in points multiplied by the value of "icon-size"s.
This property is measured in points multiplied by the value of "icon-size".
The default value of this property is an `MGLStyleValue` object containing an
`NSValue` object containing a `CGVector` struct set to 0 points multiplied by
the value of "icon-size"s rightward and 0 points multiplied by the value of
"icon-size"s upward. Set this property to `nil` to reset it to the default
value.
`NSValue` object containing a `CGVector` struct set to 0 rightward and 0
upward. Set this property to `nil` to reset it to the default value.
This property is only applied to the style if `iconImageName` is non-`nil`.
Otherwise, it is ignored.
Expand Down

0 comments on commit 5374da2

Please sign in to comment.