eval expressions in normal html attributes
[org.ibex.xt-crawshaw.git] / src / java / org / ibex / xt / Template.java
index c30ece6..01b8d7e 100644 (file)
@@ -40,10 +40,7 @@ public class Template extends JSLeaf.Element {
             //#end
 
         } else if (uri.startsWith("http://xt.ibex.org/")) {
-            //#switch(uri.substring(19))
-            case "io": System.out.println("ibex.xt.io not yet implemented"); // TODO
-            //#end
-            //throw new JSLeaf.Exn("Unknown XT library: "+uri);
+            throw new JSLeaf.Exn("Unknown XT library: "+uri);
 
         } else if (uri.startsWith("local:")) {
             // merge a new template into this tree
@@ -62,15 +59,16 @@ public class Template extends JSLeaf.Element {
                 e.getChildren().clear();
             }
 
-            Tree.Element merged = new JSLeaf.Merge(t, e);
+            // merge the attributes of the template and its representative
+            t.setAttributes(new JSLeaf.MergeAttr(e.getAttributes(), t.getAttributes()));
 
             // remap the parent of the original element
             if (e.getParent() != null) {
                 List ch = e.getParent().getChildren();
-                ch.set(ch.indexOf(e), merged);
+                ch.set(ch.indexOf(e), t);
             }
 
-            return wrap(merged, s);
+            return wrap(t, s);
         }
 
         e = new Template.AttributeEval(e);
@@ -107,11 +105,14 @@ public class Template extends JSLeaf.Element {
     /** Processes ${...} blocks in attributes, loads applicable
      *  attributes into the JS scope and processes global attributes. */
     public static class AttributeEval extends JSLeaf.Element implements Tree.Attributes {
+        // TODO: hide global attributes from out() function. waiting on util.XMLHelper
         protected Tree.Attributes a;
 
-        public AttributeEval(Tree.Element wrapped) { super(wrapped); a = wrapped.getAttributes(); }
-
-        public Tree.Attributes getAttributes() { return this; }
+        public AttributeEval(Tree.Element wrapped) {
+            super(wrapped);
+            a = wrapped.getAttributes();
+            wrapped.setAttributes(this);
+        }
 
         public int getIndex(String q) { return a.getIndex(q); }
         public int getIndex(String u, String k) { return a.getIndex(u, k); }
@@ -134,7 +135,7 @@ public class Template extends JSLeaf.Element {
                     case "declare":
                         Object d = eval(a.getVal(i));
                         if (!(d instanceof String)) throw new JSLeaf.Exn(
-                            "attribute "+getPrefix()+":declare can only contain a "+
+                            "attribute '"+getPrefix()+":declare' can only contain a "+
                             "space seperated list of variable names to declare.");
                         StringTokenizer st = new StringTokenizer((String)d, " ");
                         while (st.hasMoreTokens()) scope().declare(st.nextToken());