Permalink
Browse files

Filters can return filters

  • Loading branch information...
groue committed Sep 29, 2012
1 parent e0d442a commit b87574f94a7b13dec0d97dead7c47aea01c0bd87
@@ -457,6 +457,7 @@ - (GRMustacheExpression *)parseExpression:(NSString *)string invalid:(BOOL *)out
// stateIdentifierDone -> canFilter;'(';++sm_parenLevel -> stateInitial
// stateFilterDone -> ' ' -> stateFilterDone
// stateFilterDone -> '.' -> stateWaitingForIdentifier
+ // stateFilterDone -> '(';++sm_parenLevel -> stateInitial
// stateFilterDone -> sm_parenLevel==0;EOF; -> stateValid
// stateFilterDone -> sm_parenLevel>0;')';--sm_parenLevel -> stateFilterDone
@@ -720,7 +721,10 @@ - (GRMustacheExpression *)parseExpression:(NSString *)string invalid:(BOOL *)out
break;
case '(':
- state = stateError;
+ NSAssert(currentExpression, @"WTF");
+ state = stateInitial;
+ [filterExpressionStack addObject:currentExpression];
+ currentExpression = nil;
break;
case ')':
@@ -204,4 +204,18 @@ - (void)testFilterNameSpace
STAssertEqualObjects(rendering, @"1", nil);
}
+- (void)testFiltersCanReturnFilters
+{
+ id filter = [GRMustacheFilter filterWithBlock:^id(id value1) {
+ return [GRMustacheFilter filterWithBlock:^id(id value2) {
+ return [NSString stringWithFormat:@"%@%@", value1, value2];
+ }];
+ }];
+
+ id data = @{ @"prefix": @"prefix", @"value": @"value" };
+ id filters = @{ @"f": filter };
+ NSString *rendering = [GRMustacheTemplate renderObject:data withFilters:filters fromString:@"{{f(prefix)(value)}}" error:NULL];
+ STAssertEqualObjects(rendering, @"prefixvalue", @"");
+}
+
@end
@@ -322,11 +322,4 @@ - (void)testParsingErrorReportsImplicitIteratorAsFilter
STAssertEquals(error.code, (NSInteger)GRMustacheErrorCodeParseError, nil);
}
-- (void)testParsingErrorReportsFilteredValueAsFilter
-{
- NSError *error;
- STAssertNil([GRMustacheTemplate templateFromString:@"{{f(a)(b)}}" error:&error], nil);
- STAssertEquals(error.code, (NSInteger)GRMustacheErrorCodeParseError, nil);
-}
-
@end

0 comments on commit b87574f

Please sign in to comment.