From 27b05c6e436c68a3ec9efd843b8c8bc93f3575ef Mon Sep 17 00:00:00 2001 From: "julien@igel.co.jp" Date: Wed, 11 Apr 2012 12:49:13 +0900 Subject: [PATCH] Dynamic tree display; next up: property monitoring --- bender.js | 29 ++++++++++++--------- index.html | 8 ++++++ lib/tree.html | 46 +++++++++++++++++++++++++++++++++ lib/tree.xml | 67 +++++++++++++++++++++++++++++++++++++++++++++++++ tests/hello.xml | 4 +-- 5 files changed, 140 insertions(+), 14 deletions(-) create mode 100644 lib/tree.html create mode 100644 lib/tree.xml diff --git a/bender.js b/bender.js index f628be2..877fa6f 100644 --- a/bender.js +++ b/bender.js @@ -50,6 +50,7 @@ context._refreshed_instance = function(instance) { flexo.remove_from_array(render_queue, instance); + flexo.notify(this, "@refresh", { instance: instance }); }; context._refresh_instance = function(instance) { @@ -255,8 +256,7 @@ // Render content: record the top-level target for this content, // the node itself to fetch its attributes, the target // instance (since we may switch instances to record ids inside - // this node) and the parent content (TODO we don't use this at - // the moment, but we should?) + // this node) and the parent content content = { target: dest, node: ch, instance: this, parent: content }; if (this.use.childNodes.length > 0) { @@ -295,16 +295,21 @@ d.setAttribute(attr.localName, attr.value); } }, this); - if (content && dest === content.target) { - [].forEach.call(content.node.attributes, function(attr) { - if (attr.name === "id") return; - if (attr.name === "content-id") { - content.instance.views[attr.value.trim()] = d; - } else { - d.setAttribute(attr.name, attr.value); - } - }); - } + var content_id = function(content) { + if (content && dest === content.target) { + flexo.log("content: node=", content.node, "parent=", content.parent); + content_id(content.parent); + [].forEach.call(content.node.attributes, function(attr) { + if (attr.name === "id") return; + if (attr.name === "content-id") { + content.instance.views[attr.value.trim()] = d; + } else { + d.setAttribute(attr.name, attr.value); + } + }); + } + }; + content_id(content); dest.insertBefore(d, ref); if (dest === this.target) { [].forEach.call(this.use.attributes, function(attr) { diff --git a/index.html b/index.html index 646df7b..cc818f2 100644 --- a/index.html +++ b/index.html @@ -345,6 +345,8 @@

The component, app and context elements

href="https://github.com/bendr/bender/blob/master/lib/timer.xml">timer, or larger components relying on other components like toolbars, dialogs, all the way to complete applications.

+

Document @refresh event from context when + component instances are refreshed.

@@ -762,6 +764,12 @@

Library

controls to modify the top-level parameters of the application. Use the href attribute as well (see applications above for examples.) +
  • Runtime with dynamic tree view: show + the tree of the application running (and edit the + tree.) Use the href attribute as + well (see applications above for examples; a simple + example.)
  • Button
  • + + + ⚐ Bender tree view + + + + + + + + + + diff --git a/lib/tree.xml b/lib/tree.xml new file mode 100644 index 0000000..2c8e066 --- /dev/null +++ b/lib/tree.xml @@ -0,0 +1,67 @@ + + Bender tree visualizer + + + + + .bender_tree { border-bottom: dashed thin black; padding-bottom: 8px; + background-color: white; margin-top: 0; padding-top: 8px; } + ul.bender_tree, ul.bender_tree ul { list-style-type: none; } + .bender_tree span.tag { font-weight: bold; } + .bender_tree span.attr { font-style: italic; } + .bender_tree span.attr-value { font-family: monospace; } + .bender_tree li.text { font-family: monospace; white-space: pre } + + + + + + + + diff --git a/tests/hello.xml b/tests/hello.xml index df011aa..bbfcee5 100644 --- a/tests/hello.xml +++ b/tests/hello.xml @@ -1,7 +1,7 @@ - +

    Hello, world!

    -
    +