Skip to content

Commit

Permalink
can.stache: fixed each helper for attributes (inc jslint)
Browse files Browse the repository at this point in the history
  • Loading branch information
ilyavf committed Aug 11, 2016
1 parent bcbe326 commit 1fc3da8
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 6 deletions.
3 changes: 2 additions & 1 deletion view/stache/expression.js
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,8 @@ steal("can/util",

var helperOptionArg = {
fn: function () {},
inverse: function () {}
inverse: function () {},
stringOnly: stringOnly
},
context = scope.attr("."),
args = this.args(scope, helperOptions, nodeList, truthyRenderer, falseyRenderer, stringOnly),
Expand Down
10 changes: 6 additions & 4 deletions view/stache/mustache_helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ steal("can/util", "./utils.js","can/view/live",function(can, utils, live){
key,
i;

if( resolved instanceof can.List ) {
if( resolved instanceof can.List && !options.stringOnly) {
return function(el){
// make a child nodeList inside the can.view.live.html nodeList
// so that if the html is re
Expand All @@ -62,12 +62,14 @@ steal("can/util", "./utils.js","can/view/live",function(can, utils, live){
var expr = resolved;

if ( !! expr && utils.isArrayLike(expr)) {
for (i = 0; i < expr.length; i++) {
var isCanList = expr instanceof can.List;
for (i = 0; i < (isCanList ? expr.attr('length') : expr.length); i++) {
var item = isCanList ? expr.attr(i) : expr[i];
result.push(options.fn(options.scope.add({
"%index": i,
"@index": i
},{notContext: true})
.add(expr[i])));
.add(item)));
}
} else if (utils.isObserveLike(expr)) {
keys = can.Map.keys(expr);
Expand All @@ -91,7 +93,7 @@ steal("can/util", "./utils.js","can/view/live",function(can, utils, live){
}

}
return result;
return !options.stringOnly ? result : result.join('');

},
"@index": function(offset, options) {
Expand Down
16 changes: 16 additions & 0 deletions view/stache/stache_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4861,6 +4861,22 @@ steal("can/util/vdom/document", "can/util/vdom/build_fragment","can/view/stache"

assert.equal( className, 'sort-ascend');
});
test('Helper each inside a text section (attribute) (#8)', function(assert){
var template = can.stache('<div class="{{#each list}}{{.}} {{/}}"></div>');

var vm = new can.Map({
list: new can.List(['one','two'])
});
var frag = template(vm);
var className = frag.firstChild.className;

assert.equal( className, 'one two ' );

vm.attr('list').push('three');
className = frag.firstChild.className;

assert.equal( className, 'one two three ' );
});
// PUT NEW TESTS RIGHT BEFORE THIS!
}

Expand Down
2 changes: 1 addition & 1 deletion view/stache/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ steal("can/util", "can/view/scope",function(can){
}
var result = rendererWithScope(newScope, newOptions || parentOptions, parentNodeList|| nodeList );
return result;
}
};
return observeObservables ? convertedRenderer : can.__notObserve(convertedRenderer);
},
Options: Options
Expand Down

0 comments on commit 1fc3da8

Please sign in to comment.