Skip to content

Commit

Permalink
Merge pull request #437 from aui/v4.12.1
Browse files Browse the repository at this point in the history
fix filter bug
  • Loading branch information
aui authored Jun 29, 2017
2 parents a2ae37a + 6562b80 commit de0f67d
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 11 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
# CHANGELOG

## v4.12.1

1. 修复过滤器不能使用包含空的格字符串参数的问题

## v4.12.0

1. `bail` 默认为 `true`
2. 修复 filter 不支持 javascript 表达式的问题 [#430](https://github.com/aui/art-template/issues/430)
2. 修复过滤器不支持 javascript 表达式的问题 [#430](https://github.com/aui/art-template/issues/430)

## v4.11.0

Expand Down
6 changes: 4 additions & 2 deletions lib/compile/adapter/rule.art.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,12 @@ var artRule = {

// 将过滤器解析成二维数组
var _group = esTokens.reduce(function (group, token) {
var value = token.value;
var value = token.value,
type = token.type;

if (value === '|') {
group.push([]);
} else if (/^\S+$/.test(value)) {
} else if (type !== 'whitespace' && type !== 'comment') {
if (!group.length) {
group.push([]);
}
Expand All @@ -142,6 +143,7 @@ var artRule = {
code = _group.reduce(function (accumulator, filter) {
var name = filter.shift();
filter.unshift(accumulator);

return '$imports.' + name + '(' + filter.join(',') + ')';
}, _group.shift().join(' ').trim());
}
Expand Down
6 changes: 3 additions & 3 deletions lib/template-web.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "art-template",
"description": "JavaScript Template Engine",
"homepage": "http://aui.github.com/art-template/",
"version": "4.12.0",
"version": "4.12.1",
"keywords": [
"template"
],
Expand Down
7 changes: 4 additions & 3 deletions src/compile/adapter/rule.art.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,10 @@ const artRule = {

// 将过滤器解析成二维数组
const group = esTokens.reduce((group, token) => {
const {value} = token;
const {value, type} = token;
if (value === '|') {
group.push([]);
} else if (/^\S+$/.test(value)) {
} else if (type !== `whitespace` && type !== `comment`) {
if (!group.length) {
group.push([]);
}
Expand All @@ -138,14 +138,15 @@ const artRule = {
return group;
}, []).map(g => artRule._split(g));


// 将过滤器管道化
code = group.reduce((accumulator, filter) => {
const name = filter.shift();
filter.unshift(accumulator);

return `$imports.${name}(${filter.join(',')})`;
}, group.shift().join(` `).trim());


}

output = output || 'escape';
Expand Down
14 changes: 13 additions & 1 deletion test/compile/adapter/rule.art.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const callRule = code => {
return ruleArt.use.apply(compiler, list);
}


module.exports = {
syntax: {
'set': () => {
Expand Down Expand Up @@ -303,7 +304,14 @@ module.exports = {
code: `$imports.dateFormat(time||Date.now(),'yyyy-MM-dd')`,
output: 'escape'
}, callRule(`{{time || Date.now() | dateFormat 'yyyy-MM-dd'}}`));
}

assert.deepEqual({
code: `$imports.dateFormat(item.add_time*1000,'yyyy-MM-dd hh:mm:ss')`,
output: 'escape'
}, callRule(`{{item.add_time*1000 | dateFormat 'yyyy-MM-dd hh:mm:ss'}}`));
},


},

'rule.art': {
Expand Down Expand Up @@ -437,6 +445,10 @@ module.exports = {
result = ruleArt._split(esTokens);
assert.deepEqual(['++a', 'c'], result);

code = `dateFormat 'yyyy-MM-dd hh:mm:ss'`;
esTokens = esTokenizer(code);
result = ruleArt._split(esTokens);
assert.deepEqual(['dateFormat', `'yyyy-MM-dd hh:mm:ss'`], result);
}
}
};

0 comments on commit de0f67d

Please sign in to comment.