Permalink
Browse files

Expansions working on templates

  • Loading branch information...
1 parent 8d5540c commit 2cfbc2184a47ebc7c861174f9e6ae6c75f6468af @hiddenmemory committed Apr 5, 2012
View
@@ -0,0 +1,9 @@
+{{# def page title author }}
+<html>
+ <head>
+ <title>{{ title }}</title>
+ <meta name="author" value="{{ author }}">
+ </head>
+ <body>{{ this }}</body>
+</html>
+{{/ def }}
View
@@ -0,0 +1,21 @@
+<html>
+ <head>
+ <title>{{ title }}</title>
+ <meta name="author" value="{{ author }}">
+ </head>
+ <body>
+ <h1>{{title}}</h1>
+ <h2>Client: {{client}}</h2>
+
+ {{description}}
+
+ <h3>Platform</h3>
+ <blockquote>{{platform}}</blockquote>
+
+ <h3>Testimonial</h3>
+ {{Testimonial}}
+
+ <h4>Technologies</h4>
+ {{Technologies}}
+ </body>
+</html>
@@ -10,7 +10,7 @@
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 /* TPParser.m in Sources */ = {isa = PBXBuildFile; fileRef = 838CA67D152DB0DA0013C064 /* TPParser.m */; };
+ 838CA67E152DB0DA0013C064 /* TPInputParser.m in Sources */ = {isa = PBXBuildFile; fileRef = 838CA67D152DB0DA0013C064 /* TPInputParser.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 */; };
838CA68C152DB59F0013C064 /* RegexKitLite.m in Sources */ = {isa = PBXBuildFile; fileRef = 838CA68B152DB59F0013C064 /* RegexKitLite.m */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; };
@@ -37,6 +37,8 @@
838CA71E152DB8A10013C064 /* discountWrapper.m in Sources */ = {isa = PBXBuildFile; fileRef = 838CA700152DB8A10013C064 /* discountWrapper.m */; };
838CA71F152DB8A10013C064 /* markdownWrapper.c in Sources */ = {isa = PBXBuildFile; fileRef = 838CA701152DB8A10013C064 /* markdownWrapper.c */; };
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 */; };
/* End PBXBuildFile section */
/* Begin PBXCopyFilesBuildPhase section */
@@ -58,8 +60,8 @@
838CA670152DB08F0013C064 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
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 /* TPParser.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TPParser.h; sourceTree = "<group>"; };
- 838CA67D152DB0DA0013C064 /* TPParser.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TPParser.m; 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>"; };
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>"; };
@@ -101,6 +103,12 @@
838CA702152DB8A10013C064 /* markdownWrapper.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = markdownWrapper.h; sourceTree = "<group>"; };
838CA703152DB8A10013C064 /* mkdioWrapper.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = mkdioWrapper.c; sourceTree = "<group>"; };
838CA704152DB8A10013C064 /* mkdioWrapper.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = mkdioWrapper.h; sourceTree = "<group>"; };
+ 838CA723152DBE250013C064 /* Test01.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = Test01.html; sourceTree = "<group>"; };
+ 838CA724152DBEEB0013C064 /* TPTemplateParser.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TPTemplateParser.h; sourceTree = "<group>"; };
+ 838CA725152DBEEB0013C064 /* TPTemplateParser.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TPTemplateParser.m; sourceTree = "<group>"; };
+ 838CA727152DC02D0013C064 /* TPTemplateNode.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TPTemplateNode.h; sourceTree = "<group>"; };
+ 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>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
@@ -145,7 +153,6 @@
838CA66F152DB08F0013C064 /* Tipi */ = {
isa = PBXGroup;
children = (
- 838CA692152DB8A00013C064 /* Discount */,
838CA682152DB39F0013C064 /* Tests */,
838CA67B152DB0BF0013C064 /* Tipi */,
838CA670152DB08F0013C064 /* main.m */,
@@ -176,6 +183,8 @@
isa = PBXGroup;
children = (
838CA683152DB39F0013C064 /* Test01.txt */,
+ 838CA723152DBE250013C064 /* Test01.html */,
+ 83C656BC152DD61500454E32 /* Test02.html */,
);
path = Tests;
sourceTree = SOURCE_ROOT;
@@ -245,19 +254,24 @@
838CA721152DBA4B0013C064 /* Parsers */ = {
isa = PBXGroup;
children = (
- 838CA67C152DB0DA0013C064 /* TPParser.h */,
- 838CA67D152DB0DA0013C064 /* TPParser.m */,
+ 838CA67C152DB0DA0013C064 /* TPDataParser.h */,
+ 838CA67D152DB0DA0013C064 /* TPInputParser.m */,
838CA67F152DB11E0013C064 /* TPTextDataParser.h */,
838CA680152DB11E0013C064 /* TPTextDataParser.m */,
838CA68F152DB7BA0013C064 /* TPMarkdownDataParser.h */,
838CA690152DB7BB0013C064 /* TPMarkdownDataParser.m */,
+ 838CA724152DBEEB0013C064 /* TPTemplateParser.h */,
+ 838CA725152DBEEB0013C064 /* TPTemplateParser.m */,
+ 838CA727152DC02D0013C064 /* TPTemplateNode.h */,
+ 838CA728152DC02D0013C064 /* TPTemplateNode.m */,
);
name = Parsers;
sourceTree = "<group>";
};
838CA722152DBA560013C064 /* Helpers */ = {
isa = PBXGroup;
children = (
+ 838CA692152DB8A00013C064 /* Discount */,
838CA68A152DB59F0013C064 /* RegexKitLite.h */,
838CA68B152DB59F0013C064 /* RegexKitLite.m */,
838CA687152DB55C0013C064 /* NSString+HiddenMemory.h */,
@@ -318,7 +332,7 @@
buildActionMask = 2147483647;
files = (
838CA671152DB08F0013C064 /* main.m in Sources */,
- 838CA67E152DB0DA0013C064 /* TPParser.m in Sources */,
+ 838CA67E152DB0DA0013C064 /* TPInputParser.m in Sources */,
838CA681152DB11E0013C064 /* TPTextDataParser.m in Sources */,
838CA689152DB55C0013C064 /* NSString+HiddenMemory.m in Sources */,
838CA68C152DB59F0013C064 /* RegexKitLite.m in Sources */,
@@ -344,6 +358,8 @@
838CA71E152DB8A10013C064 /* discountWrapper.m in Sources */,
838CA71F152DB8A10013C064 /* markdownWrapper.c in Sources */,
838CA720152DB8A10013C064 /* mkdioWrapper.c in Sources */,
+ 838CA726152DBEEB0013C064 /* TPTemplateParser.m in Sources */,
+ 838CA729152DC02D0013C064 /* TPTemplateNode.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -436,6 +452,7 @@
838CA67A152DB08F0013C064 /* Release */,
);
defaultConfigurationIsVisible = 0;
+ defaultConfigurationName = Release;
};
/* End XCConfigurationList section */
};
@@ -40,4 +40,6 @@
+ (NSString*)stringByCreatingWhitespaceOfLength:(NSInteger)length;
- (NSString*)stringByTrimmingWhitespace;
+- (NSString*)removePrefix:(NSString*)prefix suffix:(NSString*)suffix;
+
@end
@@ -26,7 +26,6 @@ + (NSString*)bytesToHuman:(size_t)value {
return @"";
}
-
- (NSString *)stringByEncodingXMLEntities {
// Scanner
NSScanner *scanner = [[NSScanner alloc] initWithString:self];
@@ -275,4 +274,18 @@ - (NSString*)stringByTrimmingWhitespace {
return [self stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
}
+- (NSString*)removePrefix:(NSString*)prefix suffix:(NSString*)suffix {
+ NSString *str = self;
+
+ if( [str hasPrefix:prefix] ) {
+ str = [str stringByReplacingCharactersInRange:NSMakeRange(0, [prefix length]) withString:@""];
+ }
+
+ if( [str hasSuffix:suffix] ) {
+ str = [str stringByReplacingCharactersInRange:NSMakeRange([str length] - [suffix length], [suffix length]) withString:@""];
+ }
+
+ return str;
+}
+
@end
@@ -8,6 +8,6 @@
#import <Foundation/Foundation.h>
-@interface TPParser : NSObject
+@interface TPDataParser : NSObject
- (NSDictionary*)values;
@end
@@ -6,9 +6,9 @@
// Copyright (c) 2012 hiddenMemory Ltd. All rights reserved.
//
-#import "TPParser.h"
+#import "TPDataParser.h"
-@implementation TPParser
+@implementation TPDataParser
- (NSDictionary*)values {
return [NSDictionary dictionary];
@@ -16,7 +16,18 @@ - (NSDictionary*)values {
NSMutableDictionary *markdownValues = [NSMutableDictionary dictionary];
for( NSString *key in [values allKeys] ) {
- [markdownValues setObject:discountToHTML([values objectForKey:key]) forKey:key];
+ NSMutableString *htmlSnippet = [NSMutableString stringWithString:discountToHTML([values objectForKey:key])];
+
+ if( [htmlSnippet hasPrefix:@"<p>"] ) {
+ [htmlSnippet deleteCharactersInRange:NSMakeRange(0, [@"<p>" length])];
+ }
+ if( [htmlSnippet hasSuffix:@"</p>"] ) {
+ NSUInteger tagLength = [@"</p>" length];
+ [htmlSnippet deleteCharactersInRange:NSMakeRange([htmlSnippet length] - tagLength, tagLength)];
+ }
+
+ [markdownValues setObject:htmlSnippet
+ forKey:key];
}
return markdownValues;
View
@@ -0,0 +1,27 @@
+//
+// TPTemplateNode.h
+// Tipi
+//
+// Created by Chris Ross on 05/04/2012.
+// Copyright (c) 2012 hiddenMemory Ltd. All rights reserved.
+//
+
+#import <Foundation/Foundation.h>
+
+typedef enum {
+ TPNodeUnknown,
+ TPNodeText,
+ TPNodeDefinition,
+ TPNodeApplication
+} TPNodeType;
+
+@interface TPTemplateNode : NSObject
+@property (assign) TPNodeType type;
+@property (strong) NSString *originalValue;
+@property (strong) NSString *name;
+@property (readonly) NSMutableArray *values;
+@property (readonly) NSMutableArray *childNodes;
+
++ (TPTemplateNode*)node;
+- (NSString*)expansionUsingValues:(NSDictionary*)values;
+@end
View
@@ -0,0 +1,73 @@
+//
+// TPTemplateNode.m
+// Tipi
+//
+// Created by Chris Ross on 05/04/2012.
+// Copyright (c) 2012 hiddenMemory Ltd. All rights reserved.
+//
+
+#import "TPTemplateNode.h"
+#import "NSString+HiddenMemory.h"
+
+@implementation TPTemplateNode
+@synthesize type, originalValue, name, values, childNodes;
+
++ (TPTemplateNode*)node{
+ return [[TPTemplateNode alloc] init];
+}
+- (id)init {
+ self = [super init];
+ if( self ) {
+ self.type = TPNodeUnknown;
+ self.originalValue = @"";
+ self.name = @"";
+ values = [NSMutableArray array];
+ childNodes = [NSMutableArray array];
+ }
+ return self;
+}
+- (NSString*)descriptionWithDepth:(int)depth {
+ NSMutableString *description = nil;
+
+ if( self.type == TPNodeText ) {
+ description = [NSMutableString stringWithFormat:@"%@<Text> '%@'\n",
+ [NSString stringByCreatingWhitespaceOfLength:depth],
+ [self.originalValue stringByReplacingOccurrencesOfString:@"\n" withString:@"\\n"]];
+ }
+ else {
+ description = [NSMutableString stringWithFormat:@"%@<Node> %@(%@)\n",
+ [NSString stringByCreatingWhitespaceOfLength:depth],
+ self.name,
+ [values componentsJoinedByString:@", "]];
+ }
+
+ for( TPTemplateNode *node in childNodes ) {
+ [description appendString:[node descriptionWithDepth:depth + 1]];
+ }
+
+ return description;
+}
+- (NSString*)description {
+ return [self descriptionWithDepth:0];
+}
+- (NSString*)expansionUsingValues:(NSDictionary*)_values {
+ NSMutableString *expansion = [NSMutableString string];
+
+ if( self.type == TPNodeText ) {
+ [expansion appendString:self.originalValue];
+ }
+ else {
+ NSString *key = [self.name lowercaseString];
+ if( [_values objectForKey:key] ) {
+ [expansion appendString:[_values objectForKey:key]];
+ }
+ }
+
+ for( TPTemplateNode *node in childNodes ) {
+ [expansion appendString:[node expansionUsingValues:_values]];
+ }
+
+ return expansion;
+}
+
+@end
View
@@ -0,0 +1,14 @@
+//
+// TPTemplateParser.h
+// Tipi
+//
+// Created by Chris Ross on 05/04/2012.
+// Copyright (c) 2012 hiddenMemory Ltd. All rights reserved.
+//
+
+#import <Foundation/Foundation.h>
+
+@interface TPTemplateParser : NSObject
++ (TPTemplateParser*)parserForFile:(NSString*)path;
+- (NSString*)expansionUsingValues:(NSDictionary*)values;
+@end
Oops, something went wrong.

0 comments on commit 2cfbc21

Please sign in to comment.