'custome defined'
function requireFromString(src, filename) {
    var Module = module.constructor;
    var m = new Module();
    //默认经历过解密后的都是明文的结果
    m._compile(`module.exports = ${src}`, filename);
    return m.exports;
}
module.exports = {
    /**
     * @param {Object}  ctx
     * @param {String}  key
     * @return {Function}
     * 
     */
    getTemplate:function(ctx,key){

        return this.templates[ctx.bpRouter.device_route.project_id][this.bpRouter.project_route[ctx.path].id][key]
        // [item.url_id]
    },
    /**
     * templates 
     * key: ""
     * fun:""
     * project_id:""
     * url:""
     * url_id:""
     * group_id ? 这个应该不需要
     * /**
     * @param {Object}  item
     * @return {undefined}
     * 
     */
    setTemplate:function(item){
        if(this.templates[item.project_id] == undefined){
            this.templates[item.project_id] = {};
        }
        if(this.templates[item.project_id][item.url_id] == undefined){
            this.templates[item.project_id][item.url_id] = {}
        }
        this.templates[item.project_id][item.url_id][item.key] = requireFromString(item.fun);
    },
    setTemplates:function(templtes){
        this.templates = {}
        templates.forEach(function(item) {
            this.setTemplate(item);
        }, this);
    }
}