Permalink
Browse files

Fix bind capture to actually join child nodes rather than itterate ov…

…er them blowing away any existing value
  • Loading branch information...
1 parent eb31f00 commit ae359f701d78c8dfbb5f3c501b38ace6cc4a1bc0 @hiddenmemory committed Apr 9, 2012
Showing with 15 additions and 9 deletions.
  1. +6 −2 Tests/Test04.html
  2. +9 −7 Tipi/TPTemplateParser.m
View
@@ -1,6 +1,10 @@
{{def PollutionLevelFine="Pollution free zone"}}
{{def PollutionLevel=PollutionLevelFine}}
+{{#def lorem}}
+Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
+{{/def}}
+
{{#def test title="Default Title" content="Default Content"}}
<title>{{title}}</title>
<content>{{content}}</content>
@@ -21,7 +25,7 @@
Inline and bind arguments:
{{#test title="Inline and bind"}}
{{#bind content}}
-Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
+ {{lorem}}
{{/bind}}
{{#bind PollutionLevel}}
Polluting all the way.
@@ -35,4 +39,4 @@
{{bind content="Bound content"}}
{{bind PollutionLevel="Polluting all the way."}}
{{/test}}
--------------------
+-------------------
View
@@ -13,8 +13,8 @@
#import "NSString+Tipi.h"
#import "NSArray+Tipi.h"
-#define ParserLog if( NO ) NSLog
-//#define ParserLog NSLog
+//#define ParserLog if( NO ) NSLog
+#define ParserLog NSLog
@interface TPTemplateParser () {
TPTemplateNode *root;
@@ -86,6 +86,8 @@ - (NSString*)expansionUsingEnvironment:(NSDictionary*)values {
[environment setObject:[^NSString*( TPTemplateNode *currentNode, NSMutableDictionary *currentEnvironment ) {
NSMutableDictionary *invokeEnvironment = [NSMutableDictionary dictionaryWithDictionary:capturedEnvironment];
+ ParserLog(@"Processing node %@", currentNode.name);
+
// Capture {{this}}
[invokeEnvironment setObject:[currentNode.childNodes tp_templateNodesExpandedUsingEnvironment:currentEnvironment]
forKey:@"this"];
@@ -120,10 +122,8 @@ - (NSString*)expansionUsingEnvironment:(NSDictionary*)values {
for( TPTemplateNode *bindNode in currentNode.childNodes ) {
if( [bindNode.name isEqualToString:@"bind"] && [node.valuesMap objectForKey:[bindNode.values objectAtIndex:0]] ) {
if( [bindNode.childNodes count] ) {
- [bindNode.childNodes enumerateObjectsUsingBlock:^(TPTemplateNode *obj, NSUInteger idx, BOOL *stop) {
- [invokeEnvironment setObject:[obj expansionUsingEnvironment:currentEnvironment]
- forKey:[[bindNode.values objectAtIndex:0] lowercaseString]];
- }];
+ [invokeEnvironment setObject:[bindNode.childNodes tp_templateNodesExpandedUsingEnvironment:currentEnvironment]
+ forKey:[[bindNode.values objectAtIndex:0] lowercaseString]];
}
else if( [bindNode.values count] > 0 ) {
[invokeEnvironment setObject:[self expandValue:[bindNode.valuesMap objectForKey:[bindNode.values objectAtIndex:0]]
@@ -137,7 +137,9 @@ - (NSString*)expansionUsingEnvironment:(NSDictionary*)values {
ParserLog(@"Invoke environment: %@ (%@)", invokeEnvironment, currentNode);
// Expand and return the result
- return [node.childNodes tp_templateNodesExpandedUsingEnvironment:invokeEnvironment];
+ NSString *expansion = [node.childNodes tp_templateNodesExpandedUsingEnvironment:invokeEnvironment];
+ ParserLog(@"Expansion for %@ = %@", currentNode.name, expansion);
+ return expansion;
} copy] forKey:key];
}
else {

0 comments on commit ae359f7

Please sign in to comment.