Skip to content

Commit

Permalink
I really think this is a bad idea, but let's support implicit context…
Browse files Browse the repository at this point in the history
  • Loading branch information
Bertrand Guiheneuf committed Mar 24, 2014
1 parent 2a4d061 commit cf21d52
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/handlebars-objc/helpers/HBBuiltinHelpersRegistry.m
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,13 @@ + (void) registerEachHelper
{
HBHelperBlock eachBlock = ^(HBHelperCallingInfo* callingInfo) {

id expression = callingInfo[0];
id expression = nil;
if ([callingInfo.positionalParameters count] > 0) {
expression = callingInfo[0];
} else {
expression = callingInfo.context;
}

HBDataContext* currentData = callingInfo.data;

if (expression && [HBHelperUtils isEnumerableByIndex:expression]) {
Expand Down
10 changes: 10 additions & 0 deletions src/handlebars-objcTests/HBTestBuiltinBlockHelpers.m
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,16 @@ - (void) testEachWithNestedAtLast
XCTAssert(!error, @"evaluation should not generate an error");
}

// each on implicit context
- (void) testEachOnImplicitContext
{
NSError* error = nil;
id string = @"{{#each}}{{text}}! {{/each}}cruel world!";
id hash = @[ @{ @"text": @"goodbye" } ,@{ @"text": @"Goodbye" } ,@{ @"text": @"GOODBYE" } ];
XCTAssertEqualObjects([HBHandlebars renderTemplateString:string withContext:hash error:&error],
@"goodbye! Goodbye! GOODBYE! cruel world!");
XCTAssert(!error, @"evaluation should not generate an error");
}

// #log
- (void) testLog
Expand Down

0 comments on commit cf21d52

Please sign in to comment.