Compare commits

..

No commits in common. "master" and "v1" have entirely different histories.
master ... v1

3 changed files with 24 additions and 35 deletions

View File

@ -1,25 +1,22 @@
![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 i @gm5/views npm install @gm5/views
``` ```
## 使用 ## 使用
```js ```js
import { ViewsModule } from '@gm5/views' import Views from '@gm5/views'
app.install(ViewsModule) app.install(Views)
``` ```

View File

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

View File

@ -1,17 +1,12 @@
{ {
"name": "@gm5/views", "name": "@gm5/views",
"version": "2.0.0", "version": "1.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://git.wkit.fun/gm5/views.git", "repository": "https://github.com/bytedo/gmf.views.git",
"keywords": [ "keywords": ["fivejs", "views", "smarty"],
"fivejs",
"gm5",
"views",
"smarty"
],
"dependencies": { "dependencies": {
"smartyx": "^2.1.0" "smartyx": "^2.1.0"
}, },