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:
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.
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:
Which given
splat: { sattr: 1, sattr2: 'derp' }
as the argument to the template renders as such: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.