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 polymer_expressions; | 5 library polymer_expressions; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 import 'dart:html'; | 8 import 'dart:html'; |
9 | 9 |
10 import 'package:observe/observe.dart'; | 10 import 'package:observe/observe.dart'; |
11 | 11 |
12 import 'eval.dart'; | 12 import 'eval.dart'; |
13 import 'expression.dart'; | 13 import 'expression.dart'; |
14 import 'parser.dart'; | 14 import 'parser.dart'; |
15 import 'src/globals.dart'; | |
15 | 16 |
16 // TODO(justin): Investigate XSS protection | 17 // TODO(justin): Investigate XSS protection |
17 Object _classAttributeConverter(v) => | 18 Object _classAttributeConverter(v) => |
18 (v is Map) ? v.keys.where((k) => v[k] == true).join(' ') : | 19 (v is Map) ? v.keys.where((k) => v[k] == true).join(' ') : |
19 (v is Iterable) ? v.join(' ') : | 20 (v is Iterable) ? v.join(' ') : |
20 v; | 21 v; |
21 | 22 |
22 Object _styleAttributeConverter(v) => | 23 Object _styleAttributeConverter(v) => |
23 (v is Map) ? v.keys.map((k) => '$k: ${v[k]}').join(';') : | 24 (v is Map) ? v.keys.map((k) => '$k: ${v[k]}').join(';') : |
24 (v is Iterable) ? v.join(';') : | 25 (v is Iterable) ? v.join(';') : |
25 v; | 26 v; |
26 | 27 |
27 class PolymerExpressions extends BindingDelegate { | 28 class PolymerExpressions extends BindingDelegate { |
29 /** The default [globals] to use for Polymer expressions. */ | |
30 static const Map DEFAULT_GLOBALS = const { 'enumerate': enumerate }; | |
28 | 31 |
29 final Map<String, Object> globals; | 32 final Map<String, Object> globals; |
30 | 33 |
34 /** | |
35 * Creates a new binding delegate for Polymer expressions, with the provided | |
36 * variables used as [globals]. If no globals are supplied, a copy of the | |
37 * [DEFAULT_GLOBALS] will be used. | |
38 */ | |
31 PolymerExpressions({Map<String, Object> globals}) | 39 PolymerExpressions({Map<String, Object> globals}) |
32 : globals = (globals == null) ? new Map<String, Object>() : globals; | 40 : globals = (globals == null) ? |
41 new Map<String, Object>.from(DEFAULT_GLOBALS) : globals; | |
justinfagnani
2013/09/17 21:45:05
I think I'd rather see the default globals set in
Jennifer Messerly
2013/10/08 00:55:01
yeah, I was kinda wondering that too. So far we do
| |
33 | 42 |
34 _Binding getBinding(model, String path, name, node) { | 43 _Binding getBinding(model, String path, name, node) { |
35 if (path == null) return null; | 44 if (path == null) return null; |
36 var expr = new Parser(path).parse(); | 45 var expr = new Parser(path).parse(); |
37 if (model is! Scope) { | 46 if (model is! Scope) { |
38 model = new Scope(model: model, variables: globals); | 47 model = new Scope(model: model, variables: globals); |
39 } | 48 } |
40 if (node is Element && name == "class") { | 49 if (node is Element && name == "class") { |
41 return new _Binding(expr, model, _classAttributeConverter); | 50 return new _Binding(expr, model, _classAttributeConverter); |
42 } | 51 } |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
98 } | 107 } |
99 } | 108 } |
100 | 109 |
101 getValueWorkaround(key) { | 110 getValueWorkaround(key) { |
102 if (key == _VALUE) return value; | 111 if (key == _VALUE) return value; |
103 } | 112 } |
104 | 113 |
105 setValueWorkaround(key, v) { | 114 setValueWorkaround(key, v) { |
106 if (key == _VALUE) value = v; | 115 if (key == _VALUE) value = v; |
107 } | 116 } |
108 | |
109 } | 117 } |
OLD | NEW |