Skip to content

Commit

Permalink
TREE: fixed issue #422 append/prepend content with function body
Browse files Browse the repository at this point in the history
  • Loading branch information
miripiruni committed Mar 13, 2017
1 parent 4adfc67 commit 79602b9
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 8 deletions.
12 changes: 4 additions & 8 deletions lib/bemxjst/tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,7 @@ AddMatch.prototype.wrapBody = function(body) {
};

AddMatch.prototype.appendContentWrapBody = function(body) {
var refs = this.refs;
var applyCtx = refs.applyCtx;
var apply = refs.apply;
var apply = this.refs.apply;

if (typeof body !== 'function') {
return function() {
Expand All @@ -150,14 +148,12 @@ AddMatch.prototype.appendContentWrapBody = function(body) {
}

return function() {
return [ apply('content'), applyCtx(body.call(this, this, this.ctx)) ];
return [ apply('content'), body.call(this, this, this.ctx) ];
};
};

AddMatch.prototype.prependContentWrapBody = function(body) {
var refs = this.refs;
var applyCtx = refs.applyCtx;
var apply = refs.apply;
var apply = this.refs.apply;

if (typeof body !== 'function') {
return function() {
Expand All @@ -166,7 +162,7 @@ AddMatch.prototype.prependContentWrapBody = function(body) {
}

return function() {
return [ applyCtx(body.call(this, this, this.ctx)), apply('content') ];
return [ body.call(this, this, this.ctx), apply('content') ];
};
};

Expand Down
16 changes: 16 additions & 0 deletions test/modes-appendcontent-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,20 @@ describe('Modes appendContent', function() {
{ block: 'button', content: 'test' },
'<div class="button"><span class="tmpl_1"></span>tmpl_2</div>');
});

it('should append non simple values to content', function() {
test(function() {
block('foo').appendContent()({ elem: 'test' });
},
{ block: 'foo' },
'<div class="foo"><div class="foo__test"></div></div>');
});

it('should append function to content', function() {
test(function() {
block('foo').appendContent()(function() { return { elem: 'test' }; });
},
{ block: 'foo' },
'<div class="foo"><div class="foo__test"></div></div>');
});
});
16 changes: 16 additions & 0 deletions test/modes-prependcontent-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,20 @@ describe('Modes prependContent', function() {
{ block: 'b', content: 'test' },
'<div class="b">42</div>');
});

it('should prepend non simple values to content', function() {
test(function() {
block('foo').prependContent()({ elem: 'test' });
},
{ block: 'foo' },
'<div class="foo"><div class="foo__test"></div></div>');
});

it('should prepend function to content', function() {
test(function() {
block('foo').prependContent()(function() { return { elem: 'test' }; });
},
{ block: 'foo' },
'<div class="foo"><div class="foo__test"></div></div>');
});
});

0 comments on commit 79602b9

Please sign in to comment.