title: how to run ruby in haml in javascript definition?
body: <ul>
  <li>how can I run ruby code inside javascript in haml?</li>
  <li>if I use <code>var = #{message}</code> in my example I get <code>undefined local variable or method message</code></li>
  <li>when I move <code>- message = 'it works'</code> above <code>:javascript</code> everything works fine</li>
  </ul>
  
  <p>I want to run <strong>iteration</strong> <code>.each</code> inside <code>:javascript</code>. See the last code sample for what I need in final javascript code. Where I need to loop few ruby variables (or one hash of hashes of hashes?) to get this. Data (='basics') can have few elemenets. It can have children with few elements etc.</p>
  
  <p>SO this haml code </p>
  
  <pre><code>%html
    %head
      :javascript
        $(document).ready(function() {
          - message = 'it works'
              var = message
  
          });
  %body
      - message2 = 'hi'
      = message2
      %div{:id =&gt;"jstree"}
  </code></pre>
  
  <p>gives me this html code</p>
  
  <pre><code>&lt;html&gt;
    &lt;head&gt;
      &lt;script type='text/javascript'&gt;
        //&lt;![CDATA[
          $(document).ready(function() {
              - message = 'hi'
              var = message
  
          });
        //]]&gt;
      &lt;/script&gt;
    &lt;/head&gt;
    &lt;body&gt;
      hi
      &lt;div id='jstree'&gt;&lt;/div&gt;
    &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>The final javascript code I want to produce using haml is the javascript variable</p>
  
  <pre><code>var data = [{
         data: "basics",
         attr: {},
          children: [
           {data: "login", attr: {run: "run"},
             children: [                   
             {data: "login", attr: {}}
            ]
           } ,
           {data: "Academic Year", attr: {run: "run"},
            children: [                   
             {data: "login", attr: {}},
             {data: "Academic Year", attr: {filter: "mini", SOF: "yes"}}
            ]
  
           }
          ]
        }];
  </code></pre>