Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multi-line attribute values in HAML

I am using KnockoutJS which uses a json string within the data-bind attribute to indicate binding information. I also like using HAML.

This string can quickly become quite long, for example:-

%ul#task-list.unstyled{"data-bind" => "template: { name : 'taskHierarchy', foreach : contexts.children(), afterAdd: function(elem) { $(elem).hide().slideDown() } }"}

A solution is to use the :plain filter as follows (slightly different from above):-

:plain
  <div data-bind = "template: {
    name: 'twoLineResourceTemplate',
    foreach: resources,
    afterAdd: function(elem) { $(elem).hide().slideDown() }
  }">
  </div>

Is there a neater way to do this using HAML constructs instead of the filter?

I have tried using the pipe character but it does not seem to work for HAML attributes.

Thanks!

like image 358
vaughan Avatar asked Sep 01 '11 09:09

vaughan


1 Answers

I tried the pipe notation and it works for me:

%ul#task-list.unstyled{"data-bind" => |
"template: { "                      + |
"name : 'taskHierarchy',"           + |
"foreach : contexts.children(),"    + |
"afterAdd: function(elem) {"        + |
"$(elem).hide().slideDown()"        + |
"} }"}                                |
like image 95
christiaanderidder Avatar answered Oct 17 '22 16:10

christiaanderidder