OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 library template_binding.src.mustache_tokens; | 5 library template_binding.src.mustache_tokens; |
6 | 6 |
7 import 'package:observe/observe.dart'; | 7 import 'package:observe/observe.dart'; |
8 import 'package:template_binding/template_binding.dart'; | 8 import 'package:template_binding/template_binding.dart'; |
9 | 9 |
10 /** | 10 /** |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 | 105 |
106 tokens.add(s.substring(lastIndex)); // TEXT | 106 tokens.add(s.substring(lastIndex)); // TEXT |
107 break; | 107 break; |
108 } | 108 } |
109 | 109 |
110 if (tokens == null) tokens = []; | 110 if (tokens == null) tokens = []; |
111 tokens.add(s.substring(lastIndex, startIndex)); // TEXT | 111 tokens.add(s.substring(lastIndex, startIndex)); // TEXT |
112 var pathString = s.substring(startIndex + 2, endIndex).trim(); | 112 var pathString = s.substring(startIndex + 2, endIndex).trim(); |
113 tokens.add(oneTime); // ONETIME? | 113 tokens.add(oneTime); // ONETIME? |
114 onlyOneTime = onlyOneTime && oneTime; | 114 onlyOneTime = onlyOneTime && oneTime; |
115 tokens.add(new PropertyPath(pathString)); // PATH | |
116 var delegateFn = delegate == null ? null : | 115 var delegateFn = delegate == null ? null : |
117 delegate.prepareBinding(pathString, name, node); | 116 delegate.prepareBinding(pathString, name, node); |
| 117 // Don't try to parse the expression if there's a prepareBinding function |
| 118 if (delegateFn == null) { |
| 119 tokens.add(new PropertyPath(pathString)); // PATH |
| 120 } else { |
| 121 tokens.add(null); // PATH |
| 122 } |
118 tokens.add(delegateFn); | 123 tokens.add(delegateFn); |
119 | 124 |
120 lastIndex = endIndex + 2; | 125 lastIndex = endIndex + 2; |
121 } | 126 } |
122 | 127 |
123 if (lastIndex == length) tokens.add(''); | 128 if (lastIndex == length) tokens.add(''); |
124 | 129 |
125 return new MustacheTokens._(tokens, onlyOneTime); | 130 return new MustacheTokens._(tokens, onlyOneTime); |
126 } | 131 } |
127 | 132 |
128 | 133 |
129 // Dart note: split "combinator" into the single/list variants, so the | 134 // Dart note: split "combinator" into the single/list variants, so the |
130 // argument can be typed. | 135 // argument can be typed. |
131 String _singleCombinator(Object value) { | 136 String _singleCombinator(Object value) { |
132 if (value == null) value = ''; | 137 if (value == null) value = ''; |
133 return '${getText(0)}$value${getText(length)}'; | 138 return '${getText(0)}$value${getText(length)}'; |
134 } | 139 } |
135 | 140 |
136 String _listCombinator(List<Object> values) { | 141 String _listCombinator(List<Object> values) { |
137 var newValue = new StringBuffer(getText(0)); | 142 var newValue = new StringBuffer(getText(0)); |
138 int len = this.length; | 143 int len = this.length; |
139 for (var i = 0; i < len; i++) { | 144 for (var i = 0; i < len; i++) { |
140 var value = values[i]; | 145 var value = values[i]; |
141 if (value != null) newValue.write(value); | 146 if (value != null) newValue.write(value); |
142 newValue.write(getText(i + 1)); | 147 newValue.write(getText(i + 1)); |
143 } | 148 } |
144 return newValue.toString(); | 149 return newValue.toString(); |
145 } | 150 } |
146 } | 151 } |
OLD | NEW |