2.0重构

master
yutent 2023-11-01 16:03:07 +08:00
parent 95f088475e
commit a0dd900a39
3 changed files with 35 additions and 23 deletions

View File

@ -1,22 +1,25 @@
![module info](https://nodei.co/npm/@gm5/views.png?downloads=true&downloadRank=true&stars=true)
![downloads](https://img.shields.io/npm/dt/@gm5/views.svg)
![version](https://img.shields.io/npm/v/@gm5/views.svg)
# @gm5/views # @gm5/views
> @gm5框架的模板引擎拓展包. > @gm5框架的模板引擎拓展包.
## 安装 ## 安装
> 一般不需要单独安装, 该模块包含在`@gm5/core`的依赖里。
```bash ```bash
npm install @gm5/views npm i @gm5/views
``` ```
## 使用 ## 使用
```js ```js
import Views from '@gm5/views' import { ViewsModule } from '@gm5/views'
app.install(Views) app.install(ViewsModule)
``` ```

View File

@ -6,23 +6,27 @@
import Smarty from 'smartyx' import Smarty from 'smartyx'
export function createViewsPlugin() { const DEFAULT_CONFIG = {
return { dir: '',
ext: '.htm'
}
export const ViewsModule = {
name: 'views', name: 'views',
install() { install(conf = {}) {
let eng = new Smarty() if (!conf.dir) {
let conf = this.get('views') throw new Error('Please make sure to set the `dir` field')
}
let engine = new Smarty()
if (conf.dir) { let views = Object.assign({}, DEFAULT_CONFIG, conf)
eng.config('path', conf.dir) this.set({ views })
if (conf.ext) { engine.config('path', views.dir)
eng.config('ext', conf.ext)
} if (views.ext) {
return eng engine.config('ext', views.ext)
} else {
throw new Error('views.dir is empty')
}
} }
return engine
} }
} }

View File

@ -1,12 +1,17 @@
{ {
"name": "@gm5/views", "name": "@gm5/views",
"version": "1.0.0", "version": "2.0.0",
"description": "@gm5框架的模板引擎拓展包", "description": "@gm5框架的模板引擎拓展包",
"type": "module", "type": "module",
"main": "index.js", "main": "index.js",
"author": "yutent <yutent.io@gmail.com>", "author": "yutent <yutent.io@gmail.com>",
"repository": "https://github.com/bytedo/gmf.views.git", "repository": "https://git.wkit.fun/gm5/views.git",
"keywords": ["fivejs", "views", "smarty"], "keywords": [
"fivejs",
"gm5",
"views",
"smarty"
],
"dependencies": { "dependencies": {
"smartyx": "^2.1.0" "smartyx": "^2.1.0"
}, },