@@ -81,6 +81,7 @@ var spaceRe = /\s+/;
81
81
var equalsRe = / \s * = / ;
82
82
var curlyRe = / \s * \} / ;
83
83
var tagRe = / # | \^ | \/ | > | \{ | & | = | ! / ;
84
+ var pipelineRe = / \| \> / ;
84
85
85
86
/**
86
87
* Breaks up the given `template` string into a tree of tokens. If the `tags`
@@ -398,11 +399,46 @@ Context.prototype.push = function push(view) {
398
399
return new Context ( view , this ) ;
399
400
} ;
400
401
402
+ Context . prototype . resolvePipelineOperator = function resolvePipelineOperator (
403
+ value ,
404
+ pipelines ,
405
+ ) {
406
+ var self = this ;
407
+ var pipelineResolver = function pipelineResolver ( val , func ) {
408
+ var findFunction = function (
409
+ instance ,
410
+ functionToFind ,
411
+ valueToPutInFoundFunction ,
412
+ depth ,
413
+ ) {
414
+ if ( depth <= 0 || ! instance ) return null ;
415
+ if ( instance . view . hasOwnProperty ( functionToFind ) )
416
+ return instance . view [ func ] ( valueToPutInFoundFunction ) ;
417
+
418
+ return findFunction ( instance . parent , functionToFind , val , depth ) ;
419
+ } ;
420
+
421
+ var foundFunction = findFunction ( self , func , val , 20 ) ;
422
+
423
+ return foundFunction ? foundFunction : val ;
424
+ } ;
425
+ return pipelines . reduce ( pipelineResolver , value ) ;
426
+ } ;
427
+
401
428
/**
402
429
* Returns the value of the given name in this context, traversing
403
430
* up the context hierarchy if the value is absent in this context's view.
404
431
*/
405
432
Context . prototype . lookup = function lookup ( name ) {
433
+ // {{variable |> pipelineOne |> pipelineTwo}}
434
+ // output: [variable,pipelineOne, pipelineTwo ]
435
+ var replacedName = name
436
+ . replace ( new RegExp ( spaceRe , "g" ) , "" )
437
+ . split ( pipelineRe ) ;
438
+
439
+ name = replacedName . shift ( ) ;
440
+ var pipelines = replacedName ;
441
+
406
442
var cache = this . cache ;
407
443
408
444
var value ;
@@ -484,6 +520,10 @@ Context.prototype.lookup = function lookup(name) {
484
520
485
521
if ( isFunction ( value ) ) value = value . call ( this . view ) ;
486
522
523
+ if ( pipelines ) {
524
+ value = this . resolvePipelineOperator ( value , pipelines ) ;
525
+ }
526
+
487
527
return value ;
488
528
} ;
489
529
0 commit comments