Permalink
Browse files

NuMarkupOperators generate boolean attributes when the attribute

value is t or nil.
  • Loading branch information...
1 parent 7a99a85 commit e673cdb14049cd22aeb52757b9d9e98cd8d1101c @timburks committed Mar 15, 2013
Showing with 78 additions and 63 deletions.
  1. +12 −2 objc/Nu.m
  2. +66 −61 test/test_markup.nu
View
@@ -11332,6 +11332,9 @@ - (void) setEmpty:(BOOL) e
- (id) callWithArguments:(id)cdr context:(NSMutableDictionary *)context
{
+ NuSymbolTable *symbolTable = [context objectForKey:SYMBOLS_KEY];
+ id t_symbol = [symbolTable symbolWithString:@"t"];
+
NSMutableString *body = [NSMutableString string];
NSMutableString *attributes = [NSMutableString string];
@@ -11358,8 +11361,15 @@ - (id) callWithArguments:(id)cdr context:(NSMutableDictionary *)context
if (cursor && (cursor != [NSNull null])) {
id value = [[cursor car] evalWithContext:context];
id attributeName = [[item labelName] stringByReplacingOccurrencesOfString:@"=" withString:@":"];
- id stringValue = [value isEqual:[NSNull null]] ? @"" : [value stringValue];
- [attributes appendFormat:@" %@=\"%@\"", attributeName, stringValue];
+ if ([value isEqual:[NSNull null]]) {
+ // omit attributes that are "false"
+ } else if ([value isEqual:t_symbol]) {
+ // boolean attributes with "true" are written without values
+ [attributes appendFormat:@" %@", attributeName];
+ } else {
+ id stringValue = [value isEqual:[NSNull null]] ? @"" : [value stringValue];
+ [attributes appendFormat:@" %@=\"%@\"", attributeName, stringValue];
+ }
}
}
else {
View
@@ -4,64 +4,69 @@
;; Copyright (c) 2012 Tim Burks, Radtastical Inc.
(class TestMarkup is NuTestCase
-
- (- testMarkup is
- (set markup (&html (&body (&h1 "Hello!")
- (&p "This is a test")
- (&p "This is a second paragraph"))))
- (set golden "<!DOCTYPE html><html><body><h1>Hello!</h1><p>This is a test</p><p>This is a second paragraph</p></body></html>")
- (assert_equal golden markup))
-
- (- testAttributes is
- (set markup (&magic attribute:123 "hello"))
- (set golden "<magic attribute=\"123\">hello</magic>")
- (assert_equal golden markup))
-
- (- testHTML is
- (set markup (&html))
- (set golden "<!DOCTYPE html><html></html>")
- (assert_equal golden markup))
-
- (- testVoidElements is
- (set voidElements (array "area"
- "base"
- "br"
- "col"
- "command"
- "embed"
- "hr"
- "img"
- "input"
- "keygen"
- "link"
- "meta"
- "param"
- "source"
- "track"
- "wbr"))
- (voidElements each:
- (do (element)
- (set markup (eval (parse "(&#{element})")))
- (set golden "<#{element}/>")
- (assert_equal golden markup)))
- (set nonVoidElements (array "div"
- "span"
- "frame"
- "strong"
- "p"))
- (nonVoidElements each:
- (do (element)
- (set markup (eval (parse "(&#{element})")))
- (set golden "<#{element}></#{element}>")
- (assert_equal golden markup))))
-
- (- testEmbeddedClassAndIdProperties is
- (set markup (&div.class1.class2.class3))
- (set golden "<div class=\"class1\" class=\"class2\" class=\"class3\"></div>")
- (assert_equal golden markup)
- (set markup (&div#id1#id2#id3))
- (set golden "<div id=\"id1\" id=\"id2\" id=\"id3\"></div>")
- (assert_equal golden markup)
- (set markup (&div#myid.myclass))
- (set golden "<div id=\"myid\" class=\"myclass\"></div>")
- (assert_equal golden markup)))
+
+ (- testMarkup is
+ (set markup (&html (&body (&h1 "Hello!")
+ (&p "This is a test")
+ (&p "This is a second paragraph"))))
+ (set golden "<!DOCTYPE html><html><body><h1>Hello!</h1><p>This is a test</p><p>This is a second paragraph</p></body></html>")
+ (assert_equal golden markup))
+
+ (- testAttributes is
+ (set markup (&magic attribute:123 "hello"))
+ (set golden "<magic attribute=\"123\">hello</magic>")
+ (assert_equal golden markup))
+
+ (- testHTML is
+ (set markup (&html))
+ (set golden "<!DOCTYPE html><html></html>")
+ (assert_equal golden markup))
+
+ (- testBooleanAttributes is
+ (set markup (&p foo:(eq 1 1)) bar:(eq 1 0))
+ (set golden "<p foo></p>")
+ (assert_equal golden markup))
+
+ (- testVoidElements is
+ (set voidElements (array "area"
+ "base"
+ "br"
+ "col"
+ "command"
+ "embed"
+ "hr"
+ "img"
+ "input"
+ "keygen"
+ "link"
+ "meta"
+ "param"
+ "source"
+ "track"
+ "wbr"))
+ (voidElements each:
+ (do (element)
+ (set markup (eval (parse "(&#{element})")))
+ (set golden "<#{element}/>")
+ (assert_equal golden markup)))
+ (set nonVoidElements (array "div"
+ "span"
+ "frame"
+ "strong"
+ "p"))
+ (nonVoidElements each:
+ (do (element)
+ (set markup (eval (parse "(&#{element})")))
+ (set golden "<#{element}></#{element}>")
+ (assert_equal golden markup))))
+
+ (- testEmbeddedClassAndIdProperties is
+ (set markup (&div.class1.class2.class3))
+ (set golden "<div class=\"class1\" class=\"class2\" class=\"class3\"></div>")
+ (assert_equal golden markup)
+ (set markup (&div#id1#id2#id3))
+ (set golden "<div id=\"id1\" id=\"id2\" id=\"id3\"></div>")
+ (assert_equal golden markup)
+ (set markup (&div#myid.myclass))
+ (set golden "<div id=\"myid\" class=\"myclass\"></div>")
+ (assert_equal golden markup)))

0 comments on commit e673cdb

Please sign in to comment.