Skip to content

Commit

Permalink
Look for helper selector after KVO miss
Browse files Browse the repository at this point in the history
  • Loading branch information
groue committed Feb 17, 2012
1 parent 745be05 commit a9bc38f
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions Classes/GRMustacheContext.m
Expand Up @@ -114,22 +114,11 @@ - (id)valueForKey:(NSString *)key {
}

- (id)valueForKey:(NSString *)key scoped:(BOOL)scoped {
// value by selector

SEL renderingSelector = NSSelectorFromString([NSString stringWithFormat:@"%@Section:withContext:", key]);
if ([object respondsToSelector:renderingSelector]) {
// Avoid the "render" key to be triggered by GRMustacheHelper instances,
// who implement the renderSection:withContext: selector.
if (![object conformsToProtocol:@protocol(GRMustacheHelper)] || ![@"render" isEqualToString:key]) {
return [GRMustacheSelectorHelper helperWithObject:object selector:renderingSelector];
}
}

// value by KVC

id value = nil;

if (object) {
// value by KVC

@try {
if (preventingNSUndefinedKeyExceptionAttack) {
value = [GRMustacheNSUndefinedKeyExceptionGuard valueForKey:key inObject:object];
Expand All @@ -146,6 +135,19 @@ - (id)valueForKey:(NSString *)key scoped:(BOOL)scoped {
[exception raise];
}
}

if (value == nil) {
// value by selector

SEL renderingSelector = NSSelectorFromString([key stringByAppendingString:@"Section:withContext:"]);
if ([object respondsToSelector:renderingSelector]) {
// Avoid the "render" key to be triggered by GRMustacheHelper instances,
// who implement the renderSection:withContext: selector.
if (![object conformsToProtocol:@protocol(GRMustacheHelper)] || ![@"render" isEqualToString:key]) {
return [GRMustacheSelectorHelper helperWithObject:object selector:renderingSelector];
}
}
}
}

// value interpretation
Expand Down

0 comments on commit a9bc38f

Please sign in to comment.