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

Commit

Permalink
[ios, macos] Update format expression documentation.
Browse files Browse the repository at this point in the history
  • Loading branch information
fabian-guerra committed Mar 14, 2019
1 parent c9a363f commit e6faefe
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 7 deletions.
2 changes: 1 addition & 1 deletion platform/darwin/docs/guides/For Style Authors.md.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ In style specification | Method, function, or predicate type | Format string syn
`zoom` | `NSExpression.zoomLevelVariableExpression` | `$zoomLevel`
`heatmap-density` | `NSExpression.heatmapDensityVariableExpression` | `$heatmapDensity`
`line-progress` | `NSExpression.lineProgressVariableExpression` | `$lineProgress`
`format` | `mgl_attributed:` | `mgl_attributed({x, y, z})`
`format` | `+[NSExpression mgl_expressionForAttributedExpressions:]` or `mgl_attributed:` | `mgl_attributed({x, y, z})`
For operators that have no corresponding `NSExpression` symbol, use the
`MGL_FUNCTION()` format string syntax.
Expand Down
5 changes: 3 additions & 2 deletions platform/darwin/docs/guides/Predicates and Expressions.md
Original file line number Diff line number Diff line change
Expand Up @@ -543,10 +543,11 @@ operator in the Mapbox Style Specification.
<dd><code>mgl_attributed({x, y, z})</code></dd>
</dl>

Returns formatted text containing annotations for use in mixed-format `text-field` entries.
Concatenates and returns the array of `MGLAttributedExpression` objects, for use
with the `MGLSymbolStyleLayer.text` property.

This function corresponds to the
[`mgl_attributed`](https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-types-format)
[`format`](https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-types-format)
operator in the Mapbox Style Specification.

### `MGL_LET`
Expand Down
4 changes: 2 additions & 2 deletions platform/darwin/src/MGLAttributedExpression.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ FOUNDATION_EXTERN MGL_EXPORT MGLAttributedExpressionKey const MGLFontNamesAttrib
FOUNDATION_EXTERN MGL_EXPORT MGLAttributedExpressionKey const MGLFontSizeAttribute;

/**
An `NSExpression` that has associated text formatting attibutes (such as font size or
font names).
An `MGLAttributedExpression` object associates text formatting attibutes (such as font size or
font names) to an `NSExpression`.
*/
MGL_EXPORT
@interface MGLAttributedExpression : NSObject
Expand Down
8 changes: 8 additions & 0 deletions platform/darwin/src/NSExpression+MGLAdditions.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,14 @@ FOUNDATION_EXTERN MGL_EXPORT const MGLExpressionInterpolationMode MGLExpressionI
*/
+ (instancetype)mgl_expressionForMatchingExpression:(nonnull NSExpression *)inputExpression inDictionary:(nonnull NSDictionary<NSExpression *, NSExpression *> *)matchedExpressions defaultExpression:(nonnull NSExpression *)defaultExpression NS_SWIFT_NAME(init(forMGLMatchingKey:in:default:));

/**
Returns an attributed function expression specifying an `MGLAttributedExpression` constant
expression array.
@param attributedExpressions The `MGLAttributedExpression` constant expression array.
*/
+ (instancetype)mgl_expressionForAttributedExpressions:(nonnull NSArray<NSExpression *> *)attributedExpressions NS_SWIFT_NAME(init(forAttributedExpressions:));

#pragma mark Concatenating String Expressions

/**
Expand Down
4 changes: 4 additions & 0 deletions platform/darwin/src/NSExpression+MGLAdditions.mm
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,10 @@ + (instancetype)mgl_expressionForMatchingExpression:(nonnull NSExpression *)inpu
arguments:optionsArray];
}

+ (instancetype)mgl_expressionForAttributedExpressions:(nonnull NSArray<NSExpression *> *)attributedExpressions {
return [NSExpression expressionWithFormat:@"mgl_attributed(%@)", attributedExpressions];
}

- (instancetype)mgl_expressionByAppendingExpression:(nonnull NSExpression *)expression {
NSExpression *subexpression = [NSExpression expressionForAggregate:@[self, expression]];
return [NSExpression expressionForFunction:@"mgl_join:" arguments:@[subexpression]];
Expand Down
21 changes: 21 additions & 0 deletions platform/darwin/test/MGLExpressionTests.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1046,6 +1046,27 @@ - (void)testFormatExpressionObject {
XCTAssertEqualObjects(expression.mgl_jsonExpressionObject, jsonExpression);
XCTAssertEqualObjects([NSExpression expressionWithMGLJSONObject:jsonExpression], expression);
}
{
MGLAttributedExpression *attribute1 = [MGLAttributedExpression attributedExpression:[NSExpression expressionForConstantValue:@"foo"]
fontNames:nil
fontSize:@(1.2)];
MGLAttributedExpression *attribute2 = [MGLAttributedExpression attributedExpression:[NSExpression expressionForConstantValue:@"biz"]
fontNames:nil
fontSize:@(1.0)];
MGLAttributedExpression *attribute3 = [MGLAttributedExpression attributedExpression:[NSExpression expressionForConstantValue:@"bar"]
fontNames:nil
fontSize:@(0.8)];
MGLAttributedExpression *attribute4 = [MGLAttributedExpression attributedExpression:[NSExpression expressionForConstantValue:@"\n"]
fontNames:@[]
fontSize:nil];
NSExpression *expression = [NSExpression mgl_expressionForAttributedExpressions:@[MGLConstantExpression(attribute1),
MGLConstantExpression(attribute4),
MGLConstantExpression(attribute2),
MGLConstantExpression(attribute3)]];
NSArray *jsonExpression = @[@"format", @"foo", @{@"font-scale": @1.2}, @"\n", @{}, @"biz", @{@"font-scale": @1.0}, @"bar", @{@"font-scale": @0.8}];
XCTAssertEqualObjects(expression.mgl_jsonExpressionObject, jsonExpression);
XCTAssertEqualObjects([NSExpression expressionWithMGLJSONObject:jsonExpression], expression);
}
}

- (void)testGenericExpressionObject {
Expand Down
2 changes: 1 addition & 1 deletion platform/ios/docs/guides/For Style Authors.md
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ In style specification | Method, function, or predicate type | Format string syn
`zoom` | `NSExpression.zoomLevelVariableExpression` | `$zoomLevel`
`heatmap-density` | `NSExpression.heatmapDensityVariableExpression` | `$heatmapDensity`
`line-progress` | `NSExpression.lineProgressVariableExpression` | `$lineProgress`
`format` | `mgl_attributed:` | `mgl_attributed({x, y, z})`
`format` | `+[NSExpression mgl_expressionForAttributedExpressions:]` or `mgl_attributed:` | `mgl_attributed({x, y, z})`

For operators that have no corresponding `NSExpression` symbol, use the
`MGL_FUNCTION()` format string syntax.
Expand Down
2 changes: 1 addition & 1 deletion platform/macos/docs/guides/For Style Authors.md
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ In style specification | Method, function, or predicate type | Format string syn
`zoom` | `NSExpression.zoomLevelVariableExpression` | `$zoomLevel`
`heatmap-density` | `NSExpression.heatmapDensityVariableExpression` | `$heatmapDensity`
`line-progress` | `NSExpression.lineProgressVariableExpression` | `$lineProgress`
`format` | `mgl_attributed:` | `mgl_attributed({x, y, z})`
`format` | `+[NSExpression mgl_expressionForAttributedExpressions:]` or `mgl_attributed:` | `mgl_attributed({x, y, z})`

For operators that have no corresponding `NSExpression` symbol, use the
`MGL_FUNCTION()` format string syntax.
Expand Down

0 comments on commit e6faefe

Please sign in to comment.