Skip to content

Commit

Permalink
Pass failing tests for #46
Browse files Browse the repository at this point in the history
  • Loading branch information
groue committed Mar 5, 2013
1 parent e2e4442 commit 37128e4
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 30 deletions.
42 changes: 20 additions & 22 deletions src/classes/GRMustacheBuffer.m
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,16 @@ - (NSString *)appendString:(NSString *)string contentType:(GRMustacheContentType
}

switch (inputType) {
case GRMustacheBufferInputTypeUserContent:
case GRMustacheBufferInputTypeContent:
if (string.length > 0) {
if (self.prefix) {
[self appendSafeString:self.prefix inputType:GRMustacheBufferInputTypeBlankPrefix];
if (_needsPrefixPrepending) {
[self appendSafeString:self.prefix inputType:GRMustacheBufferInputTypeBlankPrefix];
_needsPrefixPrepending = NO;
} else {
// noop for breakpoing
_needsPrefixPrepending = NO;
}
self.prefix = nil;
}
_swallowsBlankEndOfLine = NO;
Expand All @@ -111,19 +117,15 @@ - (NSString *)appendString:(NSString *)string contentType:(GRMustacheContentType
}
break;

case GRMustacheBufferInputTypeContent:
if (self.prefix) {
[self appendSafeString:self.prefix inputType:GRMustacheBufferInputTypeBlankPrefix];
self.prefix = nil;
}
_swallowsBlankEndOfLine = NO;
[self appendSafeString:string inputType:inputType];
return string;
break;

case GRMustacheBufferInputTypeContentEndOfLine:
if (self.prefix) {
[self appendSafeString:self.prefix inputType:GRMustacheBufferInputTypeBlankPrefix];
if (_needsPrefixPrepending) {
[self appendSafeString:self.prefix inputType:GRMustacheBufferInputTypeBlankPrefix];
_needsPrefixPrepending = NO;
} else {
// noop for breakpoing
_needsPrefixPrepending = NO;
}
self.prefix = nil;
}
_swallowsBlankEndOfLine = YES;
Expand All @@ -132,19 +134,18 @@ - (NSString *)appendString:(NSString *)string contentType:(GRMustacheContentType
break;

case GRMustacheBufferInputTypeBlankLine:
self.prefix = nil;
_needsPrefixPrepending = NO;
_swallowsBlankEndOfLine = YES;
[self appendSafeString:string inputType:inputType];
return string;
break;

case GRMustacheBufferInputTypeBlankEndOfLine:
if (_swallowsBlankEndOfLine) {
_needsPrefixPrepending = NO;
return @"";
} else {
if (self.prefix) {
[self appendSafeString:self.prefix inputType:GRMustacheBufferInputTypeBlankPrefix];
self.prefix = nil;
}
_swallowsBlankEndOfLine = YES;
[self appendSafeString:string inputType:inputType];
return string;
Expand All @@ -154,18 +155,15 @@ - (NSString *)appendString:(NSString *)string contentType:(GRMustacheContentType
case GRMustacheBufferInputTypeBlankPrefix:
self.prefix = string;
_swallowsBlankEndOfLine = YES;
_needsPrefixPrepending = YES;
return string;
break;

case GRMustacheBufferInputTypeBlankSuffix:
if (_swallowsBlankEndOfLine) {
_needsPrefixPrepending = NO;
return @"";
} else {
if (self.prefix) {
[self appendSafeString:self.prefix inputType:GRMustacheBufferInputTypeBlankPrefix];
self.prefix = nil;
}
_swallowsBlankEndOfLine = NO;
[self appendSafeString:string inputType:inputType];
return string;
}
Expand Down
2 changes: 1 addition & 1 deletion src/classes/GRMustacheBuffer_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
#import "GRMustacheConfiguration_private.h"

typedef NS_ENUM(NSInteger, GRMustacheBufferInputType) {
GRMustacheBufferInputTypeUserContent,
GRMustacheBufferInputTypeContent,
GRMustacheBufferInputTypeContentEndOfLine,
GRMustacheBufferInputTypeBlankLine,
Expand All @@ -42,6 +41,7 @@ typedef NS_ENUM(NSInteger, GRMustacheBufferInputType) {
GRMustacheContentType _contentType;
NSString *_prefix;
BOOL _swallowsBlankEndOfLine;
BOOL _needsPrefixPrepending;
}

/**
Expand Down
9 changes: 9 additions & 0 deletions src/classes/GRMustacheCompiler.m
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,15 @@ - (BOOL)parser:(GRMustacheParser *)parser shouldContinueAfterParsingToken:(GRMus
break;


case GRMustacheTokenTypeContentEndOfLine:
// Parser validation
NSAssert(token.templateSubstring.length > 0, @"WTF parser?");

// Success: append GRMustacheTextComponent
[_currentComponents addObject:[GRMustacheTextComponent textComponentWithString:token.templateSubstring inputType:GRMustacheBufferInputTypeContentEndOfLine]];
break;


case GRMustacheTokenTypeBlankLine:
// Parser validation
NSAssert(token.templateSubstring.length > 0, @"WTF parser?");
Expand Down
2 changes: 1 addition & 1 deletion src/classes/GRMustacheParser.m
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ - (void)parseTemplateString:(NSString *)templateString templateID:(id)templateID
{
if (start != (i+1)) {
// Content
GRMustacheToken *token = [GRMustacheToken tokenWithType:GRMustacheTokenTypeContent
GRMustacheToken *token = [GRMustacheToken tokenWithType:GRMustacheTokenTypeContentEndOfLine
templateString:templateString
templateID:templateID
line:lineNumber
Expand Down
2 changes: 1 addition & 1 deletion src/classes/GRMustacheTag.m
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ - (BOOL)renderContentType:(GRMustacheContentType)requiredContentType inBuffer:(G
// promote
renderingContentType = GRMustacheContentTypeHTML;
}
rendering = [buffer appendString:rendering contentType:renderingContentType inputType:GRMustacheBufferInputTypeUserContent];
rendering = [buffer appendString:rendering contentType:renderingContentType inputType:GRMustacheBufferInputTypeContent];

// Tag delegates post-rendering callbacks

Expand Down
15 changes: 10 additions & 5 deletions src/classes/GRMustacheToken_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,16 @@
* The kinds of tokens
*/
typedef NS_ENUM(NSInteger, GRMustacheTokenType) {
/**
* TODO
*/
GRMustacheTokenTypeContent,

/**
* TODO
*/
GRMustacheTokenTypeContentEndOfLine,

/**
* TODO
*/
Expand All @@ -49,11 +59,6 @@ typedef NS_ENUM(NSInteger, GRMustacheTokenType) {
*/
GRMustacheTokenTypeBlankSuffix,

/**
* TODO
*/
GRMustacheTokenTypeContent,

/**
* The kind of tokens representing escaped variable tags such as `{{name}}`.
*/
Expand Down

0 comments on commit 37128e4

Please sign in to comment.