class outwxml{
constructor(option){
const _ts = this;
_ts.config = {};
option = option || {};
for(let i in option){
_ts.config[i] = option[i];
};
let Towxml = require('./main');
_ts.m = {
fs:require('fs'),
path:require('path'),
towxml:new Towxml()
};
}
init(){
const _ts = this;
_ts.outtag();
let s = _ts.outwxml();
_ts.m.fs.writeFileSync('./renderTemplate.wxml',s);
}
//输出tag
outtag(id){
const _ts = this;
let s = '',
attr = _ts.outattr(),
wxmlTag = _ts.m.towxml.wxmlTag;
wxmlTag.forEach((item,index)=>{
let imgMode = ''
if(item === 'image'){
imgMode = 'mode="widthFix"';
};
s+= `
<${item} wx:if="{{item.node === 'element' && item.tag === '${item}'}}" ${attr} ${imgMode}>
${item}>
`;
});
return s;
}
//生成模版对应属性
outattr(){
const _ts = this;
let s = '',
attr = ['class','width','height','data','src','id','style'];
attr.forEach((item,index)=>{
if(item === 'class'){
s += `${item}="{{item.attr.className}}"`;
}else{
s += `${item}="{{item.attr.${item}}}"`;
};
});
return s;
}
//wxml模版生成
outwxml(){
const _ts = this;
let s = '';
for (let i = 0, len = _ts.config.depth; i{{item.text}}${_ts.outtag(c)}`;
// let temp = `
//
//
// {{item.text}}
//
// ${_ts.outtag(c)}
//
// `;
// let temp = `
//
//
//
// {{item.text}}
//
//
//
//
//
//
//
//
//
//
// `;
s+=temp;
};
return s;
}
};
new outwxml({depth:10}).init();