From a0dd900a39d9e125f497a1e8e846329f5706eb5b Mon Sep 17 00:00:00 2001 From: yutent Date: Wed, 1 Nov 2023 16:03:07 +0800 Subject: [PATCH] =?UTF-8?q?2.0=E9=87=8D=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Readme.md | 11 +++++++---- index.js | 36 ++++++++++++++++++++---------------- package.json | 11 ++++++++--- 3 files changed, 35 insertions(+), 23 deletions(-) diff --git a/Readme.md b/Readme.md index 3a72096..16b9aa0 100644 --- a/Readme.md +++ b/Readme.md @@ -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) ``` diff --git a/index.js b/index.js index fca9768..78b4bfa 100644 --- a/index.js +++ b/index.js @@ -6,23 +6,27 @@ import Smarty from 'smartyx' -export function createViewsPlugin() { - return { - name: 'views', - install() { - let eng = new Smarty() - let conf = this.get('views') +const DEFAULT_CONFIG = { + dir: '', + ext: '.htm' +} - 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') - } +export const ViewsModule = { + name: 'views', + install(conf = {}) { + if (!conf.dir) { + throw new Error('Please make sure to set the `dir` field') } + let engine = new Smarty() + + 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 } } diff --git a/package.json b/package.json index f22f0c8..cb076a0 100644 --- a/package.json +++ b/package.json @@ -1,12 +1,17 @@ { "name": "@gm5/views", - "version": "1.0.0", + "version": "2.0.0", "description": "@gm5框架的模板引擎拓展包", "type": "module", "main": "index.js", "author": "yutent ", - "repository": "https://github.com/bytedo/gmf.views.git", - "keywords": ["fivejs", "views", "smarty"], + "repository": "https://git.wkit.fun/gm5/views.git", + "keywords": [ + "fivejs", + "gm5", + "views", + "smarty" + ], "dependencies": { "smartyx": "^2.1.0" },