1 | var ignore = 'ignore',
|
2 | missing = 'missing',
|
3 | only = 'only',
|
4 | attrs = ["id", "mode", "group", "for", "model"];
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 | exports.compile = function(compiler, args) {
|
33 | var file = args.shift(),
|
34 | onlyIdx = args.indexOf(only),
|
35 | onlyCtx = onlyIdx !== -1 ? args.splice(onlyIdx, 1) : false,
|
36 | parentFile = (args.pop() || '').replace(/\\/g, '\\\\'),
|
37 | ignore = args[args.length - 1] === missing ? (args.pop()) : false,
|
38 | w = args.filter(function(o) {
|
39 | return !o.k;
|
40 | }).join(' '),
|
41 | w_args = {
|
42 | id: "spage",
|
43 | mode: "async"
|
44 | };
|
45 |
|
46 | args.map(function(w) {
|
47 | if (w.k) w_args[w.k] = w.v;
|
48 | });
|
49 |
|
50 | return (ignore ? ' try {\n' : '') +
|
51 | 'var w_args = ' + JSON.stringify(w_args) + ';' +
|
52 | 'if (_ctx.isQuickingMode){w_args.mode="quickling"}' +
|
53 | '_output += _swig._w(_ctx._yog, '+ file+', w_args, {' +
|
54 | 'resolveFrom: "' + parentFile + '"' +
|
55 | '})(' +
|
56 | ((onlyCtx && w) ? w : (!w ? '_ctx' : '_utils.extend({}, _ctx, ' + w + ')')) +
|
57 | ');\n' +
|
58 | (ignore ? '} catch (e) {}\n' : '');
|
59 | };
|
60 |
|
61 | exports.parse = function(str, line, parser, types, stack, opts) {
|
62 | var file, w, k;
|
63 |
|
64 | parser.on(types.STRING, function(token) {
|
65 |
|
66 | if (!file) {
|
67 | file = token.match;
|
68 | this.out.push(file);
|
69 | return;
|
70 | }
|
71 |
|
72 | var out = {
|
73 | v: '',
|
74 | k: ''
|
75 | };
|
76 |
|
77 | if (~attrs.indexOf(k)) {
|
78 | out.v = token.match.replace(/^("|')?(.*)\1$/g, '$2');
|
79 | out.k = k;
|
80 | this.out.push(out);
|
81 | v = '';
|
82 | }
|
83 |
|
84 | });
|
85 |
|
86 | parser.on(types.VAR, function(token) {
|
87 | if (!file) {
|
88 | k = '';
|
89 | file = token.match;
|
90 | return true;
|
91 | }
|
92 |
|
93 | if (~attrs.indexOf(token.match)) {
|
94 | k = token.match;
|
95 | return false;
|
96 | }
|
97 |
|
98 | if (!w && token.match === 'with') {
|
99 | w = true;
|
100 | return;
|
101 | }
|
102 |
|
103 | if (w && token.match === only && this.prevToken.match !== 'with') {
|
104 | this.out.push(token.match);
|
105 | return;
|
106 | }
|
107 |
|
108 | if (token.match === ignore) {
|
109 | return false;
|
110 | }
|
111 |
|
112 | if (token.match === missing) {
|
113 | if (this.prevToken.match !== ignore) {
|
114 | throw new Error('Unexpected token "' + missing + '" on line ' + line + '.');
|
115 | }
|
116 | this.out.push(token.match);
|
117 | return false;
|
118 | }
|
119 |
|
120 | if (this.prevToken.match === ignore) {
|
121 | throw new Error('Expected "' + missing + '" on line ' + line + ' but found "' + token.match + '".');
|
122 | }
|
123 |
|
124 | return true;
|
125 | });
|
126 |
|
127 | parser.on('end', function() {
|
128 | this.out.push(opts.filename || null);
|
129 | });
|
130 |
|
131 | return true;
|
132 | };
|
133 |
|
134 | exports.ends = false; |
\ | No newline at end of file |