Skip to content

Commit

Permalink
Throw error when using view template helper with selector region
Browse files Browse the repository at this point in the history
  • Loading branch information
jridgewell committed Jan 3, 2015
1 parent 2c5ed73 commit 448e251
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
9 changes: 8 additions & 1 deletion src/region.js
Expand Up @@ -21,6 +21,10 @@ function attributeReducer(attributes, left, right) {
}).join('');
}

function throwPlaceholder() {
throw new Error('Cannot use view template helper with region declared using a selector');
}

_.extend(Minionette.Region.prototype, Backbone.Events, {
PlaceholderView: Backbone.View.extend({
// Use a span so it collapses on the DOM.
Expand Down Expand Up @@ -80,7 +84,10 @@ _.extend(Minionette.Region.prototype, Backbone.Events, {
// And set our views' _parent to this region.
this.view._parent = this;

_.extend(this, _.pick(options, 'selector'));
if (options.selector) {
this.selector = options.selector;
this.placeholder = throwPlaceholder;
}
},

// Ensures that the view's el is contained inside the parent view's.
Expand Down
7 changes: 4 additions & 3 deletions test/specs/region_spec.js
Expand Up @@ -257,6 +257,7 @@ describe('Minionette.Region', function() {
var selector = ':first-child';
region = view.addRegion('subview', selector);
region.attach(newView);
view.template = '<p></p><span></span>';

view.render();

Expand All @@ -266,11 +267,11 @@ describe('Minionette.Region', function() {
});

it("will correctly render even when not rendered and initialized with jQuery object", function() {
var selector = ':first-child',
$selector = view.$(selector);
var selector = ':first-child';
var $selector = view.$(selector);
region = view.addRegion('subview', $selector);
region.attach(newView);

view.template = '<p></p><span></span>';

view.render();

Expand Down
8 changes: 7 additions & 1 deletion test/specs/view_spec.js
Expand Up @@ -440,7 +440,13 @@ describe('Minionette.View', function() {
});

it("throws error if it cannot reattach region", function() {
var region = view.addRegion('subview', 'notexist');
view.addRegion('subview', 'notexist');
expect(function() { view.render(); }).to.throw(Error);
});

it("throws error if view template helper used with selector region", function() {
view.addRegion('subview', 'p');
view.template = _.template('<p></p><%= view("subview") %>');

expect(function() { view.render(); }).to.throw(Error);
});
Expand Down

0 comments on commit 448e251

Please sign in to comment.