Skip to content

Commit

Permalink
Added equalsString operation for "if" markers.
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.cocoasourcecode.com/MGTemplateEngine@70 fad7f400-0e54-0410-bf1d-e368f886e4d4
  • Loading branch information
mattgemmell committed Aug 5, 2010
1 parent fa877d6 commit 6a5c972
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
13 changes: 13 additions & 0 deletions MGTemplateStandardMarkers.m
Expand Up @@ -389,6 +389,19 @@ - (NSObject *)markerEncountered:(NSString *)marker withArguments:(NSArray *)args
argTrue = (num1 <= num2);
} else if ([op isEqualToString:@"\%"]) {
argTrue = ((num1 % num2) > 0);
} else if ([op isEqualToString:@"equalsstring"]) {
NSObject *firstVal = [engine resolveVariable:firstArg];
NSObject *secondVal = [engine resolveVariable:secondArg];
if (!firstVal) {
firstVal = firstArg;
}
if (!secondVal) {
secondVal = secondArg;
}
if (firstVal && secondVal) {
//NSLog(@"%@ %@", [NSString stringWithFormat:@"%@", firstVal], [NSString stringWithFormat:@"%@", secondVal]);
argTrue = [[NSString stringWithFormat:@"%@", firstVal] isEqualToString:[NSString stringWithFormat:@"%@", secondVal]];
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion sample_template.txt
Expand Up @@ -5,7 +5,7 @@ It's currently {% now | date_format: "dd MMM yyyy 'at' HH:mm:ss" %}
Nested variable: {{ foo.bar }}

{% for dude in guys %}
Current dude is {{ dude | uppercase }}...
Current dude is {{ dude | uppercase }}...{% if dude equalsString "matt" %} AWESOME!{% /if %}
{% if currentLoop.currentIndex == 0 %}
(the best!) {% comment %} Should only happen for Matt {% /comment %}
{% for 1 to 5 %}*{% /for %}
Expand Down

0 comments on commit 6a5c972

Please sign in to comment.