Comparing version 0.7.8 to 0.7.9
@@ -10,3 +10,3 @@ var helper = require("../lib/util"); | ||
})) { | ||
cb({msg: "PASS Engine"}); | ||
cb({code: "PASS Engine"}); | ||
} | ||
@@ -13,0 +13,0 @@ else { |
@@ -6,63 +6,68 @@ var helper = require("../lib/util"); | ||
module.exports = function (htmljsfile, reqOpt, param, cb) { | ||
var MIME = "application/javascript"; | ||
if (param.enable) { | ||
var MIME = "application/javascript"; | ||
var htmlfile = htmljsfile.replace(/(\.html)\.js$|(\.tpl)\.js$/, "$1$2"); | ||
var tpl = helper.getUnicode(htmlfile); | ||
if (tpl !== null) { | ||
tpl = tpl.replace(/<!--\s{0,}#def([\s\S]*?)-->/gi, ''); | ||
tpl = tpl.replace(/<!--\s{0,}#eachInclude[^\->]*?file\s{0,}=\s{0,}(["'])\s{0,}([^"']*?)\s{0,}\1\s{1,}(.+)\s{1,}as\s{1,}(.+)[^>]*?-->/gi, function (i, m1, m2, m3, m4) { | ||
var tempPath = pathLib.join(htmljsfile.replace(reqOpt.path, ''), m2); | ||
return "{@each " + m3 + " as " + m4 + "}" + (helper.getUnicode(tempPath) || '') + "{@/each}"; | ||
}); | ||
var htmlfile = htmljsfile.replace(/(\.html)\.js$|(\.tpl)\.js$/, "$1$2"); | ||
var tpl = helper.getUnicode(htmlfile); | ||
if (tpl !== null) { | ||
tpl = tpl.replace(/<!--\s{0,}#def([\s\S]*?)-->/gi, ''); | ||
tpl = tpl.replace(/<!--\s{0,}#eachInclude[^\->]*?file\s{0,}=\s{0,}(["'])\s{0,}([^"']*?)\s{0,}\1\s{1,}(.+)\s{1,}as\s{1,}(.+)[^>]*?-->/gi, function (i, m1, m2, m3, m4) { | ||
var tempPath = pathLib.join(htmljsfile.replace(reqOpt.path, ''), m2); | ||
return "{@each " + m3 + " as " + m4 + "}" + (helper.getUnicode(tempPath) || '') + "{@/each}"; | ||
}); | ||
var _method = [ | ||
"_method=_method||{};", | ||
"_method.__throw=function(e){throw(e)};" | ||
]; | ||
tpl = tpl.replace(/\{@helper\s{1,}([^\}]*?)\}([\s\S]*?)\{@\/helper\}/igm, function (all, funcname, func) { | ||
_method.push("_method." + funcname + '=' + func.replace(/^\s{0,}\n{1,}\s{0,}|\s{0,}\n{1,}\s{0,}$/g, '') + ';'); | ||
return ''; | ||
}); | ||
var _method = [ | ||
"_method=_method||{};", | ||
"_method.__throw=function(e){throw(e)};" | ||
]; | ||
tpl = tpl.replace(/\{@helper\s{1,}([^\}]*?)\}([\s\S]*?)\{@\/helper\}/igm, function (all, funcname, func) { | ||
_method.push("_method." + funcname + '=' + func.replace(/^\s{0,}\n{1,}\s{0,}|\s{0,}\n{1,}\s{0,}$/g, '') + ';'); | ||
return ''; | ||
}); | ||
var compiled = juicer(tpl)._render.toString().replace(/^function anonymous[^{]*?{\n?([\s\S]*?)\n?}$/img, function ($, fn_body) { | ||
fn_body = fn_body.replace(/(['"])use strict\1;?\n?/g, ''); | ||
var compiled = juicer(tpl)._render.toString().replace(/^function anonymous[^{]*?{\n?([\s\S]*?)\n?}$/img, function ($, fn_body) { | ||
fn_body = fn_body.replace(/(['"])use strict\1;?\n?/g, ''); | ||
var escapehtml = [], flag = false; | ||
if (/__escapehtml\.escaping|__escapehtml\.escapehash|__escapehtml\.escapereplace/.test(fn_body)) { | ||
escapehtml.push( | ||
"escapehash:" + JSON.stringify({ | ||
'<': '<', | ||
'>': '>', | ||
'&': '&', | ||
'"': '"', | ||
"'": ''', | ||
'/': '/' | ||
}), | ||
"escapereplace:function(k){return _method.__escapehtml.escapehash[k]}", | ||
"escaping:function(s){return typeof(s)!='string'?s:s.replace(/[&<>\"]/img,this.escapereplace)}" | ||
); | ||
flag = true; | ||
} | ||
if (/__escapehtml\.detection/.test(fn_body)) { | ||
escapehtml.push("detection:function(d){return typeof(d)=='undefined'?'':d}"); | ||
flag = true; | ||
} | ||
var escapehtml = [], flag = false; | ||
if (/__escapehtml\.escaping|__escapehtml\.escapehash|__escapehtml\.escapereplace/.test(fn_body)) { | ||
escapehtml.push( | ||
"escapehash:" + JSON.stringify({ | ||
'<': '<', | ||
'>': '>', | ||
'&': '&', | ||
'"': '"', | ||
"'": ''', | ||
'/': '/' | ||
}), | ||
"escapereplace:function(k){return _method.__escapehtml.escapehash[k]}", | ||
"escaping:function(s){return typeof(s)!='string'?s:s.replace(/[&<>\"]/img,this.escapereplace)}" | ||
); | ||
flag = true; | ||
} | ||
if (/__escapehtml\.detection/.test(fn_body)) { | ||
escapehtml.push("detection:function(d){return typeof(d)=='undefined'?'':d}"); | ||
flag = true; | ||
} | ||
return "function(_,_method){" + | ||
_method.join('') + | ||
(flag ? ("_method.__escapehtml={" + escapehtml.join(',') + "};") : '') + | ||
fn_body + "};"; | ||
}); | ||
return "function(_,_method){" + | ||
_method.join('') + | ||
(flag ? ("_method.__escapehtml={" + escapehtml.join(',') + "};") : '') + | ||
fn_body + "};"; | ||
}); | ||
cb(false, helper.wrapper(compiled, reqOpt.path, param), htmlfile, MIME); | ||
} | ||
else { | ||
tpl = helper.getUnicode(htmljsfile); | ||
if (tpl !== null) { | ||
cb(false, tpl, htmljsfile, MIME); | ||
cb(false, helper.wrapper(compiled, reqOpt.path, param), htmlfile, MIME); | ||
} | ||
else { | ||
cb({code: "Not Found"}); | ||
tpl = helper.getUnicode(htmljsfile); | ||
if (tpl !== null) { | ||
cb(false, tpl, htmljsfile, MIME); | ||
} | ||
else { | ||
cb({code: "Not Found"}); | ||
} | ||
} | ||
} | ||
else { | ||
cb({code: "PASS Engine"}); | ||
} | ||
}; |
{ | ||
"name": "dac", | ||
"version": "0.7.8", | ||
"version": "0.7.9", | ||
"description": "Dynamic Assets Compiler", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
12143
358