lib/rid/generators/list/templates/list.js in rid-0.3.1 vs lib/rid/generators/list/templates/list.js in rid-0.4.0

- old
+ new

@@ -1,29 +1,31 @@ function(head, req) { - provides("html", function() { - var header = '<html><head><link rel="stylesheet" href="../../stylesheets/application.css" type="text/css" media="screen" charset="utf-8"></head><body><h1>Listing <%= pluralized_model_name.humanize %></h1>'; + // !code mustache.js + // !json templates/layout.mustache + // !json templates/<%= pluralized_model_name %>/index.mustache - header += '<p><a href="../../_show/<%= model_name %>/">New <%= model_name.humanize %></a></p>'; - - header += '<table><tr>'; + provides("html", function() { + var view = { + title: "Listing <%= pluralized_model_name.humanize %>", + body: { + rows: function() { + var rows = []; + var row; + while (row = getRow()) { + rows.push({ <% attributes.each do |attribute| -%> - header += '<th><%= attribute.humanize %></th>'; + <%= attribute %>: row.value['<%= attribute %>'], <% end -%> - header += '<th></th>'; - header += '</tr>'; - send(header); + id: row.id + }); + } - var row; - while (row = getRow()) { - var body = '<tr>'; -<% attributes.each do |attribute| -%> - body += '<td>' + row.value['<%= attribute %>'] + '</td>'; -<% end -%> - body += '<td><a href="../../_show/<%= model_name %>/' + row.id + '" alt="Show <%= model_name.humanize %>">Show</a></td>'; - body += '</tr>'; - send(body); - } + return rows; + } + } + }; - var tail = '</table></body></html>'; - return tail; + Mustache.to_html(templates.layout, view, { body: templates.<%= pluralized_model_name %>.index }, function(line) { + send(line + "\n"); + }); }); }