You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+10-10Lines changed: 10 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,14 +5,14 @@ micro-template.js
5
5
6
6
https://github.com/cho45/micro-template.js
7
7
8
-
micro-template is a template engine on JavaScript which like embed js.
8
+
micro-template is a template engine for JavaScript which is similar to embed.js.
9
9
10
-
This is inspired from[John Resig's template](http://ejohn.org/blog/javascript-micro-templating/) but has more efficient feature:
10
+
This is inspired by[John Resig's template](http://ejohn.org/blog/javascript-micro-templating/) but has more efficient features:
11
11
12
-
* Better error messages: show line-number in runtime errors
13
-
*Support source map: debug is more easily on Chrome including syntax errors
14
-
* Well tested: tested on node.js
15
-
*Escape by default: all output is escaped by default for security
12
+
* Better error messages: shows line numbers in runtime errors
13
+
*Supports source maps: debugging is easier in Chrome, including for syntax errors
14
+
* Well tested: works on Node.js
15
+
*Escapes by default: all output is escaped for security
16
16
17
17
SYNOPSIS
18
18
--------
@@ -69,7 +69,7 @@ const result = template('part1', {
69
69
foo :'bar',
70
70
baz :'piyo'
71
71
});
72
-
conole.log(result)
72
+
console.log(result)
73
73
```
74
74
75
75
SYNTAX
@@ -97,9 +97,9 @@ If the second argument is an **Object**, the template will be rendered immediate
97
97
CUSTOM `get` FUNCTION
98
98
---------------------
99
99
100
-
By default, micro-template uses `document.getElementById(id).innerHTML` to get template source from id.
100
+
By default, micro-template uses `document.getElementById(id).innerHTML` to get the template source from the id.
101
101
102
-
To override this behaviour, you can set function to `template.get`.
102
+
To override this behavior, you can set a function to `template.get`. For example, if your template files are in the `tmpl/` directory:
103
103
104
104
```js
105
105
import { template } from'micro-template';
@@ -109,7 +109,7 @@ template.get = function (id) { return require('fs').readFileSync('tmpl/' + id +
109
109
DEFINE DATA VARIABLE SCOPE
110
110
----------------------------
111
111
112
-
micro-template now always expands data variables as local variables in the template function. The template API only supports two arguments: the template source/id and the data object. All keys of the data object are available as local variables in the template code.
112
+
micro-template always expands data variables as local variables in the template function. The template API only supports two arguments: the template source/id and the data object (or an array of property names for precompilation). All keys of the data object are available as local variables in the template code.
113
113
114
114
If the second argument is an **Array**, it is treated as a list of property names for the data object. In this case, the template function will be compiled with these property names as its local variables, and the function itself will be returned (not executed). This allows you to precompile a template for repeated use with the same set of variable names.
0 commit comments