Skip to content

Commit

Permalink
template compile expose model, context; update dynamic sample templat…
Browse files Browse the repository at this point in the history
…es to use model without model. prefix
  • Loading branch information
ajlopez committed May 27, 2012
1 parent bf4f16e commit eb3afc1
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion lib/template.js
Expand Up @@ -65,7 +65,7 @@ function compileToCode(text, values)
function compileTemplate($text) {
var $values = [];
var $code = compileToCode($text, $values);
var fun = new Function("writer", "__model", "__context", "$values", "with (__context) with (__model) {" + $code + "}");
var fun = new Function("writer", "model", "context", "$values", "with (context) with (model) {" + $code + "}");
return function(writer, model, context) { return fun(writer, model == null ? {} : model, context == null ? {} : context, $values); }
};

Expand Down
4 changes: 2 additions & 2 deletions samples/dynamic/customer-edit.tpl
@@ -1,6 +1,6 @@
<# include('header', { title: 'Edit Customer' }); #>
<div class='actions'>
<a href='/customer/${model.customer.id}'>View Customer</a>
<a href='/customer/${customer.id}'>View Customer</a>
</div>

<form method='post'>
Expand All @@ -9,7 +9,7 @@
Name
</div>
<div class="editor-field">
<input type='text' name='name' value='${model.customer.name}'/>
<input type='text' name='name' value='${customer.name}'/>
</div>
<div class="editor-field">
<input type='submit' value='Accept'/>
Expand Down
4 changes: 2 additions & 2 deletions samples/dynamic/customer-list.tpl
Expand Up @@ -9,8 +9,8 @@
<th>Id</th>
<th>Name</th>
</tr>
<# for (var n in model.customers) {
var customer = model.customers[n];
<# for (var n in customers) {
var customer = customers[n];
#>
<tr>
<td><a href='/customer/${customer.id}'>${customer.id}</a></td>
Expand Down
6 changes: 3 additions & 3 deletions samples/dynamic/customer-view.tpl
@@ -1,19 +1,19 @@
<# include('header', { title: 'Customer' }); #>
<div class='actions'>
<a href='/customer/edit/${model.customer.id}'>Edit Customer</a>
<a href='/customer/edit/${customer.id}'>Edit Customer</a>
</div>
<fieldset>
<div class="display-label">
Id
</div>
<div class="display-field">
${model.customer.id}
${customer.id}
</div>
<div class="display-label">
Name
</div>
<div class="display-field">
${model.customer.name}
${customer.name}
</div>
</fieldset>

Expand Down

0 comments on commit eb3afc1

Please sign in to comment.