Skip to content

Instantly share code, notes, and snippets.

@groue
Created June 24, 2013 09:33
Show Gist options
  • Save groue/5848907 to your computer and use it in GitHub Desktop.
Save groue/5848907 to your computer and use it in GitHub Desktop.
#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