views/index.js

35 lines
633 B
JavaScript

/**
* 模板引擎拓展包
* @author yutent<yutent.io@gmail.com>
* @date 2020/09/27 14:17:46
*/
import Smarty from 'smartyx'
const DEFAULT_CONFIG = {
dir: '',
ext: '.htm'
}
export function createSmartyEngine() {
return {
name: 'smarty',
install(conf = {}) {
if (!conf.dir) {
throw new Error("Smarty template's dir is required")
}
let views = Object.assign({}, DEFAULT_CONFIG, conf)
let engine = new Smarty()
this.set({ views })
engine.config('path', views.dir)
if (views.ext) {
engine.config('ext', views.ext)
}
return engine
}
}
}
@gm5框架的模板引擎拓展包
JavaScript 100%