Revision: 2350
http://vexi.svn.sourceforge.net/vexi/?rev=2350&view=rev
Author: mkpg2
Date: 2007-09-28 09:55:46 -0700 (Fri, 28 Sep 2007)
Log Message:
-----------
Feature. Pass and access arguments when applying templates.
pass: template(b, [...])
access: arguments[i]
Modified Paths:
--------------
trunk/core/org.vexi.core/src/org/vexi/core/Blessing.java
trunk/core/org.vexi.core/src/org/vexi/core/Template.java
trunk/core/org.vexi.core/src/org/vexi/net/HTTP.java
Added Paths:
-----------
trunk/core/org.vexi.core/src_junit/test/core/template/_apply_args.t
trunk/core/org.vexi.core/src_junit/test/core/template/apply_args.t
Modified: trunk/core/org.vexi.core/src/org/vexi/core/Blessing.java
===================================================================
--- trunk/core/org.vexi.core/src/org/vexi/core/Blessing.java 2007-09-28
16:27:48 UTC (rev 2349)
+++ trunk/core/org.vexi.core/src/org/vexi/core/Blessing.java 2007-09-28
16:55:46 UTC (rev 2350)
@@ -4,6 +4,7 @@
import java.io.InputStream;
import org.ibex.js.JS;
+import org.ibex.js.JSArray;
import org.ibex.js.JSExn;
import org.ibex.js.JSU;
import org.ibex.js.JS.Keys;
@@ -140,13 +141,14 @@
public JS call(JS method, JS[] args) throws JSExn {
if (method != null) return super.call(method, args);
- if (args.length != 1)
- throw new JSExn("Can only apply templates using a single-argument
function");
+ if ((args.length < 1 || !(args[0] instanceof Box))
+ || (args.length == 2 && !(args[1] instanceof JSArray))
+ || args.length > 2 )
+ throw new JSExn("to apply a template us 'template(box [,
array])'");
// Ensure template is created by creating the static part.
getStatic();
- if (t == null) throw new JSExn("No such template " + description());
- if(!(args[0] instanceof Box)) throw new JSExn("can only apply
templates to boxes");
- t.apply((Box)args[0]);
+ if (t == null) throw new JSExn("no such template " + description());
+ t.apply((Box)args[0],args.length==2?((JSArray)args[1]).toArray():null);
return args[0];
}
Modified: trunk/core/org.vexi.core/src/org/vexi/core/Template.java
===================================================================
--- trunk/core/org.vexi.core/src/org/vexi/core/Template.java 2007-09-28
16:27:48 UTC (rev 2349)
+++ trunk/core/org.vexi.core/src/org/vexi/core/Template.java 2007-09-28
16:55:46 UTC (rev 2350)
@@ -140,33 +140,35 @@
/** Applies the template to Box b
- * @param pboxes a vector of all box parents on which to put $-references
- * @param ptemplates a vector of the fileNames to recieve private
references on the pboxes
+ * @param b - box applied to
+ * @param js[] - arguments object (typically empty)
*/
- public void apply(Box b) throws JSExn {
- apply(b, null);
+ // @param pboxes a vector of all box parents on which to put $-references
+ // @param ptemplates a vector of the fileNames to recieve private
references on the pboxes
+ public void apply(Box b, JS[] js) throws JSExn {
+ apply(b, js, null);
}
- private static Template preapply(Box b, Template t) throws JSExn{
+ private static Template preapply(Box b, JS[] args, Template t) throws
JSExn{
if (t != null){
// make sure we have resolved (if were top level)
if(t.staticPart!=null && t.staticPart.staticObject==null){
t =
((Blessing)Vexi.resolveString(t.vexi,t.staticPart.sourceName,
false)).initTemplate(t);
}
- t.apply(b, null);
+ t.apply(b, args, null);
}
return t;
}
- private void apply(Box b, PerInstantiationScope parentPis) throws JSExn {
+ private void apply(Box b, JS[] args, PerInstantiationScope parentPis)
throws JSExn {
Thread.getCurrentInterpreter().enterNonJSCall( this);
try{
// REMARK - the preapplies may not have been resolved yet,
// the resolved template is not necessarily the same object.
// FOOTNOTE:2
- preapply = preapply(b, preapply);
- principal = preapply(b, principal);
+ preapply = preapply(b, args, preapply);
+ principal = preapply(b, args, principal);
// UNCOMMENT to DEBUG
//b.put(JSU.S("_template_"), JSU.S(fileName()+":"+startLine));
@@ -182,7 +184,7 @@
// FIXME needs to obey the new application-ordering rules
for (int i=0; children != null && i<children.size(); i++) {
Box kid = new Box();
- ((Template)children.elementAt(i)).apply(kid, pis);
+ ((Template)children.elementAt(i)).apply(kid, null, pis);
b.putAndTriggerTraps(b.get(SC_numchildren), kid);
}
@@ -220,7 +222,7 @@
//UGLY - avoiding adding an init param
if(script== null)script = JSU.F;
}
- if (script != JSU.F) JSU.cloneWithNewGlobalScope(script,
pis).call(null, EMPTY_JS_ARRAY);
+ if (script != JSU.F) JSU.cloneWithNewGlobalScope(script,
pis).call(null, args!=null?args:EMPTY_JS_ARRAY);
}finally{
Thread.getCurrentInterpreter().exitNonJSCall();
Modified: trunk/core/org.vexi.core/src/org/vexi/net/HTTP.java
===================================================================
--- trunk/core/org.vexi.core/src/org/vexi/net/HTTP.java 2007-09-28 16:27:48 UTC
(rev 2349)
+++ trunk/core/org.vexi.core/src/org/vexi/net/HTTP.java 2007-09-28 16:55:46 UTC
(rev 2350)
@@ -1515,7 +1515,7 @@
//
Template.buildTemplate("org/ibex/builtin/proxy_authorization.ibex",
//
Stream.getInputStream((JS)Main.builtin.get("org/ibex/builtin/proxy_authorization.ibex")),
// new Vexi(null));
- t.apply(b);
+ // t.apply(b,null);
b.put("realm", realm);
b.put("proxyIP", proxyIP);
return null;
Added: trunk/core/org.vexi.core/src_junit/test/core/template/_apply_args.t
===================================================================
--- trunk/core/org.vexi.core/src_junit/test/core/template/_apply_args.t
(rev 0)
+++ trunk/core/org.vexi.core/src_junit/test/core/template/_apply_args.t
2007-09-28 16:55:46 UTC (rev 2350)
@@ -0,0 +1,12 @@
+<vexi xmlns:ui="vexi://ui" xmlns="">
+
+
+ <ui:box>
+ assert(arguments!=null);
+ .util..assertEquals(2,arguments.length);
+ .util..assertEquals(4,arguments[0]);
+ .util..assertEquals("aces",arguments[1]);
+
+ </ui:box>
+
+</vexi>
Added: trunk/core/org.vexi.core/src_junit/test/core/template/apply_args.t
===================================================================
--- trunk/core/org.vexi.core/src_junit/test/core/template/apply_args.t
(rev 0)
+++ trunk/core/org.vexi.core/src_junit/test/core/template/apply_args.t
2007-09-28 16:55:46 UTC (rev 2350)
@@ -0,0 +1,10 @@
+<vexi xmlns:ui="vexi://ui" xmlns="">
+
+
+ <ui:box>
+ assert(arguments!=null);
+ vexi.log.info(arguments.length);
+ var _template = ._apply_args(vexi.box,[4,"aces"]);
+ </ui:box>
+
+</vexi>
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Vexi-svn mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/vexi-svn