Created
June 24, 2013 09:33
-
-
Save groue/5848907 to your computer and use it in GitHub Desktop.
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
#import "GRMustache.h" | |
NSString *templateString = @"{{# repeat(Red) }}<img src=\"img/red.png\">{{/ repeat(Red) }}}"; | |
GRMustacheTemplate *template = [GRMustacheTemplate templateFromString:templateString error:NULL]; | |
id obj = @{ | |
@"Red": @10, | |
@"repeat": [GRMustacheFilter filterWithBlock:^id(NSNumber *number) { | |
NSInteger count = [number integerValue]; | |
return [GRMustache renderingObjectWithBlock:^NSString *(GRMustacheTag *tag, GRMustacheContext *context, BOOL *HTMLSafe, NSError *__autoreleasing *error) { | |
NSString *single = [tag renderContentWithContext:context HTMLSafe:HTMLSafe error:error]; | |
NSMutableString *buffer = [NSMutableString string]; | |
for (NSInteger i=0; i<count; ++i) { | |
[buffer appendString:single]; | |
} | |
return buffer; | |
}]; | |
}] | |
}; | |
// 10 times <img src="img/red.png"> | |
NSString *rendering = [template renderObject:obj error:NULL]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment