Permalink
Browse files

Added equalsString operation for "if" markers.

git-svn-id: http://svn.cocoasourcecode.com/MGTemplateEngine@70 fad7f400-0e54-0410-bf1d-e368f886e4d4
  • Loading branch information...
mattgemmell
mattgemmell committed Aug 5, 2010
1 parent fa877d6 commit 6a5c97228a14df7c4b8e22f18979dd26ae10aa0f
Showing with 14 additions and 1 deletion.
  1. +13 −0 MGTemplateStandardMarkers.m
  2. +1 −1 sample_template.txt
@@ -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]];
+ }
}
}
View
@@ -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 %}

0 comments on commit 6a5c972

Please sign in to comment.