Chainable attributes for class + id DOM builder DSL
christhekeele opened this issue · comments
Running with the principle of least surprise, I'd expect the following to work:
$document.ready? do
DOM do
canvas.game!.lol.wut width: 500, height: 500
end.append_to $document.body
end
However, this generates
<canvas id="game" class="lol wut">{"width"=>500, "height"=>500}</canvas>
My reasoning here is when constructing DOM elements, especially divs, frequently the id and classes are the primary concern, and attributes second. (This is implied by id and class attributes being special-cased by the DSL.) Years of HAML may have reinforced this preference, but I find it to be quite pleasantly readable.
Contrast with:
$document.ready? do
DOM do
canvas(width: 500, height: 500).game!.lol.wut
end.append_to $document.body
end
which is what I must do at present.
I'm working on a PR, but I'm having trouble running the test suite, so I'm fumbling in the dark a little.
Looks like this belongs in Paggio. Moving there.