Documentation of filters: https://github.com/groue/GRMustache/blob/master/Guides/filters.md
Created
September 29, 2012 11:05
-
-
Save groue/3803707 to your computer and use it in GitHub Desktop.
GRMustache: variadic filters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{{#object1}} | |
{{ dateFormat(date, format) }} | |
{{/object1}} | |
{{#object2}} | |
{{ dateFormat(date) }} | |
{{/object2}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
id filters = @{ | |
@"dateFormat": [GRMustacheFilter variadicFilterWithBlock:^id(NSArray *arguments) { | |
// first argument is date | |
NSDate *date = [arguments objectAtIndex:0]; | |
// second (optional) argument is format | |
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; | |
if (arguments.count > 1) | |
dateFormatter.format = [arguments objectAtIndex:1]; | |
else | |
dateFormatter.format = @"yyyy-MM-dd"; | |
// compute the result | |
return [dateFormatter stringFromDate:date]; | |
}] | |
}; | |
id data = @{ | |
@"object1": @{ | |
@"format": @"yyyy-MM-dd 'at' HH:mm", | |
@"date": [NSDate date] | |
}, | |
@"object2": @{ | |
@"date": [NSDate date] | |
} | |
}; | |
NSString *rendering = [GRMustacheTemplate renderObject:data | |
withFilters:filters | |
fromResource:@"base" | |
bundle:nil | |
error:NULL]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2012-10-20 at 15:05 | |
2012-10-20 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment