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

Unified Diff: pkg/mdv/lib/src/template.dart

Issue 17552019: Reorganize mdv and observe packages (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: merged Created 7 years, 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/mdv/lib/src/node.dart ('k') | pkg/mdv/lib/src/text.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/mdv/lib/src/template.dart
diff --git a/pkg/mdv/lib/src/template.dart b/pkg/mdv/lib/src/template.dart
new file mode 100644
index 0000000000000000000000000000000000000000..9b379ea3cf28ef39b256cf97b06b831c1d98963d
--- /dev/null
+++ b/pkg/mdv/lib/src/template.dart
@@ -0,0 +1,76 @@
+// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+part of mdv;
+
+/** Extensions to [Element]s that behave as templates. */
+class _TemplateExtension extends _ElementExtension {
+ var _model;
+ _TemplateIterator _templateIterator;
+
+ _TemplateExtension(Element node) : super(node);
+
+ void bind(String name, model, String path) {
+ switch (name) {
+ case 'bind':
+ case 'repeat':
+ case 'if':
+ if (_templateIterator == null) {
+ _templateIterator = new _TemplateIterator(node);
+ }
+ _templateIterator.inputs.bind(name, model, path);
+ return;
+ default:
+ super.bind(name, model, path);
+ }
+ }
+
+ void unbind(String name) {
+ switch (name) {
+ case 'bind':
+ case 'repeat':
+ case 'if':
+ if (_templateIterator != null) {
+ _templateIterator.inputs.unbind(name);
+ }
+ return;
+ default:
+ super.unbind(name);
+ }
+ }
+
+ void unbindAll() {
+ unbind('bind');
+ unbind('repeat');
+ unbind('if');
+ super.unbindAll();
+ }
+
+ /**
+ * Creates an instance of the template.
+ */
+ DocumentFragment createInstance() {
+ var template = node.ref;
+ if (template == null) template = node;
+
+ var instance = _Bindings._createDeepCloneAndDecorateTemplates(
+ template.content, node.attributes['syntax']);
+
+ if (_instanceCreated != null) {
+ _instanceCreated.add(instance);
+ }
+ return instance;
+ }
+
+ /**
+ * The data model which is inherited through the tree.
+ */
+ get model => _model;
+
+ void set model(value) {
+ var syntax = TemplateElement.syntax[node.attributes['syntax']];
+ _model = value;
+ _Bindings._addBindings(node, model, syntax);
+ }
+}
« no previous file with comments | « pkg/mdv/lib/src/node.dart ('k') | pkg/mdv/lib/src/text.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698