@@ -3,4 +3,72 @@ Work in progress...
33derby-html-parser
44===============
55
6- Add HTML-based template parsing to Derby
6+ Add HTML-based template parsing to Derby.
7+
8+ This module depends on and extends ` derby-templates ` by implementing the ` View._parse() ` (and thus ` View.parse() ` ) function of
9+ ` derby-templates ` . It parses the html template source code and creates a template object (hierarchy?).
10+
11+ ` derby-parsing ` uses a modified ` esprima ` to parse its templates, called ` esprima-derby ` .
12+
13+ ## API
14+
15+ Additionally, ` derby-parsing ` exports the following functions.
16+
17+
18+ ### createTemplate(source, view)
19+
20+ Parses ` source ` (the full html template source) and returns a ` templates.Template ` object.
21+
22+
23+ ### createStringTemplate
24+
25+
26+ ### createExpression(source)
27+
28+ Parses ` source ` and creates an Expression hierarchy. ` source ` is the whole expression inside of ` {{ }} ` in a Derby template.
29+ Example:
30+ ```
31+ each _page.letters as #letter, #i
32+ ```
33+ Everything but the paths in such expressions is recorded as an ExpressionMeta object.
34+
35+
36+ The path (` _page.letters ` in this case) is then parsed using ` createPathExpression() ` , see the next section.
37+
38+
39+
40+ ### createPathExpression(source)
41+
42+ Parses ` source ` with ` esprima ` into a node tree and then reduces the node tree to an expression tree using
43+ ` derby-templates ` .
44+
45+
46+ An example:
47+
48+ ```
49+ createPathExpression("_page.colors[_page.key].name")
50+ ```
51+
52+ reduces to
53+
54+ ```
55+ new expressions.BracketsExpression(
56+ new expressions.PathExpression(['_page', 'colors']),
57+ new expressions.PathExpression(['_page', 'key']),
58+ ['name'])
59+ ```
60+
61+ which then returns
62+
63+ ```
64+ BracketsExpression {
65+ before: PathExpression { segments: [ '_page', 'colors' ], meta: undefined },
66+ inside: PathExpression { segments: [ '_page', 'key' ], meta: undefined },
67+ afterSegments: [ 'name' ],
68+ meta: undefined
69+ }
70+ ```
71+
72+
73+
74+ ### markup
0 commit comments