X-Git-Url: http://git.megacz.com/?p=org.ibex.xt-crawshaw.git;a=blobdiff_plain;f=src%2Fjava%2Forg%2Fibex%2Fxt%2FTemplate.java;fp=src%2Fjava%2Forg%2Fibex%2Fxt%2FTemplate.java;h=01b8d7ecb46f759fac87f07d542609267a834555;hp=c30ece66ff9d74223df874474a476d48ef5aac74;hb=ec694154e4fe2c39c30bc6149ee1f99ce4e9cea8;hpb=f84b9c1b2991c4f349d8ae63585cb51efef6f2da diff --git a/src/java/org/ibex/xt/Template.java b/src/java/org/ibex/xt/Template.java index c30ece6..01b8d7e 100644 --- a/src/java/org/ibex/xt/Template.java +++ b/src/java/org/ibex/xt/Template.java @@ -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());