Permalink
Browse files

Rename some of the files to be Tipi, rather than hM.

  • Loading branch information...
1 parent b5a1199 commit 3207d7854fb8044448c27e3f79022fa2bd176136 @hiddenmemory committed Apr 7, 2012
@@ -10,9 +10,9 @@
838CA66E152DB08F0013C064 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 838CA66D152DB08F0013C064 /* Foundation.framework */; };
838CA671152DB08F0013C064 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 838CA670152DB08F0013C064 /* main.m */; };
838CA675152DB08F0013C064 /* Tipi.1 in CopyFiles */ = {isa = PBXBuildFile; fileRef = 838CA674152DB08F0013C064 /* Tipi.1 */; };
- 838CA67E152DB0DA0013C064 /* TPInputParser.m in Sources */ = {isa = PBXBuildFile; fileRef = 838CA67D152DB0DA0013C064 /* TPInputParser.m */; };
+ 838CA67E152DB0DA0013C064 /* TPDataParser.m in Sources */ = {isa = PBXBuildFile; fileRef = 838CA67D152DB0DA0013C064 /* TPDataParser.m */; };
838CA681152DB11E0013C064 /* TPTextDataParser.m in Sources */ = {isa = PBXBuildFile; fileRef = 838CA680152DB11E0013C064 /* TPTextDataParser.m */; };
- 838CA689152DB55C0013C064 /* NSString+HiddenMemory.m in Sources */ = {isa = PBXBuildFile; fileRef = 838CA688152DB55C0013C064 /* NSString+HiddenMemory.m */; };
+ 838CA689152DB55C0013C064 /* NSString+Tipi.m in Sources */ = {isa = PBXBuildFile; fileRef = 838CA688152DB55C0013C064 /* NSString+Tipi.m */; };
838CA68C152DB59F0013C064 /* RegexKitLite.m in Sources */ = {isa = PBXBuildFile; fileRef = 838CA68B152DB59F0013C064 /* RegexKitLite.m */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; };
838CA68E152DB6920013C064 /* libicucore.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 838CA68D152DB6920013C064 /* libicucore.dylib */; };
838CA691152DB7BB0013C064 /* TPMarkdownDataParser.m in Sources */ = {isa = PBXBuildFile; fileRef = 838CA690152DB7BB0013C064 /* TPMarkdownDataParser.m */; };
@@ -39,6 +39,7 @@
838CA720152DB8A10013C064 /* mkdioWrapper.c in Sources */ = {isa = PBXBuildFile; fileRef = 838CA703152DB8A10013C064 /* mkdioWrapper.c */; };
838CA726152DBEEB0013C064 /* TPTemplateParser.m in Sources */ = {isa = PBXBuildFile; fileRef = 838CA725152DBEEB0013C064 /* TPTemplateParser.m */; };
838CA729152DC02D0013C064 /* TPTemplateNode.m in Sources */ = {isa = PBXBuildFile; fileRef = 838CA728152DC02D0013C064 /* TPTemplateNode.m */; };
+ 83DC137015305157005FCB72 /* NSArray+Tipi.m in Sources */ = {isa = PBXBuildFile; fileRef = 83DC136F15305157005FCB72 /* NSArray+Tipi.m */; };
/* End PBXBuildFile section */
/* Begin PBXCopyFilesBuildPhase section */
@@ -61,12 +62,12 @@
838CA673152DB08F0013C064 /* Tipi-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "Tipi-Prefix.pch"; sourceTree = "<group>"; };
838CA674152DB08F0013C064 /* Tipi.1 */ = {isa = PBXFileReference; lastKnownFileType = text.man; path = Tipi.1; sourceTree = "<group>"; };
838CA67C152DB0DA0013C064 /* TPDataParser.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TPDataParser.h; sourceTree = "<group>"; };
- 838CA67D152DB0DA0013C064 /* TPInputParser.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TPInputParser.m; sourceTree = "<group>"; };
+ 838CA67D152DB0DA0013C064 /* TPDataParser.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TPDataParser.m; sourceTree = "<group>"; };
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+HiddenMemory.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSString+HiddenMemory.h"; sourceTree = "<group>"; };
- 838CA688152DB55C0013C064 /* NSString+HiddenMemory.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSString+HiddenMemory.m"; sourceTree = "<group>"; };
+ 838CA687152DB55C0013C064 /* NSString+Tipi.h */ = {isa = PBXFileReference; fileEncoding = 4; 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>"; };
838CA68D152DB6920013C064 /* libicucore.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libicucore.dylib; path = usr/lib/libicucore.dylib; sourceTree = SDKROOT; };
@@ -110,6 +111,9 @@
838CA728152DC02D0013C064 /* TPTemplateNode.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TPTemplateNode.m; sourceTree = "<group>"; };
83C656BC152DD61500454E32 /* Test02.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = Test02.html; sourceTree = "<group>"; };
83C656BE152DFFA200454E32 /* Test03.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = Test03.html; sourceTree = "<group>"; };
+ 83DC136C153050D8005FCB72 /* Tipi.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Tipi.h; sourceTree = "<group>"; };
+ 83DC136E15305157005FCB72 /* NSArray+Tipi.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSArray+Tipi.h"; sourceTree = "<group>"; };
+ 83DC136F15305157005FCB72 /* NSArray+Tipi.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSArray+Tipi.m"; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
@@ -176,6 +180,7 @@
children = (
838CA722152DBA560013C064 /* Helpers */,
838CA721152DBA4B0013C064 /* Parsers */,
+ 83DC136C153050D8005FCB72 /* Tipi.h */,
);
name = Tipi;
sourceTree = "<group>";
@@ -257,7 +262,7 @@
isa = PBXGroup;
children = (
838CA67C152DB0DA0013C064 /* TPDataParser.h */,
- 838CA67D152DB0DA0013C064 /* TPInputParser.m */,
+ 838CA67D152DB0DA0013C064 /* TPDataParser.m */,
838CA67F152DB11E0013C064 /* TPTextDataParser.h */,
838CA680152DB11E0013C064 /* TPTextDataParser.m */,
838CA68F152DB7BA0013C064 /* TPMarkdownDataParser.h */,
@@ -276,8 +281,10 @@
838CA692152DB8A00013C064 /* Discount */,
838CA68A152DB59F0013C064 /* RegexKitLite.h */,
838CA68B152DB59F0013C064 /* RegexKitLite.m */,
- 838CA687152DB55C0013C064 /* NSString+HiddenMemory.h */,
- 838CA688152DB55C0013C064 /* NSString+HiddenMemory.m */,
+ 838CA687152DB55C0013C064 /* NSString+Tipi.h */,
+ 838CA688152DB55C0013C064 /* NSString+Tipi.m */,
+ 83DC136E15305157005FCB72 /* NSArray+Tipi.h */,
+ 83DC136F15305157005FCB72 /* NSArray+Tipi.m */,
);
name = Helpers;
sourceTree = "<group>";
@@ -334,9 +341,9 @@
buildActionMask = 2147483647;
files = (
838CA671152DB08F0013C064 /* main.m in Sources */,
- 838CA67E152DB0DA0013C064 /* TPInputParser.m in Sources */,
+ 838CA67E152DB0DA0013C064 /* TPDataParser.m in Sources */,
838CA681152DB11E0013C064 /* TPTextDataParser.m in Sources */,
- 838CA689152DB55C0013C064 /* NSString+HiddenMemory.m in Sources */,
+ 838CA689152DB55C0013C064 /* NSString+Tipi.m in Sources */,
838CA68C152DB59F0013C064 /* RegexKitLite.m in Sources */,
838CA691152DB7BB0013C064 /* TPMarkdownDataParser.m in Sources */,
838CA705152DB8A10013C064 /* amalloc.c in Sources */,
@@ -362,6 +369,7 @@
838CA720152DB8A10013C064 /* mkdioWrapper.c in Sources */,
838CA726152DBEEB0013C064 /* TPTemplateParser.m in Sources */,
838CA729152DC02D0013C064 /* TPTemplateNode.m in Sources */,
+ 83DC137015305157005FCB72 /* NSArray+Tipi.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
View
@@ -0,0 +1,17 @@
+//
+// NSArray+Tipi.h
+// Tipi
+//
+// Created by Chris Ross on 07/04/2012.
+// Copyright (c) 2012 hiddenMemory Ltd. All rights reserved.
+//
+
+#import <Foundation/Foundation.h>
+
+@class TPTemplateNode;
+
+@interface NSArray (Tipi)
+
+- (NSString*)tp_templateNodesExpandedUsingEnvironment:(NSMutableDictionary*)environment;
+
+@end
View
@@ -0,0 +1,24 @@
+//
+// NSArray+Tipi.m
+// Tipi
+//
+// Created by Chris Ross on 07/04/2012.
+// Copyright (c) 2012 hiddenMemory Ltd. All rights reserved.
+//
+
+#import "NSArray+Tipi.h"
+#import "Tipi.h"
+
+@implementation NSArray (Tipi)
+
+- (NSString*)tp_templateNodesExpandedUsingEnvironment:(NSMutableDictionary*)environment {
+ NSMutableString *expansion = [NSMutableString string];
+
+ for( TPTemplateNode *childNode in self ) {
+ [expansion appendString:[childNode expansionUsingEnvironment:environment]];
+ }
+
+ return expansion;
+}
+
+@end
@@ -1,6 +1,6 @@
//
-// NSString+HiddenMemory.h
-// hiddenMemory Core Library
+// NSString+Tipi.h
+// Tipi Core Library
//
// Created by Chris Ross on 03/06/2010.
// Copyright 2010 hiddenMemory Ltd. All rights reserved.
@@ -9,7 +9,7 @@
#import <Foundation/Foundation.h>
-@interface NSString (HiddenMemory)
+@interface NSString (Tipi)
+ (NSString*)bytesToHuman:(size_t)value;
@@ -1,12 +1,12 @@
//
-// NSString+HiddenMemory.m
-// hiddenMemory Core Library
+// NSString+Tipi.m
+// Tipi Core Library
//
// Created by Chris Ross on 03/06/2010.
// Copyright 2010 hiddenMemory Ltd. All rights reserved.
//
-#import "NSString+HiddenMemory.h"
+#import "NSString+Tipi.h"
#import "RegexKitLite.h"
@implementation NSString (HiddenMemory)
File renamed without changes.
View
@@ -7,7 +7,7 @@
//
#import "TPTemplateNode.h"
-#import "NSString+HiddenMemory.h"
+#import "NSString+Tipi.h"
@implementation TPTemplateNode
@synthesize type, originalValue, name, values, childNodes;
View
@@ -8,9 +8,11 @@
#import "TPTemplateParser.h"
#import "TPTemplateNode.h"
-#import "NSString+HiddenMemory.h"
#import "TPMarkdownDataParser.h"
+#import "NSString+Tipi.h"
+#import "NSArray+Tipi.h"
+
@interface TPTemplateParser () {
TPTemplateNode *root;
@@ -54,23 +56,23 @@ - (NSString*)expansionUsingEnvironment:(NSDictionary*)values {
[environment setObject:[^NSString*( TPTemplateNode *node, NSMutableDictionary *environment, NSArray *parameters ) {
if( [node.childNodes count] > 0 ) {
+ // If there is one or more child nodes, we assume that this is an expansion block
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];
+
+ // Capture {{this}}
+ [invokeEnvironment setObject:[currentNode.childNodes tp_templateNodesExpandedUsingEnvironment:freshEnvironment]
+ forKey:@"this"];
- NSMutableString *thisExpansion = [NSMutableString string];
- for( TPTemplateNode *childNode in currentNode.childNodes ) {
- [thisExpansion appendString:[childNode expansionUsingEnvironment:freshEnvironment]];
- }
- [invokeEnvironment setObject:thisExpansion forKey:@"this"];
-
+ // Capture each parameter: this maps the {{def NAME PARAM1}} -> value provided in parameters
[[node.values subarrayWithRange:NSMakeRange(1, [node.values count] - 1)] enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
[invokeEnvironment setObject:[parameters objectAtIndex:idx] forKey:[obj lowercaseString]];
}];
+ // This walks the node on which the def is being invoked to see if there are any bind commands
for( TPTemplateNode *bindNode in currentNode.childNodes ) {
if( [bindNode.name isEqualToString:@"bind"] ) {
[bindNode.childNodes enumerateObjectsUsingBlock:^(TPTemplateNode *obj, NSUInteger idx, BOOL *stop) {
@@ -80,38 +82,20 @@ - (NSString*)expansionUsingEnvironment:(NSDictionary*)values {
}
}
- for( TPTemplateNode *childNode in node.childNodes ) {
- [expansion appendString:[childNode expansionUsingEnvironment:invokeEnvironment]];
- }
-
- return expansion;
+ // Expand and return the result
+ return [node.childNodes tp_templateNodesExpandedUsingEnvironment:invokeEnvironment];
} 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]];
-
+ /// If there are no child nodes, we set a value in the environment
+ [environment setObject:[node.values objectAtIndex:1] forKey:[[node.values objectAtIndex:0] lowercaseString]];
+
NSLog(@"Environment: %@", environment);
}
return @"";
} copy] forKey:@"def"];
- [environment setObject:[^NSString*( TPTemplateNode *node, NSMutableDictionary *environment, NSArray *parameters ) {
- NSMutableString *expansion = [NSMutableString string];
- TPMarkdownDataParser *parser = [TPMarkdownDataParser parserForFile:[node.values objectAtIndex:0]];
-
- NSMutableDictionary *invokeEnvironment = [NSMutableDictionary dictionaryWithDictionary:environment];
- [invokeEnvironment addEntriesFromDictionary:parser.values];
-
- for( TPTemplateNode *childNode in node.childNodes ) {
- [expansion appendString:[childNode expansionUsingEnvironment:invokeEnvironment]];
- }
-
- return expansion;
- } copy] forKey:@"include"];
-
return [[root expansionUsingEnvironment:environment] stringByTrimmingWhitespace];
}
- (void)parseContent:(NSMutableString*)content parent:(TPTemplateNode*)parent {
@@ -154,41 +138,29 @@ - (BOOL)parseTag:(NSMutableString*)content parent:(TPTemplateNode*)parent {
while( [stringToParse length] ) {
stringToParse = [stringToParse stringByTrimmingWhitespace];
- if( [stringToParse hasPrefix:@"\""] ) {
+ if( [stringToParse hasPrefix:@"\""] || [stringToParse hasPrefix:@"'"] ) {
+ // If we match a comment character, match until the next non-escaped version, otherwise until end of the string
+ unichar matchCharacter = [stringToParse characterAtIndex:0];
BOOL success = NO;
- NSUInteger i = 0;
- for( i = 1; i < [stringToParse length]; i++ ) {
- unichar c = [stringToParse characterAtIndex:i];
- if( c == '"' && [stringToParse characterAtIndex:i - 1] != '\\' ) {
- [parts addObject:[stringToParse substringWithRange:NSMakeRange(1, i - 1)]];
- stringToParse = [stringToParse substringFromIndex:i + 1];
- success = YES;
- break;
- }
- }
- if( success == NO ) {
- [parts addObject:stringToParse];
- stringToParse = @"";
- }
- }
- else if( [stringToParse hasPrefix:@"'"] ) {
- BOOL success = NO;
- NSUInteger i = 0;
- for( i = 1; i < [stringToParse length]; i++ ) {
+
+ for( NSUInteger i = 1; i < [stringToParse length]; i++ ) {
unichar c = [stringToParse characterAtIndex:i];
- if( c == '\'' && [stringToParse characterAtIndex:i - 1] != '\\' ) {
+ if( c == matchCharacter && [stringToParse characterAtIndex:i - 1] != '\\' ) {
[parts addObject:[stringToParse substringWithRange:NSMakeRange(1, i - 1)]];
stringToParse = [stringToParse substringFromIndex:i + 1];
success = YES;
break;
}
}
+
if( success == NO ) {
+ // If we don't find the terminating character, we chomp till the end of the string
[parts addObject:stringToParse];
stringToParse = @"";
}
}
else {
+ // Chomp until the next space
NSRange range = [stringToParse rangeOfString:@" "];
NSString *nextToken = (range.location == NSNotFound ? stringToParse : [stringToParse substringToIndex:range.location]);
@@ -198,6 +170,7 @@ - (BOOL)parseTag:(NSMutableString*)content parent:(TPTemplateNode*)parent {
stringToParse = [stringToParse substringFromIndex:[nextToken length]];
}
else {
+ // We hit the end of the string
break;
}
}
View
@@ -7,7 +7,7 @@
//
#import "TPTextDataParser.h"
-#import "NSString+HiddenMemory.h"
+#import "NSString+Tipi.h"
@interface TPTextDataParser () {
NSMutableDictionary *_values;
View
@@ -0,0 +1,19 @@
+//
+// Tipi.h
+// Tipi
+//
+// Created by Chris Ross on 07/04/2012.
+// Copyright (c) 2012 hiddenMemory Ltd. All rights reserved.
+//
+
+#ifndef Tipi_Tipi_h
+#define Tipi_Tipi_h
+
+#import "TPDataParser.h"
+#import "TPTextDataParser.h"
+#import "TPMarkdownDataParser.h"
+#import "TPTemplateParser.h"
+#import "TPTemplateNode.h"
+#import "NSArray+Tipi.h"
+
+#endif
View
@@ -8,13 +8,25 @@
#import <Foundation/Foundation.h>
-#import "TPDataParser.h"
-#import "TPMarkdownDataParser.h"
-#import "TPTemplateParser.h"
+#import "Tipi.h"
int main(int argc, const char * argv[]) {
@autoreleasepool {
+ NSMutableDictionary *environment = [NSMutableDictionary dictionary];
+
+ [environment setObject:[^NSString*( TPTemplateNode *node, NSMutableDictionary *environment, NSArray *parameters ) {
+ TPMarkdownDataParser *parser = [TPMarkdownDataParser parserForFile:[node.values objectAtIndex:0]];
+
+ // Duplicate the environment for implementing the child nodes
+ NSMutableDictionary *invokeEnvironment = [NSMutableDictionary dictionaryWithDictionary:environment];
+
+ // Add the key-values from the data file
+ [invokeEnvironment addEntriesFromDictionary:parser.values];
+
+ return [node.childNodes tp_templateNodesExpandedUsingEnvironment:invokeEnvironment];
+ } copy] forKey:@"include"];
+
TPDataParser *p = [TPMarkdownDataParser parserForFile:@"/Users/chris/Repositories/git/hiddenMemory/Tipi/Tests/Test01.txt"];
NSLog(@"p.values = %@", [p values]);

0 comments on commit 3207d78

Please sign in to comment.