title: Ruby how to display a json in haml
body: <p>I'm new to ruby and i want to parse a json-File to haml.</p>
  
  <p>my idea was to parse a jsonarray:</p>
  
  <pre><code>{
      "theme": "default",
      "metatags":{
          "title":"Test",
          "charset":"utf-8"
      },
      "body":{
          "p":{
              "class": "test",
              "text": "P"
          },
          "div": "DIV",
          "span": "SPAN"
      }
  }
  </code></pre>
  
  <p>to a haml file. With the json code i want to display my htmlfile:</p>
  
  <pre><code>&lt;body&gt;
  &lt;p class="text"&gt;P&lt;/p&gt;
  &lt;div&gt;DIV&lt;/div&gt;
  &lt;span&gt;SPAN&lt;/span&gt;
  &lt;/body&gt;
  </code></pre>
  
  <p>my app.rb looks like this:</p>
  
  <pre><code>require 'sinatra'
  require 'json_builder'
  
  file = open('configs/evolutio.json')
  json = file.read
  user_settings = JSON.parse(json)
  
  set :user_settings, user_settings
  
  get '/' do
      @body = user_settings["body"]
      haml :"templates/#{user_settings["theme"]}/index"
  end
  </code></pre>
  
  <p>and my index.haml like this:</p>
  
  <pre><code>%html
      %head
          %title #{options.user_settings["metatags"]["title"]}
          %meta{'http-equiv' =&gt; 'Content-Type', :content =&gt; 'text/html'}
          %meta{'charset' =&gt; options.user_settings["metatags"]["charset"]}
      %body
          - cnt = 1
          - @body.each do |tag|
              #{tag.inspect} &lt;br&gt;
              - haml_tag tag[0], tag[1]
  </code></pre>
  
  <p>my html code looks like this:</p>
  
  <pre><code>&lt;html&gt;
    &lt;head&gt;
      &lt;title&gt;Test&lt;/title&gt;
      &lt;meta content='text/html' http-equiv='Content-Type'&gt;
      &lt;meta charset='utf-8'&gt;
    &lt;/head&gt;
    &lt;body&gt;
      ["p", {"class"=&gt;"test", "text"=&gt;"P"}] &lt;br&gt;
      &lt;p class='test' text='P'&gt;&lt;/p&gt;
      ["div", "DIV"] &lt;br&gt;
      &lt;div&gt;DIV&lt;/div&gt;
      ["span", "SPAN"] &lt;br&gt;
      &lt;span&gt;SPAN&lt;/span&gt;
    &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>