1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 | 'use strict';
|
16 |
|
17 | var CommonMarkUtils = require('@accordproject/markdown-common').CommonMarkUtils;
|
18 | var rules = {};
|
19 |
|
20 | rules.VariableDefinition = (visitor, thing, children, parameters, resultString, resultSeq) => {
|
21 | var result = [resultString('{{'), resultString(thing.name), resultString('}}')];
|
22 | resultSeq(parameters, result);
|
23 | };
|
24 | rules.FormattedVariableDefinition = (visitor, thing, children, parameters, resultString, resultSeq) => {
|
25 | var result = [resultString('{{'), resultString(thing.name), resultString(' as "'), resultString(thing.format), resultString('"}}')];
|
26 | resultSeq(parameters, result);
|
27 | };
|
28 | rules.EnumVariableDefinition = (visitor, thing, children, parameters, resultString, resultSeq) => {
|
29 | var result = [resultString('{{'), resultString(thing.name), resultString('}}')];
|
30 | resultSeq(parameters, result);
|
31 | };
|
32 | rules.FormulaDefinition = (visitor, thing, children, parameters, resultString, resultSeq) => {
|
33 | var result = [resultString('{{%'), resultString(thing.code), resultString('%}}')];
|
34 | resultSeq(parameters, result);
|
35 | };
|
36 | rules.ConditionalDefinition = (visitor, thing, children, parameters, resultString, resultSeq) => {
|
37 | var next1 = "{{#if ".concat(thing.name, "}}");
|
38 | var whenTrue = visitor.visitChildren(visitor, thing, parameters, 'whenTrue');
|
39 | var whenFalse = visitor.visitChildren(visitor, thing, parameters, 'whenFalse');
|
40 | var next2 = '{{/if}}';
|
41 | var result;
|
42 | if (whenFalse) {
|
43 | var next3 = '{{else}}';
|
44 | result = [resultString(next1), resultString(whenTrue), resultString(next3), resultString(whenFalse), resultString(next2)];
|
45 | } else {
|
46 | result = [resultString(next1), resultString(whenTrue), resultString(next2)];
|
47 | }
|
48 | resultSeq(parameters, result);
|
49 | };
|
50 | rules.OptionalDefinition = (visitor, thing, children, parameters, resultString, resultSeq) => {
|
51 | var next1 = "{{#optional ".concat(thing.name, "}}");
|
52 | var whenSome = visitor.visitChildren(visitor, thing, parameters, 'whenSome');
|
53 | var whenNone = visitor.visitChildren(visitor, thing, parameters, 'whenNone');
|
54 | var next2 = '{{/optional}}';
|
55 | var result;
|
56 | if (whenNone) {
|
57 | var next3 = '{{else}}';
|
58 | result = [resultString(next1), resultString(whenSome), resultString(next3), resultString(whenNone), resultString(next2)];
|
59 | } else {
|
60 | result = [resultString(next1), resultString(whenSome), resultString(next2)];
|
61 | }
|
62 | resultSeq(parameters, result);
|
63 | };
|
64 | rules.WithDefinition = (visitor, thing, children, parameters, resultString, resultSeq) => {
|
65 | var next1 = "{{#with ".concat(thing.name, "}}");
|
66 | var next2 = '{{/with}}';
|
67 | var result = [resultString(next1), children, resultString(next2)];
|
68 | resultSeq(parameters, result);
|
69 | };
|
70 | rules.JoinDefinition = (visitor, thing, children, parameters, resultString, resultSeq) => {
|
71 | var sepAttr = thing.separator ? ' separator="' + thing.separator + '"' : '';
|
72 | var next1 = "{{#join ".concat(thing.name).concat(sepAttr, "}}");
|
73 | var next2 = '{{/join}}';
|
74 | var result = [resultString(next1), children, resultString(next2)];
|
75 | resultSeq(parameters, result);
|
76 | };
|
77 |
|
78 | rules.ListBlockDefinition = (visitor, thing, children, parameters, resultString, resultSeq) => {
|
79 | var listKind = thing.type === 'bullet' ? 'ulist' : 'olist';
|
80 | var prefix = CommonMarkUtils.mkPrefix(parameters, 1);
|
81 | var next1 = prefix;
|
82 | var next2 = "{{#".concat(listKind, " ").concat(thing.name, "}}\n");
|
83 | var next3 = prefix;
|
84 | var next4 = "{{/".concat(listKind, "}}");
|
85 | var result = [resultString(next1), resultString(next2), children, resultString(next3), resultString(next4)];
|
86 | resultSeq(parameters, result);
|
87 | };
|
88 | rules.ClauseDefinition = (visitor, thing, children, parameters, resultString, resultSeq) => {
|
89 | var next1 = CommonMarkUtils.mkPrefix(parameters, 2);
|
90 | var srcAttr = thing.src ? ' src="' + thing.src + '"' : '';
|
91 | var next2 = "{{#clause ".concat(thing.name).concat(srcAttr, "}}\n");
|
92 | var next3 = '\n{{/clause}}';
|
93 | var result = [resultString(next1), resultString(next2), children, resultString(next3)];
|
94 | resultSeq(parameters, result);
|
95 | };
|
96 | module.exports = rules; |
\ | No newline at end of file |