Kenneth Jørgensen avatar Kenneth Jørgensen committed 1409e09

Fixed template context

Comments (0)

Files changed (3)

 ## 0.4.0 (dev)
 * *API change:* Removed all modelling code into a separate project called `discrete`.
+* *Fix:* Templates are now called with the view as their `this` value.
 ## 0.3.0 (2013-07-30)
 * *API change:* Default model functions are supplied the values object rather than as context.


 			expect(view._render.callCount).toBe 1
 	it "should by default render a provided template with model data", ->
-		templateData = null
-		template = sinon.spy (data) ->
-			templateData = data
-			return "TESTHTML"
+		template = sinon.spy (data) -> return "TESTHTML"
 		class Test extends TestView
 			template: template
 		view = new Test
 		waitsFor (-> template.called), "Template never called", 100
 		runs ->
 			expect(template.callCount).toBe 1
-			expect( "FOO"
+			call = template.getCall 0
+			expect(call.args[0].foo).toBe "FOO"
+			expect(call.thisValue).toBe view
 			expect(view.element().html()).toBe "TESTHTML"
 	it "should hide and show its element", ->
 	_callTemplate: () ->
 		template = @template
 		return undefined unless _.isFunction template
-		# Get tempalte data.
+		# Get template data.
 		data = @_getTemplateData()
 		# Render.
-		html = template(data)
+		boundTemplate = _.bind template, @
+		html = boundTemplate data
 		return html
 	# Returns the data to be passed to the template.
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.