Browse files

Support for nested/grouped attributes.

a href:'/login\', data: {icon:'arrow-r', iconpos:'right'}, 'Login' => <a href="/login" data-icon="arrow-r" data-iconos="right">Login</a>
  • Loading branch information...
1 parent 16dafaa commit b5ec938fe31d39c55b6960d969c7e0c425e5ca83 @colinta colinta committed with Sep 19, 2011
Showing with 8 additions and 3 deletions.
  1. +8 −3 src/coffeekup.coffee
View
11 src/coffeekup.coffee
@@ -140,15 +140,20 @@ skeleton = (data = {}) ->
text c
text '"'
- render_attrs: (obj) ->
+ render_attrs: (obj, prefix = '') ->
for k, v of obj
# true is rendered as `selected="selected"`.
if typeof v is 'boolean' and v
v = k
+
+ if typeof v is 'object'
+ # if you have a lot of data attributes, it gets repetitive to keep typing 'data-'
+ # plus, it looks really good to group them together, e.g. data: { icon: 'gear', iconpos: 'right' }
+ @render_attrs(v, prefix + k + '-')
# undefined, false and null result in the attribute not being rendered.
- if v
+ else if v
# strings, numbers, objects, arrays and functions are rendered "as is".
- text " #{k}=\"#{@esc(v)}\""
+ text " #{prefix + k}=\"#{@esc(v)}\""
render_contents: (contents) ->
switch typeof contents

0 comments on commit b5ec938

Please sign in to comment.