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 7, 2013
1 parent f6a4294 commit e260a2e
Show file tree
Hide file tree
Showing 8 changed files with 103 additions and 192 deletions.
79 changes: 39 additions & 40 deletions src/classes/GRMustacheBuffer.m
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ - (id)initWithContentType:(GRMustacheContentType)contentType
self = [super init];
if (self) {
_contentType = contentType;
_swallowsBlankEndOfLine = YES;
_atLineStart = YES;
}
return self;
}
Expand All @@ -100,74 +100,73 @@ - (NSString *)appendString:(NSString *)string contentType:(GRMustacheContentType
case GRMustacheBufferInputTypeContent:
if (string.length > 0) {
if (self.prefix) {
if (_needsPrefixPrepending) {
[self appendSafeString:self.prefix inputType:GRMustacheBufferInputTypeBlankPrefix];
_needsPrefixPrepending = NO;
} else {
// noop for breakpoing
_needsPrefixPrepending = NO;
}
[self appendSafeString:self.prefix inputType:GRMustacheBufferInputTypeBlank];
self.prefix = nil;
}
_swallowsBlankEndOfLine = NO;
[self appendSafeString:string inputType:inputType];
_atLineStart = NO;
return string;
} else {
if (_atLineStart) {
self.prefix = @"";
_atLineStart = NO;
}
return @"";
}
break;

case GRMustacheBufferInputTypeContentEndOfLine:
if (self.prefix) {
if (_needsPrefixPrepending) {
[self appendSafeString:self.prefix inputType:GRMustacheBufferInputTypeBlankPrefix];
_needsPrefixPrepending = NO;
} else {
// noop for breakpoing
_needsPrefixPrepending = NO;
}
[self appendSafeString:self.prefix inputType:GRMustacheBufferInputTypeBlank];
self.prefix = nil;
}
_swallowsBlankEndOfLine = YES;
[self appendSafeString:string inputType:inputType];
_atLineStart = YES;
return string;
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 @"";
case GRMustacheBufferInputTypeBlank:
if (_atLineStart) {
self.prefix = string;
_atLineStart = NO;
return string;
} else if (self.prefix) {
self.prefix = [self.prefix stringByAppendingString:string];
return string;
} else {
_swallowsBlankEndOfLine = YES;
[self appendSafeString:string inputType:inputType];
return string;
}
break;

case GRMustacheBufferInputTypeBlankPrefix:
self.prefix = string;
_swallowsBlankEndOfLine = YES;
_needsPrefixPrepending = YES;
return string;
break;

case GRMustacheBufferInputTypeBlankSuffix:
if (_swallowsBlankEndOfLine) {
_needsPrefixPrepending = NO;
case GRMustacheBufferInputTypeBlankEndOfLine:
if (_atLineStart) {
self.prefix = nil;
[self appendSafeString:string inputType:inputType];
_atLineStart = YES;
return string;
} else if (self.prefix) {
self.prefix = nil;
_atLineStart = YES;
return @"";
} else {
self.prefix = nil;
[self appendSafeString:string inputType:inputType];
_atLineStart = YES;
return string;
}
break;

default:
break;
}
}

- (void)flush
{
if (self.prefix) {
[self appendSafeString:self.prefix inputType:GRMustacheBufferInputTypeBlank];
self.prefix = nil;
}
}

Expand Down
12 changes: 7 additions & 5 deletions src/classes/GRMustacheBuffer_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,8 @@
typedef NS_ENUM(NSInteger, GRMustacheBufferInputType) {
GRMustacheBufferInputTypeContent,
GRMustacheBufferInputTypeContentEndOfLine,
GRMustacheBufferInputTypeBlankLine,
GRMustacheBufferInputTypeBlank,
GRMustacheBufferInputTypeBlankEndOfLine,
GRMustacheBufferInputTypeBlankPrefix,
GRMustacheBufferInputTypeBlankSuffix,
};

/**
Expand All @@ -40,8 +38,7 @@ typedef NS_ENUM(NSInteger, GRMustacheBufferInputType) {
@private
GRMustacheContentType _contentType;
NSString *_prefix;
BOOL _swallowsBlankEndOfLine;
BOOL _needsPrefixPrepending;
BOOL _atLineStart;
}

/**
Expand All @@ -64,4 +61,9 @@ typedef NS_ENUM(NSInteger, GRMustacheBufferInputType) {
*/
- (NSString *)appendString:(NSString *)string contentType:(GRMustacheContentType)contentType inputType:(GRMustacheBufferInputType)inputType GRMUSTACHE_API_INTERNAL;

/**
* TODO
*/
- (void)flush GRMUSTACHE_API_INTERNAL;

@end
21 changes: 2 additions & 19 deletions src/classes/GRMustacheCompiler.m
Original file line number Diff line number Diff line change
Expand Up @@ -252,12 +252,12 @@ - (BOOL)parser:(GRMustacheParser *)parser shouldContinueAfterParsingToken:(GRMus
break;


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

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

case GRMustacheTokenTypeBlankEndOfLine:
Expand All @@ -268,23 +268,6 @@ - (BOOL)parser:(GRMustacheParser *)parser shouldContinueAfterParsingToken:(GRMus
[_currentComponents addObject:[GRMustacheTextComponent textComponentWithString:token.templateSubstring inputType:GRMustacheBufferInputTypeBlankEndOfLine]];
break;

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

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

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

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


case GRMustacheTokenTypeEscapedVariable: {
// Expression validation
BOOL invalidExpression;
Expand Down
Loading

0 comments on commit e260a2e

Please sign in to comment.