@@ -21,7 +21,7 @@ function Interpolator(parser) {
21
21
this . interpolateString = function ( context , value ) {
22
22
return parser . assemble ( context , parser . parse ( value ) )
23
23
} ,
24
-
24
+
25
25
26
26
this . interpolate = function ( context , value , interpolationPolicy ) {
27
27
var index = 0
@@ -33,14 +33,12 @@ function Interpolator(parser) {
33
33
return value ;
34
34
}
35
35
var interpolationRules = self . rules [ Object . prototype . toString . call ( value ) ]
36
- if ( ! interpolationRules )
36
+ if ( ! interpolationRules )
37
37
return value
38
38
39
39
while ( index < interpolationRules . length && ! ( matched = interpolationRules [ index ] . match ( value ) ) ) index ++
40
-
41
- if ( ! matched )
40
+ if ( ! matched )
42
41
return value
43
-
44
42
return interpolationRules [ index ] . action ( self , context , value )
45
43
}
46
44
}
@@ -50,36 +48,45 @@ Interpolator.prototype.rules = {
50
48
{
51
49
name : "context reference" ,
52
50
match : function ( value ) { ( "@" === value ) } ,
53
- action : function ( interpolator , context , value ) { return context }
51
+ action : function ( interpolator , context , value ) { return context }
54
52
} ,
55
53
{
56
54
name : "eval shorthand" ,
57
55
match : function ( value ) { return value [ 0 ] == '#' } ,
58
- action : function ( interpolator , context , value ) {
56
+ action : function ( interpolator , context , value ) {
59
57
with ( context ) {
60
58
return eval ( value . slice ( 1 ) )
61
- }
59
+ }
62
60
}
63
61
} ,
64
62
{
65
63
name : "context member reference" ,
66
64
match : function ( value ) { return value [ 0 ] == '@' } ,
67
- action : function ( interpolator , context , value ) {
68
- return interpolator . readContextPath ( context , value . slice ( 1 ) )
65
+ action : function ( interpolator , context , value ) {
66
+ return interpolator . readContextPath ( context , value . slice ( 1 ) )
67
+ }
68
+ } ,
69
+ {
70
+ name : "conditional statement" ,
71
+ match : function ( value ) { return / ( .+ ) ( > | = = | = = = | ! = | ! = = | < | > = | < = ) ( .+ ) / . test ( value ) } ,
72
+ action : function ( interpolator , context , value ) {
73
+ with ( context ) {
74
+ return eval ( value )
75
+ }
69
76
}
70
77
} ,
71
78
{
72
79
name : "markup resolver" ,
73
80
match : function ( value ) { return value . indexOf ( "[" ) > - 1 } ,
74
- action : function ( interpolator , context , value ) {
75
- return interpolator . interpolateString ( context , value )
81
+ action : function ( interpolator , context , value ) {
82
+ return interpolator . interpolateString ( context , value )
76
83
}
77
84
} ] ,
78
85
"[object Array]" : [
79
86
{
80
87
name : "object field interpolator" ,
81
88
match : function ( value ) { return true } ,
82
- action : function ( interpolator , context , value ) {
89
+ action : function ( interpolator , context , value ) {
83
90
var result = [ ]
84
91
for ( var index = 0 ; index < value . length ; index ++ ) {
85
92
result . push ( interpolator . interpolate ( context , value [ index ] ) )
@@ -96,7 +103,7 @@ Interpolator.prototype.rules = {
96
103
{
97
104
name : "legacy {template:'...'} field resolver" ,
98
105
match : function ( value ) { return "template" in value } ,
99
- action : function ( interpolator , context , value ) {
106
+ action : function ( interpolator , context , value ) {
100
107
console . warn ( "obsoleted functionality: { template: value }, use [hbs]..[/hbs] instead" )
101
108
var template = value . template
102
109
var compiled = handlebars . compile ( template )
@@ -106,7 +113,7 @@ Interpolator.prototype.rules = {
106
113
{
107
114
name : "object field interpolator" ,
108
115
match : function ( value ) { return true } ,
109
- action : function ( interpolator , context , value ) {
116
+ action : function ( interpolator , context , value ) {
110
117
var result = { }
111
118
var keys = Object . keys ( value )
112
119
for ( var index = 0 ; index < keys . length ; index ++ ) {
0 commit comments