velocityjs
Advanced tools
Comparing version 0.4.4 to 0.4.5
{ | ||
"name": "velocityjs", | ||
"description": "Velocity Template Language(VTL) for JavaScript", | ||
"version": "0.4.4", | ||
"version": "0.4.5", | ||
"keywords": [ | ||
@@ -6,0 +6,0 @@ "velocity template" |
@@ -98,10 +98,2 @@ module.exports = function(Velocity, utils){ | ||
// 如果是$page.setTitle('xx')类似的方法,需要设置page为对象 | ||
var isSet = this.hasSetMethod(ast, ret); | ||
if (isSet !== false) { | ||
if (!context[ast.id]) context[ast.id] = {}; | ||
utils.mixin(context[ast.id], isSet); | ||
return ''; | ||
} | ||
if (ast.path && ret !== undefined) { | ||
@@ -127,31 +119,2 @@ | ||
/** | ||
* set方法需要单独处理,假设set只在references最后$page.setTitle('') | ||
*/ | ||
hasSetMethod: function(ast, context){ | ||
var tools = { 'control': true }; | ||
var len = ast.path && ast.path.length; | ||
if (!len || tools[ast.id]) return false; | ||
var last = ast.path[len - 1]; | ||
var lastId = '' + last.id; | ||
if (lastId.indexOf('set') !== 0 || last.type != 'method') { | ||
return false; | ||
} else { | ||
context = context || {}; | ||
utils.forEach(ast.path, function(ast){ | ||
if (ast.type === 'method' && ast.id.indexOf('set') === 0) { | ||
//if (context[ast.id]) { } | ||
context[ast.id.slice(3)] = this.getLiteral(ast.args[0]); | ||
} else { | ||
context[ast.id] = context[ast.id] || {}; | ||
} | ||
}, this); | ||
return context; | ||
} | ||
}, | ||
/** | ||
* 获取局部变量,在macro和foreach循环中使用 | ||
@@ -234,2 +197,3 @@ */ | ||
// getter 处理 | ||
if (id.indexOf('get') === 0 && !(id in baseRef)) { | ||
@@ -247,2 +211,10 @@ | ||
// setter 处理 | ||
} else if (id.indexOf('set') === 0 && !baseRef[id]) { | ||
baseRef[_id] = this.getLiteral(property.args[0]); | ||
// $page.setName(123) | ||
baseRef.toString = function() { return ''; }; | ||
return baseRef; | ||
} else if (id.indexOf('is') === 0 && !(id in baseRef)) { | ||
@@ -249,0 +221,0 @@ |
@@ -36,3 +36,3 @@ var Velocity = require('../src/velocity') | ||
var vm = '$page.setTitle( "My Home Page" ).setname("haha")$page.Title $page.name' | ||
assert.equal('My Home Page haha', render(vm)) | ||
assert.equal('My Home Page haha', render(vm, {page: {}})) | ||
}) | ||
@@ -533,3 +533,3 @@ | ||
it('$stop test', function(){ | ||
it('$control.setTemplate', function(){ | ||
@@ -536,0 +536,0 @@ var control = { |
445732
3873