Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Restored GRMustacheTemplateDelegate tests

  • Loading branch information...
commit 36981ef139d34dca8804f75410e02416dda635fa 1 parent af74975
@groue authored
View
4 src/classes/GRMustacheExpression_private.h
@@ -24,6 +24,8 @@
#import "GRMustacheAvailabilityMacros_private.h"
@class GRMustacheContext;
+@class GRMustacheTemplate;
+@class GRMustacheInvocation;
/**
* TODO
@@ -34,6 +36,6 @@
/**
* TODO
*/
-- (id)valueForContext:(GRMustacheContext *)context filterContext:(GRMustacheContext *)filterContext;
+- (id)valueForContext:(GRMustacheContext *)context filterContext:(GRMustacheContext *)filterContext delegatingTemplate:(GRMustacheTemplate *)delegatingTemplate delegates:(NSArray *)delegates invocation:(GRMustacheInvocation **)outInvocation;
@end
View
26 src/classes/GRMustacheFilteredExpression.m
@@ -22,6 +22,8 @@
#import "GRMustacheFilteredExpression_private.h"
#import "GRMustacheFilter.h"
+#import "GRMustacheTemplate_private.h"
+#import "GRMustacheInvocation_private.h"
@interface GRMustacheFilteredExpression()
@property (nonatomic, retain) id<GRMustacheExpression> filterExpression;
@@ -69,10 +71,22 @@ - (BOOL)isEqual:(id<GRMustacheExpression>)expression
#pragma mark GRMustacheExpression
-- (id)valueForContext:(GRMustacheContext *)context filterContext:(GRMustacheContext *)filterContext
+- (id)valueForContext:(GRMustacheContext *)context filterContext:(GRMustacheContext *)filterContext delegatingTemplate:(GRMustacheTemplate *)delegatingTemplate delegates:(NSArray *)delegates invocation:(GRMustacheInvocation **)outInvocation
{
- id parameter = [_parameterExpression valueForContext:context filterContext:filterContext];
- id<GRMustacheFilter> filter = [_filterExpression valueForContext:filterContext filterContext:nil];
+ id parameter = nil;
+ GRMustacheInvocation *invocation = nil;
+ if (delegatingTemplate) {
+ parameter = [_parameterExpression valueForContext:context filterContext:filterContext delegatingTemplate:delegatingTemplate delegates:delegates invocation:&invocation];
+ if (invocation) {
+ [delegatingTemplate invokeDelegates:delegates willInterpretReturnValueOfInvocation:invocation as:GRMustacheInterpretationFilterArgument];
+ parameter = invocation.returnValue;
+ [delegatingTemplate invokeDelegates:delegates didInterpretReturnValueOfInvocation:invocation as:GRMustacheInterpretationFilterArgument];
+ }
+ } else {
+ parameter = [_parameterExpression valueForContext:context filterContext:filterContext delegatingTemplate:delegatingTemplate delegates:delegates invocation:NULL];
+ }
+
+ id<GRMustacheFilter> filter = [_filterExpression valueForContext:filterContext filterContext:nil delegatingTemplate:nil delegates:nil invocation:NULL];
if (filter == nil) {
[NSException raise:GRMustacheFilterException format:@"Missing filter"];
@@ -82,6 +96,12 @@ - (id)valueForContext:(GRMustacheContext *)context filterContext:(GRMustacheCont
[NSException raise:GRMustacheFilterException format:@"Object does not conform to GRMustacheFilter protocol"];
}
+ if (delegatingTemplate) {
+ // no invocation to return
+ NSAssert(outInvocation, @"WTF");
+ *outInvocation = nil;
+ }
+
return [filter transformedValue:parameter];
}
View
14 src/classes/GRMustacheIdentifierExpression.m
@@ -22,6 +22,7 @@
#import "GRMustacheIdentifierExpression_private.h"
#import "GRMustacheContext_private.h"
+#import "GRMustacheInvocation_private.h"
@interface GRMustacheIdentifierExpression()
@property (nonatomic, copy) NSString *identifier;
@@ -63,9 +64,18 @@ - (BOOL)isEqual:(id<GRMustacheExpression>)expression
#pragma mark - GRMustacheExpression
-- (id)valueForContext:(GRMustacheContext *)context filterContext:(GRMustacheContext *)filterContext
+- (id)valueForContext:(GRMustacheContext *)context filterContext:(GRMustacheContext *)filterContext delegatingTemplate:(GRMustacheTemplate *)delegatingTemplate delegates:(NSArray *)delegates invocation:(GRMustacheInvocation **)outInvocation
{
- return [context valueForKey:_identifier];
+ id value = [context valueForKey:_identifier];
+
+ if (delegatingTemplate) {
+ NSAssert(outInvocation, @"WTF");
+ *outInvocation = [[[GRMustacheInvocation alloc] init] autorelease];
+ (*outInvocation).returnValue = value;
+ (*outInvocation).key = _identifier;
+ }
+
+ return value;
}
@end
View
11 src/classes/GRMustacheImplicitIteratorExpression.m
@@ -22,6 +22,7 @@
#import "GRMustacheImplicitIteratorExpression_private.h"
#import "GRMustacheContext_private.h"
+#import "GRMustacheInvocation_private.h"
@implementation GRMustacheImplicitIteratorExpression
@@ -35,10 +36,18 @@ - (BOOL)isEqual:(id<GRMustacheExpression>)expression
return [expression isKindOfClass:[GRMustacheImplicitIteratorExpression class]];
}
+
#pragma mark - GRMustacheExpression
-- (id)valueForContext:(GRMustacheContext *)context filterContext:(GRMustacheContext *)filterContext
+- (id)valueForContext:(GRMustacheContext *)context filterContext:(GRMustacheContext *)filterContext delegatingTemplate:(GRMustacheTemplate *)delegatingTemplate delegates:(NSArray *)delegates invocation:(GRMustacheInvocation **)outInvocation
{
+ if (delegatingTemplate) {
+ NSAssert(outInvocation, @"WTF");
+ *outInvocation = [[[GRMustacheInvocation alloc] init] autorelease];
+ (*outInvocation).returnValue = context.object;
+ (*outInvocation).key = @".";
+ }
+
return context.object;
}
View
4 src/classes/GRMustacheInvocation.h
@@ -37,6 +37,10 @@
* @since v1.12
*/
@interface GRMustacheInvocation : NSObject {
+@private
+ NSString *_key;
+ id _returnValue;
+ BOOL _nonScopable;
}
/**
View
24 src/classes/GRMustacheInvocation.m
@@ -25,8 +25,15 @@
#import "GRMustacheToken_private.h"
@implementation GRMustacheInvocation
-@dynamic returnValue;
-@dynamic key;
+@synthesize returnValue=_returnValue;
+@synthesize key=_key;
+
+- (void)dealloc
+{
+ [_returnValue release];
+ [_key release];
+ [super dealloc];
+}
- (NSString *)description
{
@@ -39,19 +46,14 @@ - (NSString *)description
return nil;
}
-- (NSString *)key
-{
- return nil;
-}
-
-- (id)returnValue
+- (BOOL)isScopable
{
- return nil;
+ return !_nonScopable;
}
-- (void)setReturnValue:(id)returnValue
+- (void)setScopable:(BOOL)scopable
{
- return;
+ _nonScopable = !scopable;
}
@end
View
11 src/classes/GRMustacheInvocation_private.h
@@ -22,21 +22,22 @@
#import <Foundation/Foundation.h>
#import "GRMustacheAvailabilityMacros_private.h"
-#import "GRMustache_private.h"
-
-@class GRMustacheContext;
-@class GRMustacheToken;
/**
* TODO
*/
@interface GRMustacheInvocation : NSObject {
+@private
+ NSString *_key;
+ id _returnValue;
+ BOOL _nonScopable;
}
// Documented in GRMustacheInvocation.h
-@property (nonatomic, readonly) NSString *key GRMUSTACHE_API_PUBLIC;
+@property (nonatomic, retain) NSString *key GRMUSTACHE_API_PUBLIC;
// Documented in GRMustacheInvocation.h
@property (nonatomic, retain) id returnValue GRMUSTACHE_API_PUBLIC;
+@property (nonatomic, getter = isScopable) BOOL scopable GRMUSTACHE_API_INTERNAL;
@end
View
19 src/classes/GRMustacheScopedExpression.m
@@ -22,6 +22,7 @@
#import "GRMustacheScopedExpression_private.h"
#import "GRMustacheContext_private.h"
+#import "GRMustacheInvocation_private.h"
@interface GRMustacheScopedExpression()
@property (nonatomic, retain) id<GRMustacheExpression> baseExpression;
@@ -70,10 +71,22 @@ - (BOOL)isEqual:(id<GRMustacheExpression>)expression
#pragma mark - GRMustacheExpression
-- (id)valueForContext:(GRMustacheContext *)context filterContext:(GRMustacheContext *)filterContext
+- (id)valueForContext:(GRMustacheContext *)context filterContext:(GRMustacheContext *)filterContext delegatingTemplate:(GRMustacheTemplate *)delegatingTemplate delegates:(NSArray *)delegates invocation:(GRMustacheInvocation **)outInvocation
{
- id value = [_baseExpression valueForContext:context filterContext:filterContext];
- return [GRMustacheContext valueForKey:_scopeIdentifier inObject:value];
+ id value = [_baseExpression valueForContext:context filterContext:filterContext delegatingTemplate:delegatingTemplate delegates:delegates invocation:outInvocation];
+ value = [GRMustacheContext valueForKey:_scopeIdentifier inObject:value];
+ if (delegatingTemplate) {
+ NSAssert(outInvocation, @"WTF");
+ if (*outInvocation == nil) {
+ *outInvocation = [[[GRMustacheInvocation alloc] init] autorelease];
+ }
+ if (value || (*outInvocation).isScopable) {
+ (*outInvocation).scopable = (value != nil);
+ (*outInvocation).returnValue = value;
+ (*outInvocation).key = _scopeIdentifier;
+ }
+ }
+ return value;
}
@end
View
14 src/classes/GRMustacheSectionElement.m
@@ -113,7 +113,12 @@ - (NSString *)renderRenderingContext:(GRMustacheContext *)renderingContext filte
// evaluate
- id object = [_expression valueForContext:renderingContext filterContext:filterContext];
+ GRMustacheInvocation *invocation = nil;
+ id object = [_expression valueForContext:renderingContext filterContext:filterContext delegatingTemplate:delegatingTemplate delegates:delegates invocation:&invocation];
+ if (invocation) {
+ [delegatingTemplate invokeDelegates:delegates willInterpretReturnValueOfInvocation:invocation as:GRMustacheInterpretationSection];
+ object = invocation.returnValue;
+ }
// augment delegates if necessary
@@ -183,6 +188,13 @@ - (NSString *)renderRenderingContext:(GRMustacheContext *)renderingContext filte
result = [[self renderElementsWithRenderingContext:innerContext filterContext:filterContext delegatingTemplate:delegatingTemplate delegates:innerDelegates] retain];
}
}
+
+ // finish
+
+ if (invocation) {
+ [delegatingTemplate invokeDelegates:delegates didInterpretReturnValueOfInvocation:invocation as:GRMustacheInterpretationSection];
+ }
+
}
if (!result) {
return @"";
View
5 src/classes/GRMustacheTemplateDelegate.h
@@ -53,6 +53,11 @@ typedef enum {
* @since v4.1
*/
GRMustacheInterpretationVariable,
+
+ /**
+ * TODO
+ */
+ GRMustacheInterpretationFilterArgument,
} GRMustacheInterpretation;
/**
View
13 src/classes/GRMustacheVariableElement.m
@@ -55,7 +55,12 @@ - (NSString *)renderRenderingContext:(GRMustacheContext *)renderingContext filte
{
// evaluate
- id object = [_expression valueForContext:renderingContext filterContext:filterContext];
+ GRMustacheInvocation *invocation = nil;
+ id object = [_expression valueForContext:renderingContext filterContext:filterContext delegatingTemplate:delegatingTemplate delegates:delegates invocation:&invocation];
+ if (invocation) {
+ [delegatingTemplate invokeDelegates:delegates willInterpretReturnValueOfInvocation:invocation as:GRMustacheInterpretationVariable];
+ object = invocation.returnValue;
+ }
// interpret
@@ -70,7 +75,11 @@ - (NSString *)renderRenderingContext:(GRMustacheContext *)renderingContext filte
// finish
-
+
+ if (invocation) {
+ [delegatingTemplate invokeDelegates:delegates didInterpretReturnValueOfInvocation:invocation as:GRMustacheInterpretationVariable];
+ }
+
if (!result) {
return @"";
}
Please sign in to comment.
Something went wrong with that request. Please try again.