diff --git a/src/hyperscript.nim b/src/hyperscript.nim index 953408b..9f72352 100644 --- a/src/hyperscript.nim +++ b/src/hyperscript.nim @@ -336,7 +336,6 @@ macro createElement(args: varargs[untyped]): untyped = var tag, style: string - classes: seq[string] attributes, children, events = newNimNode(nnkBracket) @@ -346,14 +345,6 @@ macro createElement(args: varargs[untyped]): untyped = (`first`, `second`) - func addClass(class: string) {.compileTime.} = - ## Helper that adds a new class. - classes.add class - func addClass(class: NimNode) {.compileTime.} = - ## Helper that adds a new class. - addClass class.strVal - - func addStyle(styles: auto) {.compileTime.} = ## Helper that adds styles. style.add styles @@ -389,8 +380,6 @@ macro createElement(args: varargs[untyped]): untyped = func addAttribute(key, val: auto) {.compileTime.} = ## Helper that adds a new attribute. case key: - of "class": - addClass val of "style": addStyle val else: @@ -424,7 +413,7 @@ macro createElement(args: varargs[untyped]): untyped = if len(selector) > 0: case selector[0]: of '.': - addClass selector[1..^1] + addAttribute "class", selector[1..^1] of '#': addAttribute "id", selector[1..^1] of '[': @@ -434,7 +423,7 @@ macro createElement(args: varargs[untyped]): untyped = debugEcho "unknown selector: " & selector - # Process selector and update tag, id, classes and attributes + # Process selector and update tag and attributes var j = selector.find({'.', '#', '['}) if j == -1: # Only a tag @@ -476,9 +465,6 @@ macro createElement(args: varargs[untyped]): untyped = addChild arg - if len(classes) > 0: - addTupleExpr(attributes, "class", join(classes, " ")) - if len(style) > 0: addTupleExpr(attributes, "style", style.strip) diff --git a/tests/tests.nim b/tests/tests.nim index aa32f92..2b16a9c 100644 --- a/tests/tests.nim +++ b/tests/tests.nim @@ -154,10 +154,10 @@ suite "Using selector notation": check h("div.header").tag == "div" check h("div.header").attr("class") == "header" - test "two classes get joined": + test "the last given class takes precedence": check h("div.header.note") is HTMLNode check h("div.header.note").tag == "div" - check h("div.header.note").attr("class") == "header note" + check h("div.header.note").attr("class") == "note" test "can indicate an attribute": @@ -201,11 +201,11 @@ suite "Using selector notation": check h("div.header", class = "note") is HTMLNode check h("div.header", class = "note").tag == "div" - check h("div.header", class = "note").attr("class") == "header note" + check h("div.header", class = "note").attr("class") == "note" check h("a.link[href=/]", {class: "selected"}, "Home") is HTMLNode check h("a.link[href=/]", {class: "selected"}, "Home").tag == "a" - check h("a.link[href=/]", {class: "selected"}, "Home").attr("class") == "link selected" + check h("a.link[href=/]", {class: "selected"}, "Home").attr("class") == "selected" check h("a.link[href=/]", {class: "selected"}, "Home").attr("href") == "/" check h("a.link[href=/]", {class: "selected"}, "Home").text == "Home"