creationix / haml-js

Haml ported to server-side Javascript. This is a traditional server-side templating language. Tested with node-js
MIT License
902 stars 110 forks source link

Attribute splats #69

Closed jaen closed 8 years ago

jaen commented 12 years ago

I've had a JS object with some key-value pairs I wanted to put as attributes on tags, but it seemed that only way to do so is to manually maintain attributes for all the k-v pairs I have, which I thought was pretty inelegant and dumb maintenance-wise, so I went ahead and implemented splat syntax for attributes in my fork of ruby-haml-js.

It works like this:

%p{ attr: 'val', *splat }
    hurr durr

Which given splat: { sattr: 1, sattr2: 'derp' } as the argument to the template renders as such:

<p attr="val" sattr="1", sattr2="derp">
    hurr durr
</p>

I'm not sure if there is any need for such functionality and if it is a safe thing to do - I mean I use the escape func, but since the rendering of the splats has to be done client-side it may be can be tampered with somehow? But if it feels lik a good addition, I can try to clean it up and port it back to the main library.

aaronblohowiak commented 12 years ago

Are there tests? Is it in its own branch?

jaen commented 12 years ago

At the moment no, because i just hacked it to get it working pronto, but if you deem such feature interesting I can code it clean with tests et all.