@kosatyi/ejs 0.0.13 → 0.0.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/build.js +33 -0
- package/dist/ejs.cjs +218 -432
- package/dist/ejs.js +218 -432
- package/dist/ejs.min.js +1 -1
- package/dist/ejs.mjs +215 -355
- package/package.json +5 -3
package/dist/ejs.js
CHANGED
|
@@ -11,20 +11,15 @@
|
|
|
11
11
|
defaults.cache = true;
|
|
12
12
|
defaults.path = 'views';
|
|
13
13
|
defaults.resolver = null;
|
|
14
|
-
defaults.extension =
|
|
15
|
-
|
|
16
|
-
module: 'mjs'
|
|
17
|
-
};
|
|
14
|
+
defaults.extension = 'ejs';
|
|
15
|
+
defaults.withObject = false;
|
|
18
16
|
defaults.vars = {
|
|
19
|
-
|
|
17
|
+
SCOPE: 'ejs',
|
|
18
|
+
EXTEND: '$$e',
|
|
20
19
|
BUFFER: '$$a',
|
|
21
|
-
OUTPUT: '$$i',
|
|
22
20
|
LAYOUT: '$$l',
|
|
23
|
-
MACROS: '$$m',
|
|
24
|
-
PRINT: '$$j',
|
|
25
21
|
BLOCKS: '$$b',
|
|
26
|
-
|
|
27
|
-
SCOPE: '$$s',
|
|
22
|
+
MACRO: '$$m',
|
|
28
23
|
SAFE: '$$v'
|
|
29
24
|
};
|
|
30
25
|
defaults.token = {
|
|
@@ -65,11 +60,9 @@
|
|
|
65
60
|
'"': '"',
|
|
66
61
|
"'": '''
|
|
67
62
|
};
|
|
68
|
-
|
|
69
63
|
var regexKeys = function regexKeys(obj) {
|
|
70
64
|
return new RegExp(['[', Object.keys(obj).join(''), ']'].join(''), 'g');
|
|
71
65
|
};
|
|
72
|
-
|
|
73
66
|
var htmlEntitiesMatch = regexKeys(htmlEntities);
|
|
74
67
|
var symbolEntitiesMatch = regexKeys(symbolEntities);
|
|
75
68
|
var entities = function entities() {
|
|
@@ -99,7 +92,6 @@
|
|
|
99
92
|
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
100
93
|
args[_key] = arguments[_key];
|
|
101
94
|
}
|
|
102
|
-
|
|
103
95
|
var target = args.shift();
|
|
104
96
|
return args.filter(function (source) {
|
|
105
97
|
return source;
|
|
@@ -107,9 +99,9 @@
|
|
|
107
99
|
return Object.assign(target, source);
|
|
108
100
|
}, target);
|
|
109
101
|
};
|
|
102
|
+
var noop = function noop() {};
|
|
110
103
|
var each = function each(object, callback) {
|
|
111
104
|
var prop;
|
|
112
|
-
|
|
113
105
|
for (prop in object) {
|
|
114
106
|
if (hasProp(object, prop)) {
|
|
115
107
|
callback(object[prop], prop, object);
|
|
@@ -120,7 +112,6 @@
|
|
|
120
112
|
var result = [];
|
|
121
113
|
each(object, function (value, key, object) {
|
|
122
114
|
var item = callback(value, key, object);
|
|
123
|
-
|
|
124
115
|
if (item !== undefined) {
|
|
125
116
|
result.push(item);
|
|
126
117
|
}
|
|
@@ -132,7 +123,6 @@
|
|
|
132
123
|
var result = isArray ? [] : {};
|
|
133
124
|
each(object, function (value, key, object) {
|
|
134
125
|
var item = callback(value, key, object);
|
|
135
|
-
|
|
136
126
|
if (item !== undefined) {
|
|
137
127
|
if (isArray) {
|
|
138
128
|
result.push(item);
|
|
@@ -150,6 +140,9 @@
|
|
|
150
140
|
}
|
|
151
141
|
});
|
|
152
142
|
};
|
|
143
|
+
var resolve$1 = function resolve(value, callback, context) {
|
|
144
|
+
return Promise.resolve(value).then(callback.bind(context));
|
|
145
|
+
};
|
|
153
146
|
var hasProp = function hasProp(object, prop) {
|
|
154
147
|
return object && object.hasOwnProperty(prop);
|
|
155
148
|
};
|
|
@@ -170,15 +163,12 @@
|
|
|
170
163
|
}
|
|
171
164
|
}).join(space);
|
|
172
165
|
result.push([lt, tag, space, attributes, gt].join(''));
|
|
173
|
-
|
|
174
166
|
if (content) {
|
|
175
167
|
result.push(content instanceof Array ? content.join('') : content);
|
|
176
168
|
}
|
|
177
|
-
|
|
178
169
|
if (hasClosedTag) {
|
|
179
170
|
result.push([lt, slash, tag, gt].join(''));
|
|
180
171
|
}
|
|
181
|
-
|
|
182
172
|
return result.join('');
|
|
183
173
|
}
|
|
184
174
|
|
|
@@ -203,7 +193,6 @@
|
|
|
203
193
|
return "')\n".concat(value, "\n").concat(this.BUFFER, "('");
|
|
204
194
|
}
|
|
205
195
|
}];
|
|
206
|
-
|
|
207
196
|
var match = function match(regex, text, callback) {
|
|
208
197
|
var index = 0;
|
|
209
198
|
text.replace(regex, function () {
|
|
@@ -217,16 +206,14 @@
|
|
|
217
206
|
};
|
|
218
207
|
/**
|
|
219
208
|
*
|
|
220
|
-
* @param {
|
|
209
|
+
* @param {object} config
|
|
221
210
|
* @return {function(*, *): Function}
|
|
222
211
|
* @constructor
|
|
223
212
|
*/
|
|
224
|
-
|
|
225
|
-
|
|
226
213
|
var Compiler = function Compiler(config) {
|
|
214
|
+
var withObject = config.withObject;
|
|
227
215
|
var token = config.token;
|
|
228
216
|
var vars = config.vars;
|
|
229
|
-
var module = config.extension.module;
|
|
230
217
|
var matches = [];
|
|
231
218
|
var formats = [];
|
|
232
219
|
var slurp = {
|
|
@@ -242,22 +229,15 @@
|
|
|
242
229
|
var slurpStart = new RegExp([slurp.match, slurp.start].join(''), 'gm');
|
|
243
230
|
var slurpEnd = new RegExp([slurp.end, slurp.match].join(''), 'gm');
|
|
244
231
|
/**
|
|
245
|
-
* @type
|
|
232
|
+
* @type function
|
|
246
233
|
* @name Compile
|
|
247
234
|
*/
|
|
248
|
-
|
|
249
235
|
return function (content, path) {
|
|
250
236
|
var SCOPE = vars.SCOPE,
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
var extension = path.split('.').pop();
|
|
237
|
+
SAFE = vars.SAFE,
|
|
238
|
+
BUFFER = vars.BUFFER;
|
|
254
239
|
content = content.replace(/[\r\n]+/g, '\n').replace(/^\s+|\s+$/gm, '');
|
|
255
240
|
content = content.replace(slurpStart, slurp.start).replace(slurpEnd, slurp.end);
|
|
256
|
-
|
|
257
|
-
if (extension === module) {
|
|
258
|
-
content = [token.start, content, token.end].join('\n');
|
|
259
|
-
}
|
|
260
|
-
|
|
261
241
|
var source = "".concat(BUFFER, "('");
|
|
262
242
|
match(regex, content, function (params, index, offset) {
|
|
263
243
|
source += symbols(content.slice(index, offset));
|
|
@@ -266,20 +246,22 @@
|
|
|
266
246
|
});
|
|
267
247
|
});
|
|
268
248
|
source += "');";
|
|
269
|
-
source = "
|
|
249
|
+
source = "try{".concat(source, "}catch(e){console.info(e)}");
|
|
250
|
+
if (withObject) {
|
|
251
|
+
source = "with(".concat(SCOPE, "){").concat(source, "}");
|
|
252
|
+
}
|
|
270
253
|
source = "".concat(BUFFER, ".start();").concat(source, "return ").concat(BUFFER, ".end();");
|
|
271
254
|
source += "\n//# sourceURL=".concat(path);
|
|
272
255
|
var result = null;
|
|
273
|
-
|
|
274
256
|
try {
|
|
275
257
|
result = new Function(SCOPE, BUFFER, SAFE, source);
|
|
276
|
-
result.source = "(function(".concat(SCOPE, ",").concat(BUFFER, ",").concat(SAFE, "){\n").concat(source, "\n})");
|
|
258
|
+
result.source = "(function(".concat(SCOPE, ",").concat(BUFFER, ",").concat(SAFE, "){\n").concat(source, "\n})");
|
|
277
259
|
} catch (e) {
|
|
260
|
+
console.log(e);
|
|
278
261
|
e.filename = path;
|
|
279
262
|
e.source = source;
|
|
280
263
|
throw e;
|
|
281
264
|
}
|
|
282
|
-
|
|
283
265
|
return result;
|
|
284
266
|
};
|
|
285
267
|
};
|
|
@@ -301,7 +283,6 @@
|
|
|
301
283
|
return response.text();
|
|
302
284
|
});
|
|
303
285
|
};
|
|
304
|
-
|
|
305
286
|
var FileSystem = function FileSystem(template) {
|
|
306
287
|
return new Promise(function (resolve, reject) {
|
|
307
288
|
path.readFile(template, function (error, data) {
|
|
@@ -313,7 +294,6 @@
|
|
|
313
294
|
});
|
|
314
295
|
});
|
|
315
296
|
};
|
|
316
|
-
|
|
317
297
|
var Watcher = function Watcher(path$1, cache) {
|
|
318
298
|
return path.watch('.', {
|
|
319
299
|
cwd: path$1
|
|
@@ -323,60 +303,37 @@
|
|
|
323
303
|
console.log('watcher error: ' + error);
|
|
324
304
|
});
|
|
325
305
|
};
|
|
326
|
-
|
|
327
306
|
var Template = function Template(config, cache, compile) {
|
|
328
307
|
var path = config.path;
|
|
329
308
|
config.token || {};
|
|
330
309
|
var resolver = isFunction(config.resolver) ? config.resolver : isNode() ? FileSystem : HttpRequest;
|
|
331
|
-
|
|
332
310
|
var normalize = function normalize(template) {
|
|
333
311
|
template = [path, template].join('/');
|
|
334
312
|
template = template.replace(/\/\//g, '/');
|
|
335
313
|
return template;
|
|
336
314
|
};
|
|
337
|
-
|
|
338
315
|
var resolve = function resolve(template) {
|
|
339
316
|
return resolver(normalize(template));
|
|
340
317
|
};
|
|
341
|
-
|
|
342
318
|
var result = function result(content, template) {
|
|
343
319
|
cache.set(template, content);
|
|
344
320
|
return content;
|
|
345
321
|
};
|
|
346
|
-
|
|
347
322
|
var get = function get(template) {
|
|
348
323
|
if (cache.exist(template)) {
|
|
349
324
|
return cache.resolve(template);
|
|
350
325
|
}
|
|
351
|
-
|
|
352
326
|
var content = resolve(template).then(function (content) {
|
|
353
327
|
return result(compile(content, template), template);
|
|
354
328
|
});
|
|
355
329
|
return result(content, template);
|
|
356
330
|
};
|
|
357
|
-
|
|
358
331
|
if (config.watch && isNode()) {
|
|
359
332
|
Watcher(path, cache);
|
|
360
333
|
}
|
|
361
|
-
|
|
362
334
|
return get;
|
|
363
335
|
};
|
|
364
336
|
|
|
365
|
-
function _defineProperty(obj, key, value) {
|
|
366
|
-
if (key in obj) {
|
|
367
|
-
Object.defineProperty(obj, key, {
|
|
368
|
-
value: value,
|
|
369
|
-
enumerable: true,
|
|
370
|
-
configurable: true,
|
|
371
|
-
writable: true
|
|
372
|
-
});
|
|
373
|
-
} else {
|
|
374
|
-
obj[key] = value;
|
|
375
|
-
}
|
|
376
|
-
|
|
377
|
-
return obj;
|
|
378
|
-
}
|
|
379
|
-
|
|
380
337
|
var resolve = function resolve(list) {
|
|
381
338
|
return Promise.all(list).then(function (list) {
|
|
382
339
|
return list.join('');
|
|
@@ -386,408 +343,249 @@
|
|
|
386
343
|
*
|
|
387
344
|
* @return {function}
|
|
388
345
|
*/
|
|
389
|
-
|
|
390
|
-
|
|
391
346
|
var Buffer = function Buffer() {
|
|
392
347
|
var store = [],
|
|
393
|
-
|
|
394
|
-
|
|
348
|
+
array = [];
|
|
395
349
|
function buffer(value) {
|
|
396
350
|
array.push(value);
|
|
397
351
|
}
|
|
398
|
-
|
|
399
352
|
buffer.start = function () {
|
|
400
353
|
array = [];
|
|
401
354
|
};
|
|
402
|
-
|
|
403
355
|
buffer.backup = function () {
|
|
404
356
|
store.push(array.concat());
|
|
405
357
|
array = [];
|
|
406
358
|
};
|
|
407
|
-
|
|
408
359
|
buffer.restore = function () {
|
|
409
360
|
var result = array.concat();
|
|
410
361
|
array = store.pop();
|
|
411
362
|
return resolve(result);
|
|
412
363
|
};
|
|
413
|
-
|
|
364
|
+
buffer.error = function (e) {
|
|
365
|
+
throw e;
|
|
366
|
+
};
|
|
414
367
|
buffer.end = function () {
|
|
415
368
|
return resolve(array);
|
|
416
369
|
};
|
|
417
|
-
|
|
418
370
|
return buffer;
|
|
419
371
|
};
|
|
420
372
|
|
|
421
373
|
/**
|
|
422
|
-
*
|
|
423
|
-
* @
|
|
424
|
-
* @
|
|
374
|
+
* @memberOf global
|
|
375
|
+
* @class
|
|
376
|
+
* @alias ejs
|
|
377
|
+
* @param config
|
|
378
|
+
* @param methods
|
|
379
|
+
* @return {Scope}
|
|
425
380
|
*/
|
|
426
381
|
|
|
427
|
-
var
|
|
428
|
-
var defaults = extend({}, instance.props);
|
|
429
|
-
var create = instance.create;
|
|
430
|
-
return {
|
|
431
|
-
element: element,
|
|
432
|
-
create: create,
|
|
433
|
-
render: function render(props) {
|
|
434
|
-
return this.create(extend({}, defaults, props));
|
|
435
|
-
}
|
|
436
|
-
};
|
|
437
|
-
};
|
|
438
|
-
|
|
439
|
-
var Scope = function Scope(config, methods) {
|
|
440
|
-
var _Object$definePropert;
|
|
441
|
-
|
|
442
|
-
/**
|
|
443
|
-
*
|
|
444
|
-
*/
|
|
382
|
+
var configure = function configure(config, methods) {
|
|
445
383
|
var _config$vars = config.vars,
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
384
|
+
EXTEND = _config$vars.EXTEND,
|
|
385
|
+
LAYOUT = _config$vars.LAYOUT,
|
|
386
|
+
BLOCKS = _config$vars.BLOCKS,
|
|
387
|
+
BUFFER = _config$vars.BUFFER,
|
|
388
|
+
MACRO = _config$vars.MACRO;
|
|
389
|
+
|
|
451
390
|
/**
|
|
452
391
|
*
|
|
453
392
|
* @param data
|
|
454
393
|
* @constructor
|
|
455
394
|
*/
|
|
456
|
-
|
|
457
395
|
function Scope() {
|
|
458
396
|
var data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
459
|
-
this.
|
|
397
|
+
this.initBlocks();
|
|
398
|
+
this.initMacro();
|
|
460
399
|
extend(this, data);
|
|
461
|
-
this.setLayout(false);
|
|
462
|
-
this.setExtend(false);
|
|
463
400
|
}
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
401
|
+
Scope.helpers = function (methods) {
|
|
402
|
+
extend(Scope.prototype, methods);
|
|
403
|
+
};
|
|
404
|
+
Scope.property = function (name, descriptor) {
|
|
405
|
+
Object.defineProperty(Scope.prototype, name, descriptor);
|
|
406
|
+
};
|
|
407
|
+
Scope.method = function (name, method) {
|
|
408
|
+
Object.defineProperty(Scope.prototype, name, {
|
|
409
|
+
value: method,
|
|
410
|
+
writable: false,
|
|
411
|
+
configurable: false,
|
|
412
|
+
enumerable: false
|
|
413
|
+
});
|
|
414
|
+
};
|
|
415
|
+
Scope.property(BUFFER, {
|
|
470
416
|
value: Buffer(),
|
|
471
417
|
writable: false,
|
|
472
418
|
configurable: false,
|
|
473
419
|
enumerable: false
|
|
474
|
-
})
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
})
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
})
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
})
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
})
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
})
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
})
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
})
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
Scope.
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
420
|
+
});
|
|
421
|
+
Scope.property(BLOCKS, {
|
|
422
|
+
value: {},
|
|
423
|
+
writable: true,
|
|
424
|
+
configurable: false,
|
|
425
|
+
enumerable: false
|
|
426
|
+
});
|
|
427
|
+
Scope.property(MACRO, {
|
|
428
|
+
value: {},
|
|
429
|
+
writable: true,
|
|
430
|
+
configurable: false,
|
|
431
|
+
enumerable: false
|
|
432
|
+
});
|
|
433
|
+
Scope.property(LAYOUT, {
|
|
434
|
+
value: false,
|
|
435
|
+
writable: true,
|
|
436
|
+
configurable: false,
|
|
437
|
+
enumerable: false
|
|
438
|
+
});
|
|
439
|
+
Scope.property(EXTEND, {
|
|
440
|
+
value: false,
|
|
441
|
+
writable: true,
|
|
442
|
+
configurable: false,
|
|
443
|
+
enumerable: false
|
|
444
|
+
});
|
|
445
|
+
Scope.method('initBlocks', function () {
|
|
446
|
+
this[BLOCKS] = {};
|
|
447
|
+
});
|
|
448
|
+
Scope.method('initMacro', function () {
|
|
449
|
+
this[MACRO] = {};
|
|
450
|
+
});
|
|
451
|
+
Scope.method('getMacro', function () {
|
|
452
|
+
return this[MACRO];
|
|
453
|
+
});
|
|
454
|
+
Scope.method('getBuffer', function () {
|
|
455
|
+
return this[BUFFER];
|
|
456
|
+
});
|
|
457
|
+
Scope.method('getBlocks', function () {
|
|
458
|
+
return this[BLOCKS];
|
|
459
|
+
});
|
|
460
|
+
Scope.method('setExtend', function (value) {
|
|
461
|
+
this[EXTEND] = value;
|
|
462
|
+
});
|
|
463
|
+
Scope.method('getExtend', function () {
|
|
464
|
+
return this[EXTEND];
|
|
465
|
+
});
|
|
466
|
+
Scope.method('setLayout', function (layout) {
|
|
467
|
+
this[LAYOUT] = layout;
|
|
468
|
+
});
|
|
469
|
+
Scope.method('getLayout', function () {
|
|
470
|
+
return this[LAYOUT];
|
|
471
|
+
});
|
|
472
|
+
Scope.method('clone', function (exclude_blocks) {
|
|
473
|
+
var filter = [LAYOUT, EXTEND, BUFFER];
|
|
474
|
+
if (exclude_blocks === true) {
|
|
475
|
+
filter.push(BLOCKS);
|
|
476
|
+
}
|
|
477
|
+
return omit(this, filter);
|
|
478
|
+
});
|
|
479
|
+
Scope.method('extend', function (layout) {
|
|
480
|
+
this.setExtend(true);
|
|
481
|
+
this.setLayout(layout);
|
|
482
|
+
});
|
|
483
|
+
Scope.method('echo', function () {
|
|
484
|
+
var buffer = this.getBuffer();
|
|
485
|
+
var params = [].slice.call(arguments);
|
|
486
|
+
params.forEach(function (item) {
|
|
487
|
+
buffer(item);
|
|
488
|
+
});
|
|
489
|
+
});
|
|
490
|
+
Scope.method('fn', function (callback) {
|
|
491
|
+
var buffer = this.getBuffer();
|
|
492
|
+
var context = this;
|
|
493
|
+
return function () {
|
|
494
|
+
buffer.backup();
|
|
495
|
+
if (isFunction(callback)) {
|
|
496
|
+
callback.apply(context, arguments);
|
|
540
497
|
}
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
498
|
+
return buffer.restore();
|
|
499
|
+
};
|
|
500
|
+
});
|
|
501
|
+
Scope.method('get', function (name, defaults) {
|
|
502
|
+
var path = getPath(this, name);
|
|
503
|
+
var result = path.shift();
|
|
504
|
+
var prop = path.pop();
|
|
505
|
+
return hasProp(result, prop) ? result[prop] : defaults;
|
|
506
|
+
});
|
|
507
|
+
Scope.method('set', function (name, value) {
|
|
508
|
+
var path = getPath(this, name);
|
|
509
|
+
var result = path.shift();
|
|
510
|
+
var prop = path.pop();
|
|
511
|
+
if (this.getExtend() && hasProp(result, prop)) {
|
|
512
|
+
return result[prop];
|
|
513
|
+
}
|
|
514
|
+
return result[prop] = value;
|
|
515
|
+
});
|
|
516
|
+
Scope.method('macro', function (name, callback) {
|
|
517
|
+
var list = this.getMacro();
|
|
518
|
+
var macro = this.fn(callback);
|
|
519
|
+
var context = this;
|
|
520
|
+
list[name] = function () {
|
|
521
|
+
return context.echo(macro.apply(undefined, arguments));
|
|
522
|
+
};
|
|
523
|
+
});
|
|
524
|
+
Scope.method('call', function (name) {
|
|
525
|
+
var list = this.getMacro();
|
|
526
|
+
var macro = list[name];
|
|
527
|
+
var params = [].slice.call(arguments, 1);
|
|
528
|
+
if (isFunction(macro)) {
|
|
529
|
+
return macro.apply(macro, params);
|
|
530
|
+
}
|
|
531
|
+
});
|
|
532
|
+
Scope.method('block', function (name, callback) {
|
|
533
|
+
var _this = this;
|
|
534
|
+
var blocks = this.getBlocks();
|
|
535
|
+
blocks[name] = blocks[name] || [];
|
|
536
|
+
blocks[name].push(this.fn(callback));
|
|
537
|
+
if (this.getExtend()) return;
|
|
538
|
+
var list = Object.assign([], blocks[name]);
|
|
539
|
+
var current = function current() {
|
|
540
|
+
return list.shift();
|
|
541
|
+
};
|
|
542
|
+
var next = function next() {
|
|
543
|
+
var parent = current();
|
|
544
|
+
if (parent) {
|
|
545
|
+
return function () {
|
|
546
|
+
_this.echo(parent(next()));
|
|
547
|
+
};
|
|
548
|
+
} else {
|
|
549
|
+
return noop;
|
|
550
|
+
}
|
|
551
|
+
};
|
|
552
|
+
this.echo(current()(next()));
|
|
553
|
+
});
|
|
554
|
+
Scope.method('include', function (path, data, cx) {
|
|
555
|
+
var context = cx === false ? {} : this.clone(true);
|
|
556
|
+
var params = extend(context, data || {});
|
|
557
|
+
var promise = this.render(path, params);
|
|
558
|
+
this.echo(promise);
|
|
559
|
+
});
|
|
560
|
+
Scope.method('use', function (path, namespace) {
|
|
561
|
+
var promise = this.require(path);
|
|
562
|
+
this.echo(resolve$1(promise, function (exports) {
|
|
563
|
+
var list = this.getMacro();
|
|
564
|
+
each(exports, function (macro, name) {
|
|
565
|
+
list[[namespace, name].join('.')] = macro;
|
|
555
566
|
});
|
|
556
|
-
},
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
var buffer = this.getBuffer();
|
|
567
|
-
|
|
568
|
-
var macro = function () {
|
|
569
|
-
buffer.backup();
|
|
570
|
-
|
|
571
|
-
if (isFunction(callback)) {
|
|
572
|
-
callback.apply(this, arguments);
|
|
573
|
-
}
|
|
574
|
-
|
|
575
|
-
var result = buffer.restore();
|
|
576
|
-
return echo === true ? this.echo(result) : result;
|
|
577
|
-
}.bind(this);
|
|
578
|
-
|
|
579
|
-
macro.__context = this;
|
|
580
|
-
macro.__source = callback;
|
|
581
|
-
macro.__layout = this.getLayout();
|
|
582
|
-
return macro;
|
|
583
|
-
},
|
|
584
|
-
|
|
585
|
-
/**
|
|
586
|
-
* @memberOf global
|
|
587
|
-
* @param value
|
|
588
|
-
* @param callback
|
|
589
|
-
* @return {Promise<unknown>}
|
|
590
|
-
*/
|
|
591
|
-
resolve: function resolve(value, callback) {
|
|
592
|
-
return Promise.resolve(value).then(callback.bind(this));
|
|
593
|
-
},
|
|
594
|
-
|
|
595
|
-
/**
|
|
596
|
-
* @memberOf global
|
|
597
|
-
*/
|
|
598
|
-
async: function async(promise, callback) {
|
|
599
|
-
var _this = this;
|
|
600
|
-
|
|
601
|
-
this.echo(this.resolve(promise, function (data) {
|
|
602
|
-
return _this.macro(callback)(data);
|
|
603
|
-
}));
|
|
604
|
-
},
|
|
605
|
-
|
|
606
|
-
/**
|
|
607
|
-
* @memberOf global
|
|
608
|
-
*/
|
|
609
|
-
node: element,
|
|
610
|
-
|
|
611
|
-
/**
|
|
612
|
-
* @memberOf global
|
|
613
|
-
*/
|
|
614
|
-
element: function element$1(tag, attr, content) {
|
|
567
|
+
}, this));
|
|
568
|
+
});
|
|
569
|
+
Scope.method('async', function (promise, callback) {
|
|
570
|
+
this.echo(resolve$1(promise, function (data) {
|
|
571
|
+
return this.fn(callback)(data);
|
|
572
|
+
}, this));
|
|
573
|
+
});
|
|
574
|
+
Scope.helpers(methods);
|
|
575
|
+
Scope.helpers({
|
|
576
|
+
el: function el(tag, attr, content) {
|
|
615
577
|
if (isFunction(content)) {
|
|
616
|
-
content = this.
|
|
578
|
+
content = this.fn(content)();
|
|
617
579
|
}
|
|
618
|
-
|
|
619
|
-
this.echo(this.resolve(content, function (content) {
|
|
580
|
+
this.echo(resolve$1(content, function (content) {
|
|
620
581
|
return element(tag, attr, content);
|
|
621
|
-
}));
|
|
622
|
-
},
|
|
623
|
-
|
|
624
|
-
/**
|
|
625
|
-
* @memberOf global
|
|
626
|
-
* @param {String} namespace
|
|
627
|
-
* @param {Object} instance
|
|
628
|
-
*/
|
|
629
|
-
component: function component(namespace, instance) {
|
|
630
|
-
instance = Component(instance);
|
|
631
|
-
this.set(namespace, function (props) {
|
|
632
|
-
this.echo(instance.render(props));
|
|
633
|
-
}.bind(this));
|
|
634
|
-
},
|
|
635
|
-
|
|
636
|
-
/**
|
|
637
|
-
* @memberOf global
|
|
638
|
-
* @param name
|
|
639
|
-
* @param defaults
|
|
640
|
-
*/
|
|
641
|
-
get: function get(name, defaults) {
|
|
642
|
-
var path = getPath(this, name);
|
|
643
|
-
var result = path.shift();
|
|
644
|
-
var prop = path.pop();
|
|
645
|
-
return hasProp(result, prop) ? result[prop] : defaults;
|
|
646
|
-
},
|
|
647
|
-
|
|
648
|
-
/**
|
|
649
|
-
* @memberOf global
|
|
650
|
-
* @param {String} name
|
|
651
|
-
* @param value
|
|
652
|
-
* @return
|
|
653
|
-
*/
|
|
654
|
-
set: function set(name, value) {
|
|
655
|
-
var path = getPath(this, name);
|
|
656
|
-
var result = path.shift();
|
|
657
|
-
var prop = path.pop();
|
|
658
|
-
|
|
659
|
-
if (this.getExtend()) {
|
|
660
|
-
if (hasProp(result, prop)) {
|
|
661
|
-
return result[prop];
|
|
662
|
-
}
|
|
663
|
-
}
|
|
664
|
-
|
|
665
|
-
result[prop] = value;
|
|
666
|
-
},
|
|
667
|
-
|
|
668
|
-
/**
|
|
669
|
-
* @memberOf global
|
|
670
|
-
* @param name
|
|
671
|
-
*/
|
|
672
|
-
call: function call(name) {
|
|
673
|
-
var params = [].slice.call(arguments, 1);
|
|
674
|
-
var path = getPath(this, name);
|
|
675
|
-
var result = path.shift();
|
|
676
|
-
var prop = path.pop();
|
|
677
|
-
|
|
678
|
-
if (isFunction(result[prop])) {
|
|
679
|
-
return result[prop].apply(result, params);
|
|
680
|
-
}
|
|
582
|
+
}, this));
|
|
681
583
|
},
|
|
682
|
-
|
|
683
|
-
/**
|
|
684
|
-
* @memberOf global
|
|
685
|
-
* @param object
|
|
686
|
-
* @param callback
|
|
687
|
-
*/
|
|
688
584
|
each: function each$1(object, callback) {
|
|
689
585
|
if (isString(object)) {
|
|
690
586
|
object = this.get(object, []);
|
|
691
587
|
}
|
|
692
|
-
|
|
693
588
|
each(object, callback);
|
|
694
|
-
},
|
|
695
|
-
|
|
696
|
-
/**
|
|
697
|
-
* @memberOf global
|
|
698
|
-
* @param {String} layout
|
|
699
|
-
*/
|
|
700
|
-
extend: function extend(layout) {
|
|
701
|
-
this.setExtend(true);
|
|
702
|
-
this.setLayout(layout);
|
|
703
|
-
},
|
|
704
|
-
|
|
705
|
-
/**
|
|
706
|
-
* @memberOf global
|
|
707
|
-
* @param name
|
|
708
|
-
* @param callback
|
|
709
|
-
* @return {*}
|
|
710
|
-
*/
|
|
711
|
-
block: function block(name, callback) {
|
|
712
|
-
var blocks = this.getBlocks();
|
|
713
|
-
blocks[name] = blocks[name] || [];
|
|
714
|
-
blocks[name].push(this.macro(callback));
|
|
715
|
-
if (this.getExtend()) return;
|
|
716
|
-
|
|
717
|
-
var current = function current() {
|
|
718
|
-
return blocks[name].shift();
|
|
719
|
-
};
|
|
720
|
-
|
|
721
|
-
var next = function next() {
|
|
722
|
-
var parent = current();
|
|
723
|
-
|
|
724
|
-
if (parent) {
|
|
725
|
-
var context = parent.__context;
|
|
726
|
-
return function () {
|
|
727
|
-
context.echo(parent(next()));
|
|
728
|
-
};
|
|
729
|
-
} else {
|
|
730
|
-
return function () {};
|
|
731
|
-
}
|
|
732
|
-
};
|
|
733
|
-
|
|
734
|
-
this.echo(current()(next()));
|
|
735
|
-
},
|
|
736
|
-
|
|
737
|
-
/**
|
|
738
|
-
* @memberOf global
|
|
739
|
-
* @param {string} path
|
|
740
|
-
* @param {object} [data]
|
|
741
|
-
* @param {boolean} [cx]
|
|
742
|
-
*/
|
|
743
|
-
include: function include(path, data, cx) {
|
|
744
|
-
var context = cx === false ? {} : this.clone(true);
|
|
745
|
-
var params = extend(context, data || {});
|
|
746
|
-
var promise = this.render(path, params);
|
|
747
|
-
this.echo(promise);
|
|
748
|
-
},
|
|
749
|
-
|
|
750
|
-
/**
|
|
751
|
-
* @memberOf global
|
|
752
|
-
* @param {string} path
|
|
753
|
-
*/
|
|
754
|
-
use: function use(path) {
|
|
755
|
-
var scope = this;
|
|
756
|
-
|
|
757
|
-
var promise = this.require(path);
|
|
758
|
-
|
|
759
|
-
this.echo(promise);
|
|
760
|
-
return {
|
|
761
|
-
as: function as(namespace) {
|
|
762
|
-
promise.then(function (exports) {
|
|
763
|
-
scope.set(namespace, exports);
|
|
764
|
-
});
|
|
765
|
-
return this;
|
|
766
|
-
}
|
|
767
|
-
};
|
|
768
|
-
},
|
|
769
|
-
|
|
770
|
-
/**
|
|
771
|
-
* @memberOf global
|
|
772
|
-
* @param {string} path
|
|
773
|
-
*/
|
|
774
|
-
from: function from(path) {
|
|
775
|
-
var scope = this;
|
|
776
|
-
|
|
777
|
-
var promise = this.require(path);
|
|
778
|
-
|
|
779
|
-
this.echo(promise);
|
|
780
|
-
return {
|
|
781
|
-
use: function use() {
|
|
782
|
-
var params = [].slice.call(arguments);
|
|
783
|
-
promise.then(function (exports) {
|
|
784
|
-
params.forEach(function (name) {
|
|
785
|
-
scope.set(name, exports[name]);
|
|
786
|
-
});
|
|
787
|
-
});
|
|
788
|
-
return this;
|
|
789
|
-
}
|
|
790
|
-
};
|
|
791
589
|
}
|
|
792
590
|
});
|
|
793
591
|
return Scope;
|
|
@@ -801,7 +599,6 @@
|
|
|
801
599
|
if (isNode() === false) {
|
|
802
600
|
this.load(window[namespace]);
|
|
803
601
|
}
|
|
804
|
-
|
|
805
602
|
return this;
|
|
806
603
|
},
|
|
807
604
|
exist: function exist(key) {
|
|
@@ -834,17 +631,13 @@
|
|
|
834
631
|
*/
|
|
835
632
|
var config = {};
|
|
836
633
|
var _helpers = {};
|
|
837
|
-
|
|
838
634
|
var ext = function ext(path, defaults) {
|
|
839
635
|
var ext = path.split('.').pop();
|
|
840
|
-
|
|
841
636
|
if (ext !== defaults) {
|
|
842
637
|
path = [path, defaults].join('.');
|
|
843
638
|
}
|
|
844
|
-
|
|
845
639
|
return path;
|
|
846
640
|
};
|
|
847
|
-
|
|
848
641
|
var view = {
|
|
849
642
|
element: element,
|
|
850
643
|
output: function output(path, scope) {
|
|
@@ -853,26 +646,23 @@
|
|
|
853
646
|
});
|
|
854
647
|
},
|
|
855
648
|
render: function render(name, data) {
|
|
856
|
-
var filepath = ext(name, config.extension
|
|
649
|
+
var filepath = ext(name, config.extension);
|
|
857
650
|
var scope = new view.scope(data);
|
|
858
651
|
return view.output(filepath, scope).then(function (content) {
|
|
859
652
|
if (scope.getExtend()) {
|
|
860
653
|
scope.setExtend(false);
|
|
861
654
|
var layout = scope.getLayout();
|
|
862
|
-
|
|
863
655
|
var _data = scope.clone();
|
|
864
|
-
|
|
865
656
|
return view.render(layout, _data);
|
|
866
657
|
}
|
|
867
|
-
|
|
868
658
|
return content;
|
|
869
659
|
});
|
|
870
660
|
},
|
|
871
661
|
require: function require(name) {
|
|
872
|
-
var filepath = ext(name, config.extension
|
|
662
|
+
var filepath = ext(name, config.extension);
|
|
873
663
|
var scope = new view.scope({});
|
|
874
664
|
return view.output(filepath, scope).then(function () {
|
|
875
|
-
return scope.
|
|
665
|
+
return scope.getMacro();
|
|
876
666
|
});
|
|
877
667
|
},
|
|
878
668
|
helpers: function helpers(methods) {
|
|
@@ -880,14 +670,14 @@
|
|
|
880
670
|
extend(_helpers, methods);
|
|
881
671
|
view.scope.helpers(methods);
|
|
882
672
|
},
|
|
883
|
-
configure: function configure(options) {
|
|
673
|
+
configure: function configure$1(options) {
|
|
884
674
|
config["export"] = typeProp(isString, defaults["export"], options["export"]);
|
|
885
675
|
config.path = typeProp(isString, defaults.path, options.path);
|
|
886
676
|
config.resolver = typeProp(isFunction, defaults.resolver, options.resolver);
|
|
887
|
-
config.extension =
|
|
677
|
+
config.extension = typeProp(isString, defaults.extension, options.extension);
|
|
888
678
|
config.token = extend({}, defaults.token, options.token);
|
|
889
679
|
config.vars = extend({}, defaults.vars, options.vars);
|
|
890
|
-
view.scope =
|
|
680
|
+
view.scope = configure(config, _helpers);
|
|
891
681
|
view.compile = Compiler(config);
|
|
892
682
|
view.wrapper = Wrapper(config);
|
|
893
683
|
view.cache = Cache(config);
|
|
@@ -899,7 +689,6 @@
|
|
|
899
689
|
callback = options;
|
|
900
690
|
options = {};
|
|
901
691
|
}
|
|
902
|
-
|
|
903
692
|
options = options || {};
|
|
904
693
|
var settings = extend({}, options.settings);
|
|
905
694
|
var viewPath = typeProp(isString, settings['views'], defaults.path);
|
|
@@ -919,12 +708,10 @@
|
|
|
919
708
|
/**
|
|
920
709
|
*
|
|
921
710
|
*/
|
|
922
|
-
|
|
923
711
|
view.configure(options || {});
|
|
924
712
|
/**
|
|
925
713
|
*
|
|
926
714
|
*/
|
|
927
|
-
|
|
928
715
|
view.helpers({
|
|
929
716
|
require: function require(name) {
|
|
930
717
|
return view.require(name, this);
|
|
@@ -935,7 +722,6 @@
|
|
|
935
722
|
});
|
|
936
723
|
return view;
|
|
937
724
|
}
|
|
938
|
-
|
|
939
725
|
var index = init();
|
|
940
726
|
|
|
941
727
|
return index;
|