Comparing version 0.2.2 to 0.2.3
{ | ||
"name": "yog-swig", | ||
"version": "0.2.2", | ||
"version": "0.2.3", | ||
"description": "custom swig template, add some tag or filter ", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -32,3 +32,3 @@ var ignore = 'ignore', | ||
*/ | ||
exports.compile = function(compiler, args) { | ||
exports.compile = function (compiler, args) { | ||
var file = args.shift(), | ||
@@ -39,5 +39,5 @@ onlyIdx = args.indexOf(only), | ||
ignore = args[args.length - 1] === missing ? (args.pop()) : false, | ||
w = args.filter(function(o) { | ||
w = args.filter(function (o) { | ||
return !o.k; | ||
}).join(' '), | ||
}).join(','), | ||
w_args = { | ||
@@ -48,10 +48,13 @@ id: "spage", | ||
args.map(function(w) { | ||
args.map(function (w) { | ||
if (w.k) w_args[w.k] = w.v; | ||
}); | ||
// 处理_VAR_:标记,将其转变为获取ctx变量 | ||
var w_args_str = JSON.stringify(w_args).replace(/"<<VAR:(.*?)>>"/g, "_ctx.$1"); | ||
return (ignore ? ' try {\n' : '') + | ||
'var w_args = ' + JSON.stringify(w_args) + ';' + | ||
'if (_ctx.isQuickingMode){w_args.mode="quickling"}' + | ||
'_output += _swig._w(_ctx._yog, '+ file+', w_args, {' + | ||
'_output += _swig._w(_ctx._yog, ' + file + ', w_args, {' + | ||
'resolveFrom: "' + parentFile + '"' + | ||
@@ -64,6 +67,6 @@ '})(' + | ||
exports.parse = function(str, line, parser, types, stack, opts) { | ||
exports.parse = function (str, line, parser, types, stack, opts) { | ||
var file, w, k; | ||
parser.on(types.STRING, function(token) { | ||
parser.on(types.STRING, function (token) { | ||
@@ -85,3 +88,3 @@ if (!file) { | ||
this.out.push(out); | ||
v = ''; //reset | ||
k = ''; //reset | ||
} | ||
@@ -91,3 +94,3 @@ | ||
parser.on(types.VAR, function(token) { | ||
parser.on(types.VAR, function (token) { | ||
if (!file) { | ||
@@ -99,2 +102,13 @@ k = ''; | ||
if (~attrs.indexOf(k)) { | ||
var out = { | ||
v: '', | ||
k: '' | ||
}; | ||
out.v = '<<VAR:' + token.match + '>>'; | ||
out.k = k; | ||
this.out.push(out); | ||
k = ''; | ||
} | ||
if (~attrs.indexOf(token.match)) { | ||
@@ -134,3 +148,3 @@ k = token.match; | ||
parser.on('end', function() { | ||
parser.on('end', function () { | ||
this.out.push(opts.filename || null); | ||
@@ -142,2 +156,2 @@ }); | ||
exports.ends = false; | ||
exports.ends = false; |
@@ -40,3 +40,3 @@ var ignore = 'ignore', | ||
return !o.k; | ||
}).join(' '), | ||
}).join(','), | ||
w_args = {}; | ||
@@ -43,0 +43,0 @@ |
23321
595