# sugar-engine

> sugar2.0框架的模板渲染引擎组件

Latest version **0.0.2** (published 2017-05-23) · ISC license · 0 weekly downloads

## Install

```sh
npm install sugar-engine
pnpm add sugar-engine
yarn add sugar-engine
bun add sugar-engine
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.2 |
| Published | 2017-05-23 |
| First published | 2017-05-12 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 4 |
| Known vulnerabilities | 0 (+2 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 0 |
| Author | ss.feng |
| Maintainers | fengshangshi |

## Links

- npm: https://www.npmjs.com/package/sugar-engine
- Repository: https://github.com/fengshangshi/sugar-engine
- Homepage: https://github.com/fengshangshi/sugar-engine#readme
- Issues: https://github.com/fengshangshi/sugar-engine/issues
- npm.io page: https://npm.io/package/sugar-engine

## Dependencies (4)

- [ejs](https://npm.io/package/ejs.md) ^2.5.6
- [sha1](https://npm.io/package/sha1.md) ^1.1.1
- [handlebars](https://npm.io/package/handlebars.md) ^4.0.8
- [sugar-utils](https://npm.io/package/sugar-utils.md) 0.0.3

## Recent versions

- 0.0.2 (latest) — 2017-05-23
- 0.0.1 — 2017-05-12

## README

# sugar-engine

渲染模板使用。当前提供两种模板引擎：ejs和handlebars。


## API
### 引入

```
const engine = require('sugar-engine');

```
### engine.html(file, data, options)
输入：模板文件、希望渲染的数据

返回：编译后的html字符串

* options.engine - 默认：ejs，指定模板渲染引擎
* options.isCache - 默认：ture，模板文件是否被缓存

```
let data = {
	username: 'sugar',
	password: '123456',
};

let html = engine.html('/path/to', data, {
	isCache: false,
	engine: 'ejs', // or 'hbs'
});
```

### engine.template(file, isCache)
输入：模板文件，是否被缓存开关

返回：模板字符串

```
let template = engine.template('/path/to', true);
```

### engine.render(engine)
输入：模板引擎

返回：模板渲染器
```
let render = engine.render('hbs');
```

### engine.ejs(source, data)
输入：模板字符串，希望渲染的数据

返回：按照ejs的规范编译后的字符串
```
let ejsHtml = engine.ejs('<h1><%=title%></h1>', {
	title: 'sugar'
});
```


### engine.hbs(source, data)
输入：模板字符串，希望渲染的数据

返回：按照handlebars的规范编译后的字符串
```
let hbsHtml = engine.ejs('<h1>{{title}}</h1>', {
	title: 'sugar'
});
```

---
_Source: https://npm.io/package/sugar-engine · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
