Skip to content

Commit

Permalink
+ 支持冒号属性
Browse files Browse the repository at this point in the history
+ 支持花括号属性值
  • Loading branch information
cloudcome committed Apr 14, 2017
1 parent 964cde2 commit d553dbc
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "blear.classes.template",
"version": "1.0.35",
"version": "1.1.0",
"description": "指令类型模板引擎",
"scripts": {
"live": "browser-sync start --config bs-config.js",
Expand Down
2 changes: 1 addition & 1 deletion src/_directives/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ var reColon = /:/g;
* @returns {{}}
*/
exports.str2Obj = function (str) {
var items = str.split(reSeperator);
var items = str.replace(/^\s*{|}\s*$/g, '').split(reSeperator);
var obj = {};

array.each(items, function (index, item) {
Expand Down
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ var reUnExp = /\\$/;
var reDoubleBackSlash = /\\\\$/;
var IGNORE_SEP = '•';
var reStatement = /^#/;
var reDirective = /^@/;
var reDirective = /^[@:]/;
var reExpression = /\{\{.*?}}/;
var reIgnore = /\{\{#ignore}}([\s\S]*?)\{\{\/ignore}}/g;
var reSlash = /\\\{\{.*?}}/g;
Expand Down
29 changes: 29 additions & 0 deletions test/test.index.js
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,20 @@ describe('测试文件', function () {
expect(/<b\s+class="a\s+b\s+d">/.test(html)).toEqual(true);
});

it(':class 花括号', function () {
var str = '<a class="a" :class="{b: c}"></a><b class="a" @class="{b: c, d: e,}"></b>';
var data = {
c: 1,
e: 2
};
var tpl = new Template(str);
var html = tpl.render(data);

console.log(html);
expect(/<a\s+class="a\s+b">/.test(html)).toEqual(true);
expect(/<b\s+class="a\s+b\s+d">/.test(html)).toEqual(true);
});

it('@style', function () {
var str = '<a style="a:b" @style="c: d"></a><b style="e:f" @style="g:h,i:j"></b>';
var data = {
Expand All @@ -361,6 +375,21 @@ describe('测试文件', function () {
expect(/<b\s+style="e\s*:\s*f(\s*;)+\s*g\s*:\s*2(\s*;)+\s*i\s*:\s*3(\s*;)*">/.test(html)).toEqual(true);
});

it(':style 花括号', function () {
var str = '<a style="a:b" :style="c: d"></a><b style="e:f" @style="{g:h,i:j}"></b>';
var data = {
d: 1,
h: 2,
j: 3
};
var tpl = new Template(str);
var html = tpl.render(data);

console.log(html);
expect(/<a\s+style="a\s*:\s*b(\s*;)+\s*c\s*:\s*1\s*;(\s*;)*">/.test(html)).toEqual(true);
expect(/<b\s+style="e\s*:\s*f(\s*;)+\s*g\s*:\s*2(\s*;)+\s*i\s*:\s*3(\s*;)*">/.test(html)).toEqual(true);
});

it('a="a"', function () {
var template = '<a a="a"></a>';
var data = {a: 'b'};
Expand Down

0 comments on commit d553dbc

Please sign in to comment.