1 | # Node xTemplate
|
2 |
|
3 | [![NPM version][npm-image]][npm-url]
|
4 | [![NPM download][download-image]][download-url]
|
5 | [![Build Status][travis-image]][travis-url]
|
6 | [![Dependency Status][dependency-image]][dependency-url]
|
7 | [![devDependency Status][devdependency-image]][devdependency-url]
|
8 | [![Code Style][style-image]][style-url]
|
9 |
|
10 | [npm-image]: https://badge.fury.io/js/node-xtemplate.svg
|
11 | [npm-url]: https://npmjs.org/package/node-xtemplate
|
12 | [download-image]: https://img.shields.io/npm/dm/node-xtemplate.svg
|
13 | [download-url]: https://npmjs.org/package/node-xtemplate
|
14 | [travis-image]: https://travis-ci.org/zce/node-xtemplate.svg?branch=master
|
15 | [travis-url]: https://travis-ci.org/zce/node-xtemplate
|
16 | [dependency-image]: https://david-dm.org/zce/node-xtemplate/status.svg
|
17 | [dependency-url]: https://david-dm.org/zce/node-xtemplate
|
18 | [devdependency-image]: https://david-dm.org/zce/node-xtemplate/dev-status.svg
|
19 | [devdependency-url]: https://david-dm.org/zce/node-xtemplate?type=dev
|
20 | [style-image]: https://img.shields.io/badge/code%20style-standard-brightgreen.svg
|
21 | [style-url]: http://standardjs.com/
|
22 |
|
23 | > A node.js wrapper around xtemplate engine
|
24 |
|
25 |
|
26 | ## Install
|
27 |
|
28 | ```sh
|
29 | $ npm install --save node-xtemplate
|
30 | ```
|
31 |
|
32 |
|
33 | ## Usage
|
34 |
|
35 | demo.xtpl
|
36 | ```html
|
37 | <p>{{ message }}</p>
|
38 | ```
|
39 |
|
40 | demo.js
|
41 |
|
42 | ```js
|
43 | const xTemplate = require('node-xtemplate');
|
44 |
|
45 | xTemplate.render(path.resolve(__dirname, 'demo.xtpl'), {
|
46 | message: 'hello world'
|
47 | }, function (err, result) {
|
48 | // => <p>hello world</p>
|
49 | })
|
50 | ```
|
51 |
|
52 |
|
53 | ## API
|
54 |
|
55 | ### render(path, data[, options], callback)
|
56 |
|
57 | #### path
|
58 |
|
59 | Type: `string`
|
60 |
|
61 | The path of template file.
|
62 |
|
63 | #### data
|
64 |
|
65 | Type: `object`
|
66 |
|
67 | The template data.
|
68 |
|
69 | #### options
|
70 |
|
71 | ##### extname
|
72 |
|
73 | Type: `string`
|
74 |
|
75 | ##### strict
|
76 |
|
77 | Type: `boolean`
|
78 |
|
79 | ##### catchError
|
80 |
|
81 | Type: `boolean`
|
82 |
|
83 | ##### cache
|
84 |
|
85 | Type: `boolean`
|
86 |
|
87 | ##### encoding
|
88 |
|
89 | Type: `string`<br>
|
90 | Default: `utf-8`
|
91 |
|
92 | #### callback(err, result)
|
93 |
|
94 | Type: `function`
|
95 |
|
96 | Done callback
|
97 |
|
98 |
|
99 | ## License
|
100 |
|
101 | [MIT](LICENSE) © [汪磊](http://github.com/zce)
|
102 |
|