A simple template renderer in Objective-C. Fill templates with object properties, methods, and key paths.
Given
@interface MYObject : NSObject
@property (nonatomic, copy) NSString *color;
@property (nonatomic, copy) NSNumber *favoriteNumber;
@property (nonatomic, assign) NSInteger leastFavoriteNumber;
@end
...
obj = [[MYObject alloc] init];
obj.color = @"red";
obj.favoriteNumber = @47;
obj.leastFavoriteNumber = -12;
and
NSString *templateString = @"My favorite color is {{ color }} and my favorite number is {{ favoriteNumber }} and my least favorite number is {{ leastFavoriteNumber }}!";
template = [[FFCTemplate alloc] initWithTemplate:templateString];
template.valueSource = obj;
NSString *result = [template render];
//@"My favorite color is red and my favorite number is 47 and my least favorite number is -12!"
To run the example project, clone the repo, and run pod install
from the Example directory first.
FFCTemplate is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod "FFCTemplate"
Fabian Canas
FFCTemplate is available under the MIT license. See the LICENSE file for more info.