Compare commits

...

3 Commits
v1 ... master

Author SHA1 Message Date
yutent a5f77c6f25 调整调用方式; 增加types声明 2025-01-03 17:30:00 +08:00
yutent a0dd900a39 2.0重构 2023-11-01 16:03:07 +08:00
yutent 95f088475e 重构2.0 2023-10-27 19:18:41 +08:00
4 changed files with 57 additions and 24 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框架的模板引擎拓展包.
## 安装
> 一般不需要单独安装, 该模块包含在`@gm5/core`的依赖里。
```bash
npm install @gm5/views
npm i @gm5/views
```
## 使用
```js
import Views from '@gm5/views'
import { ViewsModule } from '@gm5/views'
app.install(Views)
app.install(ViewsModule)
```

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

@ -6,24 +6,29 @@
import Smarty from 'smartyx'
export default {
name: 'views',
install() {
var eng = new Smarty()
var conf = this.get('views')
const DEFAULT_CONFIG = {
dir: '',
ext: '.htm'
}
if (conf.enabled) {
if (conf.dir) {
eng.config('path', conf.dir)
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()
if (conf.ext) {
eng.config('ext', conf.ext)
this.set({ views })
engine.config('path', views.dir)
if (views.ext) {
engine.config('ext', views.ext)
}
return eng
} else {
throw new Error('views.dir is empty')
return engine
}
}
return Object.create(null)
}
}

View File

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