Skip to content

Commit

Permalink
improved compliance to principle of least surprise
Browse files Browse the repository at this point in the history
  • Loading branch information
groue committed Dec 14, 2010
1 parent 4a0f55f commit f0af976
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
17 changes: 7 additions & 10 deletions Classes/GRMustacheContext.m
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ @interface GRMustacheContext()
@property (nonatomic, retain) GRMustacheContext *parent;
- (id)initWithObject:(id)object parent:(GRMustacheContext *)parent;
- (BOOL)shouldConsiderObjectValue:(id)value forKey:(NSString *)key asBoolean:(CFBooleanRef *)outBooleanRef;
- (id)valueForKeyComponent:(NSString *)key foundInContext:(GRMustacheContext **)outContext;
- (id)valueForKeyComponent:(NSString *)key;
@end


Expand Down Expand Up @@ -153,7 +153,7 @@ - (id)valueForKey:(NSString *)key {
}
return parent.object;
}
return [self valueForKeyComponent:key foundInContext:nil];
return [self valueForKeyComponent:key];
}

// slow path for multiple components
Expand All @@ -173,12 +173,12 @@ - (id)valueForKey:(NSString *)key {
}
continue;
}
GRMustacheContext *valueContext = nil;
id value = [context valueForKeyComponent:component foundInContext:&valueContext];
id value = [context valueForKeyComponent:component];
if (value == nil) {
return nil;
}
context = [valueContext contextByAddingObject:value];
// further contexts are not in the context stack
context = [GRMustacheContext contextWithObject:value];
}

return context.object;
Expand All @@ -190,7 +190,7 @@ - (void)dealloc {
[super dealloc];
}

- (id)valueForKeyComponent:(NSString *)key foundInContext:(GRMustacheContext **)outContext {
- (id)valueForKeyComponent:(NSString *)key {
// value by selector

SEL renderingSelector = NSSelectorFromString([NSString stringWithFormat:@"%@Section:withContext:", key]);
Expand Down Expand Up @@ -218,9 +218,6 @@ - (id)valueForKeyComponent:(NSString *)key foundInContext:(GRMustacheContext **)
// value interpretation

if (value != nil) {
if (outContext != NULL) {
*outContext = self;
}
CFBooleanRef booleanRef;
if ([self shouldConsiderObjectValue:value forKey:key asBoolean:&booleanRef]) {
return (id)booleanRef;
Expand All @@ -231,7 +228,7 @@ - (id)valueForKeyComponent:(NSString *)key foundInContext:(GRMustacheContext **)
// parent value

if (parent == nil) { return nil; }
return [parent valueForKeyComponent:key foundInContext:outContext];
return [parent valueForKeyComponent:key];
}

- (BOOL)shouldConsiderObjectValue:(id)value forKey:(NSString *)key asBoolean:(CFBooleanRef *)outBooleanRef {
Expand Down
2 changes: 1 addition & 1 deletion Tests/Mustache-Spec

0 comments on commit f0af976

Please sign in to comment.