Compare commits
No commits in common. "master" and "v1" have entirely different histories.
11
Readme.md
11
Readme.md
|
@ -1,25 +1,22 @@
|
||||||
|

|
||||||

|
|
||||||

|
|
||||||
|
|
||||||
# @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)
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
|
@ -1,19 +0,0 @@
|
||||||
/**
|
|
||||||
* {}
|
|
||||||
* @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
|
|
35
index.js
35
index.js
|
@ -6,29 +6,24 @@
|
||||||
|
|
||||||
import Smarty from 'smartyx'
|
import Smarty from 'smartyx'
|
||||||
|
|
||||||
const DEFAULT_CONFIG = {
|
export default {
|
||||||
dir: '',
|
name: 'views',
|
||||||
ext: '.htm'
|
install() {
|
||||||
}
|
var eng = new Smarty()
|
||||||
|
var conf = this.get('views')
|
||||||
|
|
||||||
export function createSmartyEngine() {
|
if (conf.enabled) {
|
||||||
return {
|
if (conf.dir) {
|
||||||
name: 'smarty',
|
eng.config('path', conf.dir)
|
||||||
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 })
|
if (conf.ext) {
|
||||||
|
eng.config('ext', conf.ext)
|
||||||
engine.config('path', views.dir)
|
|
||||||
|
|
||||||
if (views.ext) {
|
|
||||||
engine.config('ext', views.ext)
|
|
||||||
}
|
}
|
||||||
return engine
|
return eng
|
||||||
|
} else {
|
||||||
|
throw new Error('views.dir is empty')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return Object.create(null)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
14
package.json
14
package.json
|
@ -1,18 +1,12 @@
|
||||||
{
|
{
|
||||||
"name": "@gm5/views",
|
"name": "@gm5/views",
|
||||||
"version": "3.0.0",
|
"version": "1.0.0",
|
||||||
"description": "@gm5框架的模板引擎拓展包",
|
"description": "@gm5框架的模板引擎拓展包",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"author": "yutent <yutent.io@gmail.com>",
|
|
||||||
"repository": "https://git.wkit.fun/gm5/views.git",
|
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"types": "index.d.ts",
|
"author": "yutent <yutent.io@gmail.com>",
|
||||||
"keywords": [
|
"repository": "https://github.com/bytedo/gmf.views.git",
|
||||||
"fivejs",
|
"keywords": ["fivejs", "views", "smarty"],
|
||||||
"gm5",
|
|
||||||
"views",
|
|
||||||
"smarty"
|
|
||||||
],
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"smartyx": "^2.1.0"
|
"smartyx": "^2.1.0"
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue