Permalink
Browse files

Move over to the more uniform syntax {{name key=value}}

  • Loading branch information...
1 parent 3207d78 commit 93a09848dd0a8bc3f0ed5df43895217fc1fc7a35 @hiddenmemory committed Apr 9, 2012
Showing with 178 additions and 81 deletions.
  1. +4 −4 Tests/Test01.html
  2. +2 −0 Tests/Test02.html
  3. +23 −0 Tests/Test04.html
  4. +3 −1 Tipi.xcodeproj/project.pbxproj
  5. +1 −0 Tipi/TPTemplateNode.h
  6. +4 −22 Tipi/TPTemplateNode.m
  7. +140 −53 Tipi/TPTemplateParser.m
  8. +1 −1 Tipi/main.m
View
@@ -1,13 +1,13 @@
-{{# def page title_test client_test }}
+{{# def page title client }}
<html>
<head>
- <title>{{ title_test }}</title>
+ <title>{{ title }}</title>
<meta name="author" value="{{ author }}">
</head>
- <body>{{ client_test }}</body>
+ <body>{{ client }}</body>
</html>
{{/ def }}
{{ def title "This is a title" }}
{{ def client "This is a client" }}
-{{ page title client }}
+{{ page title=title client=client }}
View
@@ -1,3 +1,5 @@
+{{def author "Chris Ross"}}
+
{{#def case_study title_cs client_cs description_cs platform_cs testimonial_cs literal }}
<html>
<head>
View
@@ -0,0 +1,23 @@
+{{#def test title="Default Title" content="Default Content"}}
+<title>{{title}}</title>
+<content>{{content}}</content>
+{{/def}}
+
+-------------------
+No arguments:
+{{test}}
+-------------------
+
+-------------------
+Inline arguments:
+{{test content="Inline Content" title="Inline Title"}}
+-------------------
+
+-------------------
+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.
+{{/bind}}
+{{/test}}
+-------------------
@@ -56,6 +56,7 @@
/* End PBXCopyFilesBuildPhase section */
/* Begin PBXFileReference section */
+ 831A8D0F1532F39F00E36646 /* Test04.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = Test04.html; sourceTree = "<group>"; };
838CA669152DB08F0013C064 /* Tipi */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = Tipi; sourceTree = BUILT_PRODUCTS_DIR; };
838CA66D152DB08F0013C064 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
838CA670152DB08F0013C064 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
@@ -66,7 +67,7 @@
838CA67F152DB11E0013C064 /* TPTextDataParser.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TPTextDataParser.h; sourceTree = "<group>"; };
838CA680152DB11E0013C064 /* TPTextDataParser.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TPTextDataParser.m; sourceTree = "<group>"; };
838CA683152DB39F0013C064 /* Test01.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = Test01.txt; sourceTree = "<group>"; };
- 838CA687152DB55C0013C064 /* NSString+Tipi.h */ = {isa = PBXFileReference; fileEncoding = 4; path = "NSString+Tipi.h"; sourceTree = "<group>"; };
+ 838CA687152DB55C0013C064 /* NSString+Tipi.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSString+Tipi.h"; sourceTree = "<group>"; };
838CA688152DB55C0013C064 /* NSString+Tipi.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSString+Tipi.m"; sourceTree = "<group>"; };
838CA68A152DB59F0013C064 /* RegexKitLite.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RegexKitLite.h; sourceTree = "<group>"; };
838CA68B152DB59F0013C064 /* RegexKitLite.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RegexKitLite.m; sourceTree = "<group>"; };
@@ -192,6 +193,7 @@
838CA723152DBE250013C064 /* Test01.html */,
83C656BC152DD61500454E32 /* Test02.html */,
83C656BE152DFFA200454E32 /* Test03.html */,
+ 831A8D0F1532F39F00E36646 /* Test04.html */,
);
path = Tests;
sourceTree = SOURCE_ROOT;
View
@@ -20,6 +20,7 @@ typedef enum {
@property (strong) NSString *originalValue;
@property (strong) NSString *name;
@property (readonly) NSMutableArray *values;
+@property (readonly) NSMutableDictionary *valuesMap;
@property (readonly) NSMutableArray *childNodes;
+ (TPTemplateNode*)node;
View
@@ -10,7 +10,7 @@
#import "NSString+Tipi.h"
@implementation TPTemplateNode
-@synthesize type, originalValue, name, values, childNodes;
+@synthesize type, originalValue, name, values, valuesMap, childNodes;
+ (TPTemplateNode*)node{
return [[TPTemplateNode alloc] init];
@@ -22,6 +22,7 @@ - (id)init {
self.originalValue = @"";
self.name = @"";
values = [NSMutableArray array];
+ valuesMap = [NSMutableDictionary dictionary];
childNodes = [NSMutableArray array];
}
return self;
@@ -66,27 +67,8 @@ - (NSString*)expansionUsingEnvironment:(NSMutableDictionary*)environment {
[expansion appendString:value];
}
else {
- NSString *(^expansionBlock)( TPTemplateNode *node, NSMutableDictionary *global, NSArray *parameters ) = value;
-
- NSMutableArray *parameters = [NSMutableArray array];
-
- for( NSString *_valueName in self.values ) {
- NSString *valueName = [_valueName lowercaseString];
- id valueValue = [environment objectForKey:valueName];
-
- if( valueValue == nil ) {
- [parameters addObject:_valueName];
- }
- else if( [[valueValue class] isSubclassOfClass:[NSString class]] ) {
- [parameters addObject:valueValue];
- }
- else {
- NSString *(^valueExpansionBlock)( TPTemplateNode *node, NSMutableDictionary *global, NSArray *parameters ) = valueValue;
- [parameters addObject:valueExpansionBlock(self, environment, nil)];
- }
- }
-
- [expansion appendString:expansionBlock(self, environment, parameters)];
+ NSString *(^expansionBlock)( TPTemplateNode *node, NSMutableDictionary *global ) = value;
+ [expansion appendString:expansionBlock(self, environment)];
}
}
else {
Oops, something went wrong.

0 comments on commit 93a0984

Please sign in to comment.