Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
jsonify: function(vm){
var vmLayout = this._getLayoutString();
vm = vmLayout.replace(/\$screen_placeholder/, vm);
vm = this.globalMacros + vm;
var context = {
control: this.tools.control
};
var asts = Velocity.Parser.parse(vm);
var jsonify = new Velocity.Jsonify(asts, context);
return (jsonify.toVTL());
},
parse: function(){
var filePath = this.get('filePath');
var vm = Iconv.decode(fs.readFileSync(filePath), 'gbk');
var str = '';
var isParse = this.get('isParse');
var isJsonify = this.get('isJsonify');
var file = this.get('file').replace('.htm', '.js');
var context = this.getContext(file);
var basePath = this.get('basePath');
try {
var html = Velocity.Parser.parse(vm);
if (isParse) {
str = JSON.stringify(html, false, 2);
} else if (isJsonify) {
str = this.jsonify(vm);
} else {
for(var i in this.tools)
context[i] = this.tools[i];
//context = utils.mixin(context, this.tools);
var macros = this.globalMacros;
var url = URL.parse(request.url, true);
var isParse = '__parse' in url.query;
//接受处理
this.fire('receive', {file: file, index: i});
this._add();
var dataFile = path.dirname(filePath) + '/.data/' + path.basename(filePath);
var data = {};
if (fs.existsSync(dataFile)) {
data = JSON.parse(fs.readFileSync(dataFile).toString());
}
var vm = fs.readFileSync(filePath).toString();
try {
var html = Velocity.Parser.parse(vm);
if (isParse) {
this.fire('set:header', {type: '.json'});
var str = JSON.stringify(html, false, 2);
} else {
str = new Velocity.Compile(html).render(data);
}
this.fire('end', {index: i, data: str});
} catch(e) {
this.fire('end', {index: i, data: '<pre>' + e.toString()});
throw e;
}
}
</pre>