Skip to content

Commit c3d2746

Browse files
committed
README
1 parent 18a2497 commit c3d2746

File tree

1 file changed

+70
-0
lines changed

1 file changed

+70
-0
lines changed

README.md

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,73 @@ var template = derbyParsing.createTemplate(templateSource);
2323
```shell
2424
npm test
2525
```
26+
27+
28+
29+
This module depends on and extends `derby-templates` by implementing the `View._parse()` (and thus `View.parse()`) function of
30+
`derby-templates`. It parses the html template source code and creates a template object (hierarchy?).
31+
32+
`derby-parsing` uses a modified `esprima` to parse its templates, called `esprima-derby`.
33+
34+
## API
35+
36+
Additionally, `derby-parsing` exports the following functions.
37+
38+
39+
### createTemplate(source, view)
40+
41+
Parses `source` (the full html template source) and returns a `templates.Template` object.
42+
43+
44+
### createStringTemplate
45+
46+
47+
### createExpression(source)
48+
49+
Parses `source` and creates an Expression hierarchy. `source` is the whole expression inside of `{{ }}` in a Derby template.
50+
Example:
51+
```
52+
each _page.letters as #letter, #i
53+
```
54+
Everything but the paths in such expressions is recorded as an ExpressionMeta object.
55+
56+
57+
The path (`_page.letters` in this case) is then parsed using `createPathExpression()`, see the next section.
58+
59+
60+
61+
### createPathExpression(source)
62+
63+
Parses `source` with `esprima` into a node tree and then reduces the node tree to an expression tree using
64+
`derby-templates`.
65+
66+
67+
An example:
68+
69+
```
70+
createPathExpression("_page.colors[_page.key].name")
71+
```
72+
73+
reduces to
74+
75+
```
76+
new expressions.BracketsExpression(
77+
new expressions.PathExpression(['_page', 'colors']),
78+
new expressions.PathExpression(['_page', 'key']),
79+
['name'])
80+
```
81+
82+
which then returns
83+
84+
```
85+
BracketsExpression {
86+
before: PathExpression { segments: [ '_page', 'colors' ], meta: undefined },
87+
inside: PathExpression { segments: [ '_page', 'key' ], meta: undefined },
88+
afterSegments: [ 'name' ],
89+
meta: undefined
90+
}
91+
```
92+
93+
94+
95+
### markup

0 commit comments

Comments
 (0)