Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(118)

Side by Side Diff: pkg/mdv/lib/src/template_iterator.dart

Issue 19744006: Ensure model is passed with <template if> (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: add comment Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | pkg/mdv/test/template_element_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 part of mdv; 5 part of mdv;
6 6
7 // This code is a port of Model-Driven-Views: 7 // This code is a port of Model-Driven-Views:
8 // https://github.com/polymer-project/mdv 8 // https://github.com/polymer-project/mdv
9 // The code mostly comes from src/template_element.js 9 // The code mostly comes from src/template_element.js
10 10
(...skipping 25 matching lines...) Expand all
36 } else if (node is Text) { 36 } else if (node is Text) {
37 _parseAndBind(node, 'text', node.text, model, delegate); 37 _parseAndBind(node, 'text', node.text, model, delegate);
38 } 38 }
39 39
40 for (var c = node.firstChild; c != null; c = c.nextNode) { 40 for (var c = node.firstChild; c != null; c = c.nextNode) {
41 _addBindings(c, model, delegate); 41 _addBindings(c, model, delegate);
42 } 42 }
43 } 43 }
44 44
45 void _addAttributeBindings(Element element, model, delegate) { 45 void _addAttributeBindings(Element element, model, delegate) {
46 element.attributes.forEach((name, value) { 46 var attrs = new LinkedHashMap.from(element.attributes);
47 if (value == '' && (name == 'bind' || name == 'repeat')) { 47 if (element.isTemplate) {
48 value = '{{}}'; 48 // Accept 'naked' bind & repeat.
49 if (attrs['bind'] == '') attrs['bind'] = '{{}}';
50 if (attrs['repeat'] == '') attrs['repeat'] = '{{}}';
51
52 // Treat <template if="{{expr}}"> as <template bind if="{{expr}}">
53 if (attrs.containsKey('if') &&
54 !attrs.containsKey('bind') &&
55 !attrs.containsKey('repeat')) {
56 attrs['bind'] = '{{}}';
49 } 57 }
58 }
59
60 attrs.forEach((name, value) {
50 _parseAndBind(element, name, value, model, delegate); 61 _parseAndBind(element, name, value, model, delegate);
51 }); 62 });
52 } 63 }
53 64
54 void _parseAndBind(Node node, String name, String text, model, 65 void _parseAndBind(Node node, String name, String text, model,
55 BindingDelegate delegate) { 66 BindingDelegate delegate) {
56 67
57 var tokens = _parseMustacheTokens(text); 68 var tokens = _parseMustacheTokens(text);
58 if (tokens.length == 0 || (tokens.length == 1 && tokens[0].isText)) { 69 if (tokens.length == 0 || (tokens.length == 1 && tokens[0].isText)) {
59 return; 70 return;
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after
375 nodeExt._templateIterator = null; 386 nodeExt._templateIterator = null;
376 } 387 }
377 } 388 }
378 389
379 _nodeOrCustom(node).unbindAll(); 390 _nodeOrCustom(node).unbindAll();
380 for (var c = node.firstChild; c != null; c = c.nextNode) { 391 for (var c = node.firstChild; c != null; c = c.nextNode) {
381 _unbindAllRecursively(c); 392 _unbindAllRecursively(c);
382 } 393 }
383 } 394 }
384 } 395 }
OLDNEW
« no previous file with comments | « no previous file | pkg/mdv/test/template_element_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698