Skip to content

Commit

Permalink
Create TemplateRenderingSupport mixin to house the render function …
Browse files Browse the repository at this point in the history
…so it can be used elsewhere
  • Loading branch information
ebryn committed Jan 31, 2015
1 parent ee12bb2 commit 8fb8f5f
Showing 1 changed file with 24 additions and 22 deletions.
46 changes: 24 additions & 22 deletions packages/ember-views/lib/views/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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'],

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -2231,4 +2233,4 @@ View.applyAttributeBindings = function(dom, elem, name, initialValue) {

export default View;

export { ViewKeywordSupport, ViewStreamSupport, ViewContextSupport, ViewChildViewsSupport, ViewStateSupport };
export { ViewKeywordSupport, ViewStreamSupport, ViewContextSupport, ViewChildViewsSupport, ViewStateSupport, TemplateRenderingSupport };

0 comments on commit 8fb8f5f

Please sign in to comment.