Revision: 4583 http://sourceforge.net/p/vexi/code/4583 Author: mkpg2 Date: 2013-11-20 15:47:48 +0000 (Wed, 20 Nov 2013) Log Message: ----------- Fix. Allow sibling subtemplates to use the same ids ...
Modified Paths: -------------- branches/vexi3/org.vexi-core.main/src/main/java/org/vexi/core/VML.java branches/vexi3/org.vexi-core.main/src/main/java/org/vexi/core/VMLBuilder.java branches/vexi3/org.vexi-core.main/src/test/java/test/core/template/TestTemplate.java branches/vexi3/org.vexi-core.main/src/test/java/test/core/template/lang_subtemplate_ids.t Modified: branches/vexi3/org.vexi-core.main/src/main/java/org/vexi/core/VML.java =================================================================== --- branches/vexi3/org.vexi-core.main/src/main/java/org/vexi/core/VML.java 2013-11-20 14:12:46 UTC (rev 4582) +++ branches/vexi3/org.vexi-core.main/src/main/java/org/vexi/core/VML.java 2013-11-20 15:47:48 UTC (rev 4583) @@ -12,6 +12,7 @@ import org.ibex.js.JSExn; import org.ibex.js.JSU; import org.ibex.js.parse.Function; +import org.ibex.util.Basket; import org.ibex.util.Tree; import org.vexi.core.VML.Static.Template; import org.vexi.core.VML.Static.Template.PerInstantiationScope; @@ -50,7 +51,7 @@ public Static(JS vexi, JS constructor, String sourceName) { // UGLY in fact it doesn't matter what the elementStart, it is only // used for skipping lines, but we are never inside another code block. - super(null, -1); + super(null, -1, true); this.vexi = vexi; this.constructor = constructor; this.sourceName = sourceName; @@ -141,7 +142,7 @@ // Static data/methods /////////////////////////////////////////////////////////////////// // FOOTNOTE:1 Template(CodeBlock parent, int elementStart, Template preapply) { - super(parent, elementStart); + super(parent, elementStart, parent==null); this.preapply = preapply; } @@ -440,14 +441,15 @@ Template template; public SubTemplate(CodeBlock parent, int elementStart, boolean apply) { - super(parent, elementStart); + super(parent, elementStart, true); this.apply = apply; } } static abstract class CodeBlock { - final CodeBlock parent; /// Only used for sharing namepspace prefix information. - /// (i.e. templates are otherwise independent of each other). + final CodeBlock parent; /// Only used for sharing id scopeing + final Basket.Array idlist; + // Only used during parsing ///////////////////////////////////////////////////////////////// StringBuffer content = null; ///< during XML parsing, this holds partially-read character data; null otherwise @@ -457,11 +459,30 @@ Prefixes uriPrefixes; /// Uri prefixes->Blessings - CodeBlock(CodeBlock parent, int elementStart) { + CodeBlock(CodeBlock parent, int elementStart, boolean idContext) { this.parent = parent; this.elementStart = elementStart; + if(idContext){ + idlist = new Basket.Array(); + }else{ + idlist = null; + } } + public boolean hasId(String id){ + // COULD be more efficient - instead of linking to the parent, directly link + // to the idcontext (i.e. the parent topmost template, in file or subtemplate) + if(idlist!=null && idlist.containsValue(id)) return true; + if(parent!=null) return parent.hasId(id); + return false; + } + + public void addId(String id){ + if(idlist==null) parent.addId(id); + else idlist.add(id); + } + + /** * Contains list of xml namespace prefixes. The <vexi/> and * each template node has its xml namespace converted into JS objects Modified: branches/vexi3/org.vexi-core.main/src/main/java/org/vexi/core/VMLBuilder.java =================================================================== --- branches/vexi3/org.vexi-core.main/src/main/java/org/vexi/core/VMLBuilder.java 2013-11-20 14:12:46 UTC (rev 4582) +++ branches/vexi3/org.vexi-core.main/src/main/java/org/vexi/core/VMLBuilder.java 2013-11-20 15:47:48 UTC (rev 4583) @@ -196,7 +196,6 @@ private int state = STATE_INITIAL; int meta_start = -1; // Used in calculating endLines to add to static_content - Basket.Array idlist = new Basket.Array(); Vec nodeStack = new Vec(); Template t = null; CodeBlock cb = null; @@ -332,7 +331,7 @@ case STATE_IN_ROOT_NODE: case STATE_IN_APPLY_NODE: case STATE_IN_SUB_TEMPLATE_NODE: - CodeBlock parent = state!=STATE_IN_ROOT_NODE?cb.parent:null; + CodeBlock parent = cb; Template preapply = t; cb = t = static_.new Template(parent, getLine(), preapply); state = STATE_IN_TEMPLATE_NODE; @@ -383,10 +382,11 @@ String v = a.getVal(i); if (k.equals("id")) { t.id = v.toString().intern(); - if (idlist.containsValue(t.id)) { + if (cb.hasId(t.id)) { + cb.hasId(t.id); throw new XML.Exn("duplicate node id '"+t.id+"'", XML.Exn.SCHEMA, getLine(), -1); } - idlist.add(t.id); + cb.addId(t.id); continue ATTR; } Modified: branches/vexi3/org.vexi-core.main/src/test/java/test/core/template/TestTemplate.java =================================================================== --- branches/vexi3/org.vexi-core.main/src/test/java/test/core/template/TestTemplate.java 2013-11-20 14:12:46 UTC (rev 4582) +++ branches/vexi3/org.vexi-core.main/src/test/java/test/core/template/TestTemplate.java 2013-11-20 15:47:48 UTC (rev 4583) @@ -16,8 +16,8 @@ public static void main(String[] args) throws Throwable { CoreTestSuite cts = new CoreTestSuite(TestTemplate.class); - TestCase t = cts.createTestCase(cts.getResourceDirs(), "lang_apply_prop.t"); -// TestCase t = cts.createTestCase(cts.getResourceDirs(), "lang_subtemplate_ids.t"); +// TestCase t = cts.createTestCase(cts.getResourceDirs(), "lang_apply_prop.t"); + TestCase t = cts.createTestCase(cts.getResourceDirs(), "lang_subtemplate_ids.t"); t.runBare(); } } Modified: branches/vexi3/org.vexi-core.main/src/test/java/test/core/template/lang_subtemplate_ids.t =================================================================== --- branches/vexi3/org.vexi-core.main/src/test/java/test/core/template/lang_subtemplate_ids.t 2013-11-20 14:12:46 UTC (rev 4582) +++ branches/vexi3/org.vexi-core.main/src/test/java/test/core/template/lang_subtemplate_ids.t 2013-11-20 15:47:48 UTC (rev 4583) @@ -25,14 +25,30 @@ </ui:Box> </lang:subtemplate> + + <lang:subtemplate property="sub2"> + <ui:Box> + <ui:Box id="item"/> + $item.text = arguments[0]; + + thisbox.path ++= function(){ + return $outer.text+" / "+$title.text +" / "+ $nonxml.text+" / "+$item.text; + }; + + </ui:Box> + </lang:subtemplate> + .util..assertEquals(0,thisbox.numchildren); thisbox.add(new sub("A")); thisbox.add(new sub("B")); + thisbox.add(new sub("C")); + .util..assertEquals("Outer / Ids Test / boo / Moo",$main.path); .util..assertEquals("Outer / Ids Test / boo / A",thisbox[0].path); .util..assertEquals("Outer / Ids Test / boo / B",thisbox[1].path); + .util..assertEquals("Outer / Ids Test / boo / C",thisbox[2].path); </ui:Box> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ------------------------------------------------------------------------------ Shape the Mobile Experience: Free Subscription Software experts and developers: Be at the forefront of tech innovation. Intel(R) Software Adrenaline delivers strategic insight and game-changing conversations that shape the rapidly evolving mobile landscape. Sign up now. http://pubads.g.doubleclick.net/gampad/clk?id=63431311&iu=/4140/ostg.clktrk _______________________________________________ Vexi-svn mailing list Vexi-svn@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/vexi-svn