Skip to content

Commit b814b1c

Browse files
committed
[ Add ] Manual of Template syntax
[ Optimize ] Update Getting started document
1 parent 1842a0d commit b814b1c

File tree

3 files changed

+58
-20
lines changed

3 files changed

+58
-20
lines changed

.esdoc.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
"source": "./test",
1515
"interfaces": ["describe", "it"],
1616
"includes": ["\\.js$"]
17+
},
18+
"manual": {
19+
"files": ["./manual/Template.md"]
1720
}
1821
}
1922
},

ReadMe.md

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# DOM Renderer
22

3-
**Template engine** based on **HTML 5** & **ECMAScript 6**
3+
**Template engine** based on **HTML 5**, **ECMAScript 6** & **MVVM**
44

55
[![NPM Dependency](https://david-dm.org/EasyWebApp/DOM-Renderer.svg)](https://david-dm.org/EasyWebApp/DOM-Renderer)
66
[![Build Status](https://travis-ci.com/EasyWebApp/DOM-Renderer.svg?branch=master)](https://travis-ci.com/EasyWebApp/DOM-Renderer)
@@ -27,7 +27,7 @@
2727
}
2828
```
2929

30-
[`source/index.html`](https://github.com/EasyWebApp/DOM-Renderer/blob/master/test/source/index.html)
30+
`source/index.html` [**Template syntax**](https://web-cell/DOM-Renderer/manual/Template.html)
3131

3232
```HTML
3333
<template>
@@ -49,6 +49,8 @@
4949
<li>${view.title}</li>
5050
</template>
5151
</ol>
52+
53+
<input type="text" name="name" placeholder="Switch account">
5254
</template>
5355
```
5456

@@ -60,7 +62,7 @@ import View, { parseDOM } from 'dom-renderer';
6062
import template from './index.html';
6163
import data from './index.json';
6264

63-
const view = new View( parseDOM( template ).firstChild.innerHTML );
65+
const view = new View( View.getTemplate( parseDOM( template ) ) );
6466

6567
view.render( data ).then(() => console.log(view + ''));
6668
```
@@ -89,6 +91,8 @@ view.render( data ).then(() => console.log(view + ''));
8991
<li>MVP</li>
9092
<li>KaiYuanShe</li>
9193
</ol>
94+
95+
<input type="text" name="name" placeholder="Switch account">
9296
```
9397

9498
## Installation
@@ -115,10 +119,7 @@ import View from 'dom-renderer';
115119
## Compile & bundle
116120

117121
```Shell
118-
npm install -D \
119-
web-cell \
120-
@babel/preset-env \
121-
babel-plugin-inline-import
122+
npm install web-cell-cli @babel/preset-env -D
122123
```
123124

124125
`package.json`
@@ -134,18 +135,6 @@ npm install -D \
134135
"babel": {
135136
"presets": [
136137
"@babel/preset-env"
137-
],
138-
"plugins": [
139-
[
140-
"babel-plugin-inline-import",
141-
{
142-
"extensions": [
143-
".html",
144-
".css",
145-
".json"
146-
]
147-
}
148-
]
149138
]
150139
}
151140
}
@@ -198,4 +187,4 @@ nextTick().then(() => {
198187

199188
## Typical cases
200189

201-
https://www.npmjs.com/browse/depended/dom-renderer
190+
1. [WebCell](https://web-cell.tk/)

manual/Template.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Template syntax
2+
3+
Source code of **DOM-Renderer** templates is legal [HTML 5 markups][1] with legal [ECMAScript 6 template literals][2] in it.
4+
5+
## Typical example
6+
7+
```HTML
8+
<template>
9+
<h1 hidden="${! view.name}">
10+
Hello, ${view.name} !
11+
</h1>
12+
13+
<ul data-view="profile">
14+
<template>
15+
<li title="${scope.name}">
16+
${view.URL}
17+
</li>
18+
<li>${view.title}</li>
19+
</template>
20+
</ul>
21+
22+
<ol data-view="job">
23+
<template>
24+
<li>${view.title}</li>
25+
</template>
26+
</ol>
27+
28+
<input type="text" name="name" placeholder="Switch account">
29+
</template>
30+
```
31+
32+
| Code | Type | Explanation |
33+
| :------------------------: | :--------------: | :-----------------------------------------------------------------------------------: |
34+
| `this` | Local variable | The [Element][3] which current Template literals located at |
35+
| `view` | Local variable | **Data object** of the [View][4] which current Template literals located at |
36+
| `scope` | Local variable | Data object of the parent View which current Template literals located at |
37+
| `"${! view.name}"` | Template literal | Evaluated value of Template literals supports all kinds of Data types |
38+
| `hidden="${! view.name}"` | HTML attribute | HTML Boolean attributes are treated as DOM Properties |
39+
| `data-view="job"` | HTML attribute | Attribute value is a key in current View data, Object or Array will map to Sub views |
40+
| `<template>...</template>` | HTML tag | A `<template />` may map to a View or Sub views, `<!-- -->` is a Compatibility option |
41+
| `<input name="name">` | HTML tag | The same-name value of Data object will be updated by User's inputting |
42+
43+
[1]: https://developer.mozilla.org/en-US/docs/Web/HTML
44+
[2]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals
45+
[3]: https://developer.mozilla.org/en-US/docs/Web/API/element
46+
[4]: https://web-cell.tk/DOM-Renderer/class/source/view/View.js~View.html

0 commit comments

Comments
 (0)