views/index.js

35 lines
633 B
JavaScript
Raw Normal View History

2020-09-27 18:37:49 +08:00
/**
* 模板引擎拓展包
* @author yutent<yutent.io@gmail.com>
* @date 2020/09/27 14:17:46
*/
import Smarty from 'smartyx'
2023-11-01 16:03:07 +08:00
const DEFAULT_CONFIG = {
dir: '',
ext: '.htm'
}
2025-01-03 17:30:00 +08:00
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()
2023-11-01 16:03:07 +08:00
2025-01-03 17:30:00 +08:00
this.set({ views })
2020-09-27 19:33:57 +08:00
2025-01-03 17:30:00 +08:00
engine.config('path', views.dir)
2020-09-27 19:33:57 +08:00
2025-01-03 17:30:00 +08:00
if (views.ext) {
engine.config('ext', views.ext)
}
return engine
2020-09-27 19:33:57 +08:00
}
2020-09-27 18:37:49 +08:00
}
}