From 8fb8f5fb5093b0353b7bfed00f12e3a7cf6af200 Mon Sep 17 00:00:00 2001 From: Erik Bryn Date: Sat, 20 Dec 2014 20:23:45 -0800 Subject: [PATCH] Create TemplateRenderingSupport mixin to house the `render` function so it can be used elsewhere --- packages/ember-views/lib/views/view.js | 46 ++++++++++++++------------ 1 file changed, 24 insertions(+), 22 deletions(-) diff --git a/packages/ember-views/lib/views/view.js b/packages/ember-views/lib/views/view.js index 6fa719e36a8..14666dba65e 100644 --- a/packages/ember-views/lib/views/view.js +++ b/packages/ember-views/lib/views/view.js @@ -432,6 +432,28 @@ var ViewStateSupport = Mixin.create({ } }); +var TemplateRenderingSupport = Mixin.create({ + /** + Called on your view when it should push strings of HTML into a + `Ember.RenderBuffer`. Most users will want to override the `template` + or `templateName` properties instead of this method. + + By default, `Ember.View` will look for a function in the `template` + property and invoke it with the value of `context`. The value of + `context` will be the view's controller unless you override it. + + @method render + @param {Ember.RenderBuffer} buffer The render buffer + */ + render: function(buffer) { + // If this view has a layout, it is the responsibility of the + // the layout to render the view's template. Otherwise, render the template + // directly. + var template = get(this, 'layout') || get(this, 'template'); + renderView(this, buffer, template); + } +}); + /** `Ember.View` is the class in Ember responsible for encapsulating templates of HTML content, combining templates with data to render as sections of a page's @@ -1019,7 +1041,7 @@ var ViewStateSupport = Mixin.create({ @namespace Ember @extends Ember.CoreView */ -var View = CoreView.extend(ViewStreamSupport, ViewKeywordSupport, ViewContextSupport, ViewChildViewsSupport, ViewStateSupport, { +var View = CoreView.extend(ViewStreamSupport, ViewKeywordSupport, ViewContextSupport, ViewChildViewsSupport, ViewStateSupport, TemplateRenderingSupport, { concatenatedProperties: ['classNames', 'classNameBindings', 'attributeBindings'], @@ -1290,26 +1312,6 @@ var View = CoreView.extend(ViewStreamSupport, ViewKeywordSupport, ViewContextSup }); }), - /** - Called on your view when it should push strings of HTML into a - `Ember.RenderBuffer`. Most users will want to override the `template` - or `templateName` properties instead of this method. - - By default, `Ember.View` will look for a function in the `template` - property and invoke it with the value of `context`. The value of - `context` will be the view's controller unless you override it. - - @method render - @param {Ember.RenderBuffer} buffer The render buffer - */ - render: function(buffer) { - // If this view has a layout, it is the responsibility of the - // the layout to render the view's template. Otherwise, render the template - // directly. - var template = get(this, 'layout') || get(this, 'template'); - renderView(this, buffer, template); - }, - /** Renders the view again. This will work regardless of whether the view is already in the DOM or not. If the view is in the DOM, the @@ -2231,4 +2233,4 @@ View.applyAttributeBindings = function(dom, elem, name, initialValue) { export default View; -export { ViewKeywordSupport, ViewStreamSupport, ViewContextSupport, ViewChildViewsSupport, ViewStateSupport }; \ No newline at end of file +export { ViewKeywordSupport, ViewStreamSupport, ViewContextSupport, ViewChildViewsSupport, ViewStateSupport, TemplateRenderingSupport };