diff -uNr sajax-0.8/Changes.txt sajax-0.9/Changes.txt --- sajax-0.8/Changes.txt Wed Mar 9 16:58:31 2005 +++ sajax-0.9/Changes.txt Tue Mar 15 01:09:54 2005 @@ -1,6 +1,20 @@ SAJAX CHANGELOG --------------- +Sajax version 0.9 (March 15, 2005) + +* [php] Major changes to the PHP backend: +* [php] Renamed incl_sajax.php to Sajax.php to fit PEAR and other language + naming conventions +* [php] Functions and vars previously named rs_* are now sajax_* +* [php] Function stubs all call one generalized sajax_do_call() dispatcher +* [php] Added non-echoing version of sajax_echo_javascript() called + sajax_get_javascript via the magic of output buffering +* [php] Changed all examples to support new framework +* [perl] Applied fix for URL encoding of space (Thanks Max Maischein) +* [ruby] Added Ruby backend contributed by anonymous author +* [io] Added Io (http://www.iolanguage.com/) backend by Sajax team @ MM + Sajax version 0.8 (March 9, 2005) * [php] Bug in the long-open-tags changes. Thanks to Matthew M. Vince. diff -uNr sajax-0.8/io/Sajax.io sajax-0.9/io/Sajax.io --- sajax-0.8/io/Sajax.io Wed Dec 31 19:00:00 1969 +++ sajax-0.9/io/Sajax.io Fri Mar 11 20:01:29 2005 @@ -0,0 +1,203 @@ +// +// Sajax Io Backend +// (C) Copyright 2005 ModernMethod, Inc. +// Released under BSD license +// + +String interpolate := method( + work := self clone + last_idx := 0 + while (1, + idx := work find("", idx + 1) + if (end_idx == Nil, + // invalid interp expression.. we're done. + break) + + // in the case of an empty interpolated expression, + // lets move on + if (end_idx - idx == 1, + continue) + + // otherwise proceed with replacement. + slotName := work substring(idx+1, end_idx) + find_str := "" + // write("doString(" .. slotName .. ")") + replace_str := sender doString(slotName) + work := work replace(find_str, replace_str) + last_idx = end_idx + 1 + ) + return work +) + +Sajax := Object clone do ( + + debug_mode := 0 + export_list := List clone + js_has_been_shown := Nil + + init := method( + return self + ) + + handle_client_request := method( + + if (my_getenv("QUERY_STRING") == Nil, + return + ) + + form := CGI clone parse + if (form hasKey("rs") == Nil, + return + ) + + write("Content-type: text/html\n"); + write("Expires: Mon, 26 Jul 1997 05:00:00 GMT\n"); + write("Cache-Control: no-cache, must-revalidate\n"); + write("Pragma: no-cache\n\n"); + + func_name := form at("rs") + if (export_list contains(func_name) == Nil) then ( + write("-:$func_name not callable\n") + ) else ( + write("+:") + args := form at("rsargs[]") + result := sender performWithArgList(func_name, args) + write(result) + ) + exit; + } + + show_common_js := method( + + if (debug_mode == 1, + debugModeTrueFalse := "true", + debugModeTrueFalse := "false") + + html := """ + + // remote scripting library + // (c) copyright 2005 modernmethod, inc + var rs_debug_mode = ; + + function rs_debug(text) { + if (rs_debug_mode) + alert("RSD: " + text) + } + function rs_init_object() { + rs_debug("rs_init_object() called..") + + var A; + try { + A=new ActiveXObject("Msxml2.XMLHTTP"); + } catch (e) { + try { + A=new ActiveXObject("Microsoft.XMLHTTP"); + } catch (oc) { + A=null; + } + } + if(!A && typeof XMLHttpRequest != "undefined") + A = new XMLHttpRequest(); + if (!A) + rs_debug("Could not create connection object."); + return A; + } + + """ + write(html interpolate) + } + + esc := method(val, + return val replace("\"", "\\\\\""); + ) + + my_getenv := method(val, + my_get := Nil + if (?System) then ( + my_get := System getSlot("getenv") + ) else ( + my_get := Object getSlot("getenv") + ) + return my_get(val) + ) + + get_my_uri := method( + uri := "http://www.example.com/" + if (my_getenv("REQUEST_URI") != Nil) then ( + uri := my_getenv("REQUEST_URI") + ) else ( + if (my_getenv("SCRIPT_NAME") != Nil) then ( + uri := my_getenv("SCRIPT_NAME") + if (my_getenv("QUERY_STRING") != Nil) then ( + uri := uri .. "?" .. my_getenv("QUERY_STRING") + ) + ) + ) + return uri + ) + + show_one := method(func_name, + uri := get_my_uri + func_name_encoded := CGI encodeUrlParam(func_name) + if (uri contains("?") == Nil) then ( + uri = uri .. "?rs=" .. func_name_encoded + ) else ( + uri = uri .. "&rs=" .. func_name_encoded + ) + + html := """ + // wrapper for + + function x_() { + // count args; build URL + var i, x, n; + var url = ""; + var a = x_.arguments; + for (i = 0; i < a.length-1; i++) + url = url + "&rsargs[]=" + escape(a[i]); + url = url + "&rsrnd=" + new Date().getTime(); + x = rs_init_object(); + x.open("GET", url, true); + x.onreadystatechange = function() { + if (x.readyState != 4) + return; + rs_debug("received " + x.responseText); + + var status; + var data; + status = x.responseText.charAt(0); + data = x.responseText.substring(2); + if (status == "-") + alert("Error: " + callback_n); + else + a[a.length-1](data); + } + x.send(null); + rs_debug("x_ url = " + url); + rs_debug("x_ waiting.."); + delete x; + } + """ + write(html interpolate) + ) + + export := method(func, + export_list add(func) + } + + show_javascript := method( + if (js_has_been_shown == Nil, + show_common_js + ) + export_list foreach(index, func_name, + show_one(func_name) + ) + ) + +) + diff -uNr sajax-0.8/io/example_multiply.io sajax-0.9/io/example_multiply.io --- sajax-0.8/io/example_multiply.io Wed Dec 31 19:00:00 1969 +++ sajax-0.9/io/example_multiply.io Fri Mar 11 20:03:13 2005 @@ -0,0 +1,53 @@ +#!/usr/bin/env ioServer + +c := CGI clone + +multiply := method(x, y, + x := x asNumber + y := y asNumber + return x * y +) + +s := Sajax clone +s debug_mode := 1 +s init +s export("multiply") +s handle_client_request + +write("Content-type: text/html\n\n") + +html := """ + + + Multiplier + + + + + + * + + = + + + + +""" +write(html) diff -uNr sajax-0.8/perl/Sajax.pm sajax-0.9/perl/Sajax.pm --- sajax-0.8/perl/Sajax.pm Wed Mar 9 16:54:26 2005 +++ sajax-0.9/perl/Sajax.pm Tue Mar 15 01:06:37 2005 @@ -1,183 +1,184 @@ -package Sajax; -use Data::Dumper; - -my $rs_debug_mode = 0; -my $rs_js_has_been_shown = 0; -my %rs_export_list = (); -my %rs_coderef_list = (); - -sub incl_sajax { -} -sub rs_init { - $rs_debug_mode = 0; - $rs_js_has_been_shown = 0; - %rs_export_list = (); - %rs_coderef_list = (); - -} - -sub rs_handle_client_request { - my($q)=@_; - my $rv=""; - - if (!defined $q->param("rs")) { - return undef; - } - - my $func_name = $q->param("rs"); - - if ( defined $rs_export_list{$func_name}) { - $rv .= "+:"; - eval { - $rv .= &$func_name($q->param("rsargs")); - }; - if($@) { - print STDERR "Err:[$@]\n"; - } - } elsif ( defined $rs_coderef_list{$func_name}) { - $rv .= "+:"; - my $cr = $rs_coderef_list{$func_name}; - eval { - $rv .= &$cr($q->param("rsargs")); - }; - if($@) { - print STDERR "Err:[$@]\n"; - } - } else { - $rv .= "-:$func_name not callable"; - } - - return $rv; -} - -sub rs_show_common_js() { - my $rv = ""; - my $debug_mode = $rs_debug_mode ? "true" : "false"; - my $CC = "\n// Perl backend version (c) copyright 2005 Nathan Schmidt"; - $CC = ""; - $rv .= <url(-query=>1); - if ($uri =~ m/\?/) { - $uri .= "&rs=".rs_urlencode($func_name); - } else { - $uri .= "?rs=".rs_urlencode($func_name); - } - - my $urie = rs_esc($uri); - - $rv .= <param("rs")) { + return undef; + } + + my $func_name = $q->param("rs"); + + if ( defined $rs_export_list{$func_name}) { + $rv .= "+:"; + eval { + $rv .= &$func_name($q->param("rsargs")); + }; + if($@) { + print STDERR "Err:[$@]\n"; + } + } elsif ( defined $rs_coderef_list{$func_name}) { + $rv .= "+:"; + my $cr = $rs_coderef_list{$func_name}; + eval { + $rv .= &$cr($q->param("rsargs")); + }; + if($@) { + print STDERR "Err:[$@]\n"; + } + } else { + $rv .= "-:$func_name not callable"; + } + + return $rv; +} + +sub rs_show_common_js() { + my $rv = ""; + my $debug_mode = $rs_debug_mode ? "true" : "false"; + my $CC = "\n// Perl backend version (c) copyright 2005 Nathan Schmidt"; + $CC = ""; + $rv .= <url(-query=>1); + if ($uri =~ m/\?/) { + $uri .= "&rs=".rs_urlencode($func_name); + } else { + $uri .= "?rs=".rs_urlencode($func_name); + } + + my $urie = rs_esc($uri); + + $rv .= < + + // remote scripting library + // (c) copyright 2005 modernmethod, inc + var sajax_debug_mode = ; + + function sajax_debug(text) { + if (sajax_debug_mode) + alert("RSD: " + text) + } + function sajax_init_object() { + sajax_debug("sajax_init_object() called..") + + var A; + try { + A=new ActiveXObject("Msxml2.XMLHTTP"); + } catch (e) { + try { + A=new ActiveXObject("Microsoft.XMLHTTP"); + } catch (oc) { + A=null; + } + } + if(!A && typeof XMLHttpRequest != "undefined") + A = new XMLHttpRequest(); + if (!A) + sajax_debug("Could not create connection object."); + return A; + } + function sajax_do_call(func_name, url, args) { + var i, x, n; + for (i = 0; i < args.length-1; i++) + url = url + "&rsargs[]=" + escape(args[i]); + url = url + "&rsrnd=" + new Date().getTime(); + x = sajax_init_object(); + x.open("GET", url, true); + x.onreadystatechange = function() { + if (x.readyState != 4) + return; + sajax_debug("received " + x.responseText); + + var status; + var data; + status = x.responseText.charAt(0); + data = x.responseText.substring(2); + if (status == "-") + alert("Error: " + data); + else + args[args.length-1](data); + } + x.send(null); + sajax_debug(func_name + " url = " + url); + sajax_debug(func_name + " waiting.."); + delete x; + } + + + + // wrapper for + + function x_() { + // count args; build URL + + sajax_do_call("", + "", + x_.arguments); + } + + diff -uNr sajax-0.8/php/Sajax.php.txt sajax-0.9/php/Sajax.php.txt --- sajax-0.8/php/Sajax.php.txt Wed Dec 31 19:00:00 1969 +++ sajax-0.9/php/Sajax.php.txt Tue Mar 15 01:03:43 2005 @@ -0,0 +1,178 @@ + + + // remote scripting library + // (c) copyright 2005 modernmethod, inc + var sajax_debug_mode = ; + + function sajax_debug(text) { + if (sajax_debug_mode) + alert("RSD: " + text) + } + function sajax_init_object() { + sajax_debug("sajax_init_object() called..") + + var A; + try { + A=new ActiveXObject("Msxml2.XMLHTTP"); + } catch (e) { + try { + A=new ActiveXObject("Microsoft.XMLHTTP"); + } catch (oc) { + A=null; + } + } + if(!A && typeof XMLHttpRequest != "undefined") + A = new XMLHttpRequest(); + if (!A) + sajax_debug("Could not create connection object."); + return A; + } + function sajax_do_call(func_name, url, args) { + var i, x, n; + for (i = 0; i < args.length-1; i++) + url = url + "&rsargs[]=" + escape(args[i]); + url = url + "&rsrnd=" + new Date().getTime(); + x = sajax_init_object(); + x.open("GET", url, true); + x.onreadystatechange = function() { + if (x.readyState != 4) + return; + sajax_debug("received " + x.responseText); + + var status; + var data; + status = x.responseText.charAt(0); + data = x.responseText.substring(2); + if (status == "-") + alert("Error: " + data); + else + args[args.length-1](data); + } + x.send(null); + sajax_debug(func_name + " url = " + url); + sajax_debug(func_name + " waiting.."); + delete x; + } + + + + // wrapper for + + function x_() { + // count args; build URL + + sajax_do_call("", + "", + x_.arguments); + } + + diff -uNr sajax-0.8/php/example_multiply.php sajax-0.9/php/example_multiply.php --- sajax-0.8/php/example_multiply.php Wed Mar 9 16:54:26 2005 +++ sajax-0.9/php/example_multiply.php Tue Mar 15 00:58:03 2005 @@ -1,14 +1,14 @@ @@ -16,7 +16,7 @@ Multiplier