Permalink
Browse files

Look for helper selector after KVO miss

  • Loading branch information...
1 parent 745be05 commit a9bc38fed3ad599dd3401e0f6d795f58d49b1f6d @groue committed Feb 17, 2012
Showing with 15 additions and 13 deletions.
  1. +15 −13 Classes/GRMustacheContext.m
@@ -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];
@@ -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

0 comments on commit a9bc38f

Please sign in to comment.