Revision: 2463
          http://vexi.svn.sourceforge.net/vexi/?rev=2463&view=rev
Author:   mkpg2
Date:     2007-10-14 20:19:14 -0700 (Sun, 14 Oct 2007)

Log Message:
-----------
Feature. Create templates from strings (via blessing named,non-dir streams).
Cleaned up Fountain.

Modified Paths:
--------------
    trunk/core/org.vexi.core/src/org/vexi/core/Blessing.java
    trunk/core/org.vexi.core/src/org/vexi/core/Main.java
    trunk/core/org.vexi.core/src/org/vexi/core/Resources.java
    trunk/core/org.vexi.core/src/org/vexi/core/Vexi.jpp

Added Paths:
-----------
    trunk/core/org.vexi.core/src_junit/test/core/template/parse.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-10-15 
00:10:30 UTC (rev 2462)
+++ trunk/core/org.vexi.core/src/org/vexi/core/Blessing.java    2007-10-15 
03:19:14 UTC (rev 2463)
@@ -20,6 +20,7 @@
     private JS vexi;
     private Template t = null;
     public JS parentkey = null;
+    public JS name = null;
     public Blessing parent = null;
 
     //OPTIMIZE - use our own hash map
@@ -31,6 +32,11 @@
         this.parentkey = parentkey;
         this.parent = parent;
     }
+    Blessing(JS clonee, JS vexi, JS name) throws JSExn {
+        super(clonee);
+        this.vexi = vexi;
+        this.name = name;
+    }
 
     public JS getAndTriggerTraps(JS key) throws JSExn {
        Trap t = (Trap)super.get(key, 1);
@@ -116,10 +122,10 @@
                initializing = true;
         // FEATURE: Might want to handle the ".t" part better
         try{
-               if(parent==null) return;
-               JS res = parent.getTemplateRes(parentkey);
+               JS res = (parent==null)?
+                       this:parent.getTemplateRes(parentkey);
                unresolved.staticPart.sourceName = description();
-               t = TemplateBuilder.build(unresolved, res);
+               t = TemplateBuilder.build(unresolved, res);
         }finally{
                initializing = false;
         }
@@ -137,13 +143,11 @@
     }
     
     private String description() {
-       if(parent==null) return "";
+       if(parent==null) return JSU.toString(name);
         String s = JSU.toString(parentkey);
-        for(Blessing b = parent; b.parentkey != null; b = b.parent) s = 
JSU.toString(b.parentkey) + "." + s;
-        return s;/*
-        String s = "";//JSU.toString(parentkey);
-        for(Blessing b = this; b != null; b = b.parent) s = 
JSU.toString(b.parentkey) + "." + s;
-        return s;*/
+        for(Blessing b = parent; b!=null && b.parentkey != null; b = b.parent)
+               s = JSU.toString(b.parentkey) + "." + s;
+        return s;
     }
     
     public JS call(JS method, JS[] args) throws JSExn {

Modified: trunk/core/org.vexi.core/src/org/vexi/core/Main.java
===================================================================
--- trunk/core/org.vexi.core/src/org/vexi/core/Main.java        2007-10-15 
00:10:30 UTC (rev 2462)
+++ trunk/core/org.vexi.core/src/org/vexi/core/Main.java        2007-10-15 
03:19:14 UTC (rev 2463)
@@ -227,7 +227,6 @@
     private final String data;
     private String name;
     public BuiltinFountain(String data, String name) { this.data = data; 
this.name = name; }
-    public String getCacheKey() throws NotCacheableException { throw new 
NotCacheableException(); }
     public InputStream getInputStream() throws IOException { return 
Encode.JavaSourceCode.decode(data); }
     public String coerceToString(){ return 
name!=null?name:super.coerceToString(); }
 }

Modified: trunk/core/org.vexi.core/src/org/vexi/core/Resources.java
===================================================================
--- trunk/core/org.vexi.core/src/org/vexi/core/Resources.java   2007-10-15 
00:10:30 UTC (rev 2462)
+++ trunk/core/org.vexi.core/src/org/vexi/core/Resources.java   2007-10-15 
03:19:14 UTC (rev 2463)
@@ -168,8 +168,8 @@
     
     static Fountain _fountainForURL(final String url) throws JSExn{
         if (url.startsWith("http://";) || url.startsWith("https://";)) return 
new Fountain.HTTP(url);
-        else if (url.startsWith("data:")) return new 
Fountain.ByteArray(Encode.fromBase64(url.substring(5)), null);
-        else if (url.startsWith("utf8:")) return new 
Fountain.ByteArray(url.substring(5).getBytes(), null);
+        else if (url.startsWith("data:")) return new 
Fountain.ByteArray(Encode.fromBase64(url.substring(5)));
+        else if (url.startsWith("utf8:")) return new 
Fountain.ByteArray(url.substring(5).getBytes());
         else if (url.startsWith("file:")) {
             // FIXME
             //Platform.fileDialog(url.substring(5), false);

Modified: trunk/core/org.vexi.core/src/org/vexi/core/Vexi.jpp
===================================================================
--- trunk/core/org.vexi.core/src/org/vexi/core/Vexi.jpp 2007-10-15 00:10:30 UTC 
(rev 2462)
+++ trunk/core/org.vexi.core/src/org/vexi/core/Vexi.jpp 2007-10-15 03:19:14 UTC 
(rev 2463)
@@ -25,7 +25,7 @@
 /** Singleton class that provides all functionality in the vexi.* namespace */
 public final class Vexi extends JS.Obj implements JS.Cloneable, Constants, 
Callable {
 
-    public Vexi(Fountain rr) { try { super.addTrap(SC_,bless(this, rr));} 
catch(JSExn e) { throw new Error("should never happen: " + e); } }
+    public Vexi(Fountain rr) { try { super.addTrap(SC_,bless(this, rr, SC_));} 
catch(JSExn e) { throw new Error("should never happen: " + e); } }
 
        public Object run(Object o) throws JSExn {
                Log.uInfo(Main.class, "invoking initial template: "+ 
Main.initialTemplate);
@@ -111,6 +111,7 @@
            case "stream": return getSub(name);
            case "stream.cache": return METHOD;
            case "stream.combine": return METHOD;
+           case "stream.fromString": return METHOD;
            case "stream.homedir": return Resources.fountainForURL("file:" + 
System.getProperty("user.home"));
            case "stream.tempdir": return Resources.fountainForURL("file:" + 
System.getProperty("java.io.tempdir"));
            case "stream.unzip": return METHOD;
@@ -188,6 +189,7 @@
     public JS call(JS target, JS method, JS[] args) throws JSExn {
         try {
             //#switch(JSU.toString(method))
+               case "bless":        return bless_jsthread(target, 
args[0],(args.length<2)?null:args[1]);
             case "date": return new JSDate(args);
                        case "file.load": return new 
Fountain.File(Platform.fileDialog("", false));
                        case "file.save": return new 
Fountain.File(Platform.fileDialog("", true));
@@ -208,7 +210,6 @@
                     break;
                 case 1:
                     //#switch(JSU.toString(method))
-                       case "bless": return bless_jsthread(target, args[0]);
                        case "clone":
                            if(args[0] == null) throw new JSExn("can't clone 
the null value");
                            return new JS.Clone(args[0]);
@@ -226,6 +227,7 @@
                        case "net.rpc.xml": return new 
XMLRPC(JSU.toString(args[0]), "");
                        case "regexp": return new JSRegexp(args[0], null);
                        case "stream.cache": return Resources.cache(args[0]);
+                       case "stream.fromString": return new 
Fountain.ByteArray(JSU.toString(args[0]).getBytes());
                        case "stream.parse.html": throw new JSExn("not 
implemented yet"); //return null;
                            // FIXME backgrounding
                        case "stream.parse.utf8": return 
Resources.parseUTF8(args);
@@ -346,14 +348,14 @@
 
     // FEATURE: move this into builtin.vexi
     // From JS thread.
-    static private Blessing bless_jsthread(final JS vexi, final JS fountain) 
throws JSExn {
+    static private Blessing bless_jsthread(final JS vexi, final JS fountain, 
final JS name) throws JSExn {
        try {
             final Callable callback = Thread.pauseCurrent();
             new java.lang.Thread() { public void run() { 
                try{
                        Fountain f = JSU.getFountain(fountain);
                        f.cache(f);
-                       JSU.schedule(callback, bless(vexi,fountain));
+                       JSU.schedule(callback, bless(vexi,fountain,name));
                }catch(Exception e){
                        JSExn jsexn = (e instanceof JSExn)?(JSExn)e: new 
JSExn(e.getMessage());
                        JSU.schedule(callback,jsexn);
@@ -365,10 +367,10 @@
         }
     }
     
-    static private Blessing bless(JS vexi, JS fountain) throws JSExn {
+    static private Blessing bless(JS vexi, JS fountain, JS name) throws JSExn {
        Fountain f = JSU.getFountain(fountain);
        if(f==null) throw new JSExn("cannot bless a non-stream JS");
-       return new Blessing(fountain, vexi, null, null);
+       return new Blessing(fountain, vexi, name);
     }
           
     // JS:FIXME: This doesn't properly handle traps

Added: trunk/core/org.vexi.core/src_junit/test/core/template/parse.t
===================================================================
--- trunk/core/org.vexi.core/src_junit/test/core/template/parse.t               
                (rev 0)
+++ trunk/core/org.vexi.core/src_junit/test/core/template/parse.t       
2007-10-15 03:19:14 UTC (rev 2463)
@@ -0,0 +1,28 @@
+<vexi xmlns:ui="vexi://ui" xmlns="">
+
+
+    <ui:box>
+        
+        var tString = 
+          ["&lt;vexi xmlns:ui='vexi://ui'>", 
+           "static.a=1; ",
+           "static.ex++=function(){try{throw \"\";}catch(e){return e;}}",
+           " &lt;ui:box b='z'/>&lt;/vexi>"].join("\n");
+        
+        var tStream = vexi.stream.fromString(tString);
+        
+        
+        vexi.thread = function(){
+            var t = vexi.bless(tStream,"mytemplate");
+            .util..assertEquals(1,t..a);
+            var b = t(vexi.box);
+            .util..assertEquals("z",b.b);
+            var e = t..ex;
+            .util..assertEquals("mytemplate:3",e.backtrace[0]);
+        };
+        
+        
+        
+    </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: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
Vexi-svn mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/vexi-svn

Reply via email to