Permalink
Browse files

Fix bug where "this" context got lost inside of :each and :if blocks.

  • Loading branch information...
1 parent 8ba8077 commit 908480ed5d98fb8d246d7a464c1ed65e40cabcfd @creationix committed Feb 11, 2010
Showing with 22 additions and 2 deletions.
  1. +2 −2 lib/haml.js
  2. +6 −0 test/nested_context.haml
  3. +6 −0 test/nested_context.html
  4. +8 −0 test/nested_context.js
View
4 lib/haml.js
@@ -251,7 +251,7 @@ if (exports) {
'if (' + avar + '.hasOwnProperty(' + ivar + ')) { ' +
vvar + ' = ' + avar + '[' + ivar + ']; ' +
rvar + '.push(\n' + (this.render_contents() || "''") + '\n); ' +
- '} } return ' + rvar + '.join(""); }())';
+ '} } return ' + rvar + '.join(""); }).call(this)';
}
},
@@ -263,7 +263,7 @@ if (exports) {
return '(function () { ' +
'if (' + condition + ') { ' +
'return (\n' + (this.render_contents() || '') + '\n);' +
- '} else { return ""; } }())';
+ '} else { return ""; } }).call(this)';
}
},
View
6 test/nested_context.haml
@@ -0,0 +1,6 @@
+%p= this.name
+#main
+ :each item in items
+ .item= this.name + ": " + item
+ :if items
+ #cool= this.name
View
6 test/nested_context.html
@@ -0,0 +1,6 @@
+<p>Frank
+</p><div id="main"><div class="item">Frank: 1
+</div><div class="item">Frank: 2
+</div><div class="item">Frank: 3
+</div><div id="cool">Frank
+</div></div>
View
8 test/nested_context.js
@@ -0,0 +1,8 @@
+{
+ context: {
+ name: "Frank"
+ },
+ locals: {
+ items: [1,2,3]
+ }
+}

1 comment on commit 908480e

@tj

thanks bud! :D

Please sign in to comment.