Skip to content

Commit

Permalink
markup enhancements
Browse files Browse the repository at this point in the history
- accept numbers (NSNumbers) as well as strings (actually anything that responds to stringValue).
- accept arrays of strings and automatically expand them.
  • Loading branch information
Tim Burks committed Jan 24, 2010
1 parent 2d85f3e commit 897b4e3
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Nukefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
(case SYSTEM
("Darwin"
(set @arch (list "i386"))
(set @cflags "-g -fobjc-gc -DDARWIN")
(set @cflags "-g -std=gnu99 -fobjc-gc -DDARWIN")
(set @ldflags "-framework Foundation -framework Nu -levent -lcrypto"))
("Linux"
(set @arch (list "i386"))
Expand Down
14 changes: 12 additions & 2 deletions objc/markup.m
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#import <Foundation/Foundation.h>


@interface NuOperator : NSObject
{
}
Expand Down Expand Up @@ -65,7 +64,18 @@ - (id) callWithArguments:(id)cdr context:(NSMutableDictionary *)context
}
}
else {
[body appendString:[item evalWithContext:context]];
id evaluatedItem = [item evalWithContext:context];
if ([evaluatedItem isKindOfClass:[NSString class]]) {
[body appendString:evaluatedItem];
}
else if ([evaluatedItem isKindOfClass:[NSArray class]]) {
int max = [evaluatedItem count];
for (int i = 0; i < max; i++) {
[body appendString:[evaluatedItem objectAtIndex:i]];
}
} else {
[body appendString:[evaluatedItem stringValue]];
}
}
if (cursor && (cursor != [NSNull null]))
cursor = [cursor cdr];
Expand Down
4 changes: 2 additions & 2 deletions test/test_markup.nu
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@
(assert_equal "<body/>" (&body))
(assert_equal "<body/>" (&body incomplete:))
(assert_equal "<body attr=\"val\"/>" (&body attr:"val"))
(assert_equal "<!DOCTYPE html>\n<html><body this=\"is\" a=\"test\">hello, world</body></html>" (&html (&body this:"is" a:"test" "hello," " world")))))

(assert_equal "<!DOCTYPE html>\n<html><body this=\"is\" a=\"test\">hello, world</body></html>" (&html (&body this:"is" a:"test" "hello," " world")))
(assert_equal "<body>abc123</body>" (&body (array "a" "b" "c") 123))))

0 comments on commit 897b4e3

Please sign in to comment.