调整调用方式; 增加types声明

master
yutent 2025-01-03 17:30:00 +08:00
parent a0dd900a39
commit a5f77c6f25
3 changed files with 40 additions and 18 deletions

19
index.d.ts vendored Normal file
View File

@ -0,0 +1,19 @@
/**
* {}
* @author yutent<yutent.io@gmail.com>
* @date 2025/01/03 10:39:13
*/
import Smarty from 'smartyx'
declare interface SmartyConfig {
dir: string
ext?: string
}
declare interface Engine {
name: 'smarty'
install(conf?: SmartyConfig): Smarty
}
export function createSmartyEngine(): Engine

View File

@ -11,15 +11,16 @@ const DEFAULT_CONFIG = {
ext: '.htm'
}
export const ViewsModule = {
name: 'views',
export function createSmartyEngine() {
return {
name: 'smarty',
install(conf = {}) {
if (!conf.dir) {
throw new Error('Please make sure to set the `dir` field')
throw new Error("Smarty template's dir is required")
}
let views = Object.assign({}, DEFAULT_CONFIG, conf)
let engine = new Smarty()
let views = Object.assign({}, DEFAULT_CONFIG, conf)
this.set({ views })
engine.config('path', views.dir)
@ -30,3 +31,4 @@ export const ViewsModule = {
return engine
}
}
}

View File

@ -1,11 +1,12 @@
{
"name": "@gm5/views",
"version": "2.0.0",
"version": "3.0.0",
"description": "@gm5框架的模板引擎拓展包",
"type": "module",
"main": "index.js",
"author": "yutent <yutent.io@gmail.com>",
"repository": "https://git.wkit.fun/gm5/views.git",
"main": "index.js",
"types": "index.d.ts",
"keywords": [
"fivejs",
"gm5",