Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Update to be inline with the basic syntax of the Scala implementation

  • Loading branch information...
commit b5a119922ac6888253aae8abfb034674b8f79c1c 1 parent 92bfc59
@hiddenmemory authored
View
6 Tests/Test01.html
@@ -1,4 +1,4 @@
-{{# template page title_test client_test }}
+{{# def page title_test client_test }}
<html>
<head>
<title>{{ title_test }}</title>
@@ -8,6 +8,6 @@
</html>
{{/ def }}
-{{ global title "This is a title" }}
-{{ global client "This is a client" }}
+{{ def title "This is a title" }}
+{{ def client "This is a client" }}
{{ page title client }}
View
4 Tests/Test02.html
@@ -1,4 +1,4 @@
-{{#template case_study title_cs client_cs description_cs platform_cs testimonial_cs literal }}
+{{#def case_study title_cs client_cs description_cs platform_cs testimonial_cs literal }}
<html>
<head>
<title>{{ title_cs }}</title>
@@ -32,7 +32,7 @@
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.
{{/ bind }}
{{# bind client_cs }}Box and Arrow Ltd{{/ bind }}
- {{#bind technologies}}ALL OF THEM!{{/bind}}
+ {{# bind technologies}}ALL OF THEM!{{/bind}}
{{/case_study}}
{{/include}}
View
2  Tests/Test03.html
@@ -3,7 +3,7 @@
{{ValueB}}
{{/def}}
-{{env ValueB "This is ValueB"}}
+{{def ValueB "This is ValueB"}}
{{#def B}}
{{ValueB}}
View
85 Tipi/TPTemplateParser.m
@@ -50,55 +50,54 @@ - (NSString*)expansionUsingEnvironment:(NSDictionary*)values {
NSMutableDictionary *environment = [NSMutableDictionary dictionaryWithDictionary:values];
[environment setObject:[^NSString*( TPTemplateNode *node, NSMutableDictionary *environment, NSArray *parameters ) { return @""; } copy]
- forKey:@"bind"];
+ forKey:@"bind"];
[environment setObject:[^NSString*( TPTemplateNode *node, NSMutableDictionary *environment, NSArray *parameters ) {
- NSString *key = [[node.values objectAtIndex:0] lowercaseString];
- NSMutableDictionary *freshEnvironment = [NSMutableDictionary dictionaryWithDictionary:environment];
-
- [environment setObject:[^NSString*( TPTemplateNode *currentNode, NSMutableDictionary *environment, NSArray *parameters ) {
- NSMutableString *expansion = [NSMutableString string];
- NSMutableDictionary *invokeEnvironment = [NSMutableDictionary dictionaryWithDictionary:freshEnvironment];
-
- NSMutableString *thisExpansion = [NSMutableString string];
- for( TPTemplateNode *childNode in currentNode.childNodes ) {
- [thisExpansion appendString:[childNode expansionUsingEnvironment:freshEnvironment]];
- }
- [invokeEnvironment setObject:thisExpansion forKey:@"this"];
-
- [[node.values subarrayWithRange:NSMakeRange(1, [node.values count] - 1)] enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
- [invokeEnvironment setObject:[parameters objectAtIndex:idx] forKey:[obj lowercaseString]];
- }];
+ if( [node.childNodes count] > 0 ) {
+ NSString *key = [[node.values objectAtIndex:0] lowercaseString];
+ NSMutableDictionary *freshEnvironment = [NSMutableDictionary dictionaryWithDictionary:environment];
- for( TPTemplateNode *bindNode in currentNode.childNodes ) {
- if( [bindNode.name isEqualToString:@"bind"] ) {
- [bindNode.childNodes enumerateObjectsUsingBlock:^(TPTemplateNode *obj, NSUInteger idx, BOOL *stop) {
- [invokeEnvironment setObject:[obj expansionUsingEnvironment:freshEnvironment]
- forKey:[[bindNode.values objectAtIndex:0] lowercaseString]];
- }];
+ [environment setObject:[^NSString*( TPTemplateNode *currentNode, NSMutableDictionary *environment, NSArray *parameters ) {
+ NSMutableString *expansion = [NSMutableString string];
+ NSMutableDictionary *invokeEnvironment = [NSMutableDictionary dictionaryWithDictionary:freshEnvironment];
+
+ NSMutableString *thisExpansion = [NSMutableString string];
+ for( TPTemplateNode *childNode in currentNode.childNodes ) {
+ [thisExpansion appendString:[childNode expansionUsingEnvironment:freshEnvironment]];
}
- }
-
- for( TPTemplateNode *childNode in node.childNodes ) {
- [expansion appendString:[childNode expansionUsingEnvironment:invokeEnvironment]];
- }
+ [invokeEnvironment setObject:thisExpansion forKey:@"this"];
+
+ [[node.values subarrayWithRange:NSMakeRange(1, [node.values count] - 1)] enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
+ [invokeEnvironment setObject:[parameters objectAtIndex:idx] forKey:[obj lowercaseString]];
+ }];
+
+ for( TPTemplateNode *bindNode in currentNode.childNodes ) {
+ if( [bindNode.name isEqualToString:@"bind"] ) {
+ [bindNode.childNodes enumerateObjectsUsingBlock:^(TPTemplateNode *obj, NSUInteger idx, BOOL *stop) {
+ [invokeEnvironment setObject:[obj expansionUsingEnvironment:freshEnvironment]
+ forKey:[[bindNode.values objectAtIndex:0] lowercaseString]];
+ }];
+ }
+ }
+
+ for( TPTemplateNode *childNode in node.childNodes ) {
+ [expansion appendString:[childNode expansionUsingEnvironment:invokeEnvironment]];
+ }
+
+ return expansion;
+ } copy] forKey:key];
+ }
+ else {
+ [environment setObject:[^NSString*( TPTemplateNode *_node, NSMutableDictionary *environment, NSArray *parameters ) {
+ return [node.values objectAtIndex:1];
+ } copy] forKey:[[node.values objectAtIndex:0] lowercaseString]];
- return expansion;
- } copy] forKey:key];
-
- return @"";
- } copy] forKey:@"def"];
-
- [environment setObject:[^NSString*( TPTemplateNode *node, NSMutableDictionary *environment, NSArray *parameters ) {
- [environment setObject:[^NSString*( TPTemplateNode *_node, NSMutableDictionary *environment, NSArray *parameters ) {
- return [node.values objectAtIndex:1];
- } copy] forKey:[[node.values objectAtIndex:0] lowercaseString]];
-
- NSLog(@"Environment: %@", environment);
+ NSLog(@"Environment: %@", environment);
+ }
return @"";
- } copy] forKey:@"env"];
-
+ } copy] forKey:@"def"];
+
[environment setObject:[^NSString*( TPTemplateNode *node, NSMutableDictionary *environment, NSArray *parameters ) {
NSMutableString *expansion = [NSMutableString string];
TPMarkdownDataParser *parser = [TPMarkdownDataParser parserForFile:[node.values objectAtIndex:0]];
@@ -240,7 +239,7 @@ - (BOOL)parseTag:(NSMutableString*)content parent:(TPTemplateNode*)parent {
if( [content characterAtIndex:0] == '\n' ) {
[content deleteCharactersInRange:NSMakeRange(0, 1)];
}
-
+
return YES;
}
else {
Please sign in to comment.
Something went wrong with that request. Please try again.