Permalink
Browse files

V037

  • Loading branch information...
mrohad committed Aug 29, 2010
1 parent 9503232 commit 910addd7681d460f44bf21853da4b22db35e4c00
View
Binary file not shown.
View
@@ -1,3 +1,12 @@
+Change LOG 0.37
+================================
+Features:
+1) Now compile into object whereas the main code is nested to the page() function
+2) ability to write code outside the page() function using the <?!code?> tag
+3) add examples to README
+4) commands has been change to context
+
+
Change LOG 0.35
================================
Features:
View
@@ -1,6 +1,6 @@
Alligator is a simple application server built on top of AntiNode and Node.js
-Latest Version 0.35
+Latest Version 0.37
# Usage
@@ -28,11 +28,11 @@ Example settings file:
},
"server_script": {
"template_ext" : "jssp",
- "script_ext" : "sjs",
+ "script_ext" : "ssjs",
"begin" : "<?",
"begin_additional_write": "=",
"end" : "?>",
- "session_minutes" : 1,
+ "session_minutes" : 30,
"memcached" : {
"enable" : 0,
"server" : "localhost",
@@ -73,27 +73,27 @@ Explanation of properties:
When one is writing a script nested to the <? some;JavaScript;Code;In Here;?> tags
-He/She can use the following implicit functions/variables:
+He/She can use the following implicit functions/variables over the context object:
-- `request` for handling the request
-- `request.parameters` to read and write request post/get parameters
-- `responseHead.header` to add headers of the response (e.g. responseHead.header["set-cookie"] = "..";)
-- `responseHead.status` to change the HTTP response status
-- `commands.write(str)` to add string to the response body (or instead one can use the <?=str?> tag)
-- `commands.forward(other.jssp)` to forward the request and response to another server-side resource
-- `commands.sendRedirect(url)` to send HTTP redirect response back to the client
-- `lib.filename.member` to access whatever lib one has loaded
-- `session.set(key,value,callbackFunc)` to put anything on the HttpSession
-- `session.get(key,callbackFunc)` to get anything from the HttpSession
-- `application.set(key,value,callbackFunc)` to put anything on the application context
-- `application.get(key,callbackFunc)` to get anything from the application context
+- `context.request` for handling the request
+- `context.request.parameters` to read and write request post/get parameters
+- `context.responseHead.header` to add headers of the response (e.g. responseHead.header["set-cookie"] = "..";)
+- `context.responseHead.status` to change the HTTP response status
+- `context.write(str)` to add string to the response body (or instead one can use the <?=str?> tag)
+- `context.forward(other.jssp)` to forward the request and response to another server-side resource
+- `context.sendRedirect(url)` to send HTTP redirect response back to the client
+- `context.lib.filename.member` to access whatever lib one has loaded
+- `context.session.set(key,value,callbackFunc)` to put anything on the HttpSession
+- `context.session.get(key,callbackFunc)` to get anything from the HttpSession
+- `context.application.set(key,value,callbackFunc)` to put anything on the application context
+- `context.application.get(key,callbackFunc)` to get anything from the application context
#Examples
Ex1.jssp:
<? var a = 1+1;?><br/>
- <? write(a);?>
+ <? context.write(a);?>
Translates to:
<br/>2
Once can achieve the same thing using Ex2.jssp
@@ -103,32 +103,32 @@ Once can achieve the same thing using Ex2.jssp
One can forward from one jssp to another:
Exf1.jssp:
<? var dbInfo= gettingInfoFromDatabase();
- request.parameters.db = dbInfo;
- commands.forward("showTable.jssp");?>
+ context.request.parameters.db = dbInfo;
+ context.forward("showTable.jssp");?>
showTable.jssp:
<?=genetrateHTMLTable(request.parameters.db)?>
One can easily redirect:
<? if(request.parameters.googleIt=="true")
- commands.sendRedirect("http://www.google.com");
- else{>
+ context.sendRedirect("http://www.google.com");
+ else{?>
<H1> Welcome...</H1>
<?}?>
How to use the session scope, the counter Example: (separation of logic and view)
logic.jssp:
<?
var counter = 1;
- session.get("counter",function(value){
- log.debug("SESSIONLOGIC.JSSP, value - " +value);
+ context.session.get("counter",function(value){
+ context.log.debug("SESSIONLOGIC.JSSP, value - " +value);
if(value == undefined){
- session.set("counter",1);
+ context.session.set("counter",1);
}else{
counter = value+1;
- session.set("counter",counter);
+ context.session.set("counter",counter);
}
- request.parameters.counter = counter;
- commands.forward("counter/view.jssp");
+ context.request.parameters.counter = counter;
+ context.forward("counter/view.jssp");
});
?>
view.jssp:
@@ -138,29 +138,37 @@ view.jssp:
<?
var counter = request.parameters.counter;
if(counter==1)
- commands.write("First Time");
+ context.write("First Time");
else
- commands.write("Number of hits by you:" + counter);
+ context.write("Number of hits by you:" + counter);
?>
</BODY>
</HTML>
In case you had like to write JS only you can use a file with the 'script_ext', here is a different way to write logic.jssp
-logic.sjs: (no script tags)
- var counter = 1;
- application.get("counter",function(value){
- log.debug("ApplicationLOGIC.JSSP, value - " +value);
- if(value == undefined){
- application.set("counter",1);
- }else{
- counter = value+1;
- application.set("counter",counter);
- }
- request.parameters.counter = counter;
- commands.forward("counter/view.jssp");
- });
+logic.ssjs: (no script tags)
+ this.page = function (context){
+ var counter = 1;
+ context.application.get("counter",function(value){
+ context.log.debug("ApplicationLOGIC.JSSP, value - " +value);
+ if(value == undefined){
+ context.application.set("counter",1);
+ }else{
+ counter = value+1;
+ context.application.set("counter",counter);
+ }
+ context.request.parameters.counter = counter;
+ context.forward("counter/view.jssp");
+ });
+
+ }
+
+**Please note that behind the scene Alligator translate JSSP file to SSJS file upon the first request to this JSSP file(lazy)
+**and later on use the SSJS file only.
+**One can develop SSJS files instead of JSSP which makes the translation unnecessary.
+**Alligator invokes the page() function.
In case Memcached is enabled, the application and session contexts are being saved there.
View
@@ -0,0 +1,6 @@
+function server(action,cb){
+ $.get("", { serverFunction: action},
+ function(data) {
+ cb(data);
+ });
+}
@@ -1,14 +1,14 @@
<?
var counter = 1;
- application.get("counter",function(value){
- log.debug("ApplicationLOGIC.JSSP, value - " +value);
+ context.application.get("counter",function(value){
+ context.log.debug("ApplicationLOGIC.JSSP, value - " +value);
if(value == undefined){
- application.set("counter",1);
+ context.application.set("counter",1);
}else{
counter = value+1;
- application.set("counter",counter);
+ context.application.set("counter",counter);
}
- request.parameters.counter = counter;
- commands.forward("counter/view.jssp");
- });
-?>
+ context.request.parameters.counter = counter;
+ context.forward("counter/view.jssp");
+ });
+?>
@@ -0,0 +1,19 @@
+this.page = function (context){context.writeEscapedText("");
+ var counter = 1;
+ context.application.get("counter",function(value){
+ context.log.debug("ApplicationLOGIC.JSSP, value - " +value);
+ if(value == undefined){
+ context.application.set("counter",1);
+ }else{
+ counter = value+1;
+ context.application.set("counter",counter);
+ }
+ context.request.parameters.counter = counter;
+ context.forward("counter/view.jssp");
+ });
+
+context.writeEscapedText("");
+};
+ this.test = function(context){
+ return "hello ajax world";
+ };
@@ -1,14 +1,14 @@
<?
var counter = 1;
- session.get("counter",function(value){
- log.debug("SESSIONLOGIC.JSSP, value - " +value);
+ context.session.get("counter",function(value){
+ context.log.debug("SESSIONLOGIC.JSSP, value - " +value);
if(value == undefined){
- session.set("counter",1);
+ context.session.set("counter",1);
}else{
counter = value+1;
- session.set("counter",counter);
+ context.session.set("counter",counter);
}
- request.parameters.counter = counter;
- commands.forward("counter/view.jssp");
+ context.request.parameters.counter = counter;
+ context.forward("counter/view.jssp");
});
?>
View
@@ -2,11 +2,11 @@
<HEAD><TITLE>Application Scope Counter Tester</TITLE></HEAD>
<BODY>
<?
- var counter = request.parameters.counter;
+ var counter = context.request.parameters.counter;
if(counter==1)
- commands.write("First Time");
+ context.write("First Time");
else
- commands.write("Number of users:" + counter);
+ context.write("Number of users:" + counter);
?>
</BODY>
View
@@ -0,0 +1,14 @@
+this.page = function (context){context.writeEscapedText("%3CHTML%3E%0A");
+context.writeEscapedText("%09%3CHEAD%3E%3CTITLE%3EApplication%20Scope%20Counter%20Tester%3C/TITLE%3E%3C/HEAD%3E%0A");
+context.writeEscapedText("%09%3CBODY%3E%0A");
+context.writeEscapedText("%09");
+ var counter = context.request.parameters.counter;
+ if(counter==1)
+ context.write("First Time");
+ else
+ context.write("Number of users:" + counter);
+
+
+context.writeEscapedText("%09%3C/BODY%3E%0A");
+context.writeEscapedText("%3C/HTML%3E%0A");
+};
View
@@ -0,0 +1,3 @@
+this.page = function (context){context.writeEscapedText("ERROR%3A%0A");
+context.writeEscapedText(""); write(;
+};
View
@@ -1,22 +1,2 @@
-<HTML>
- <?="<head><title>nodeJS and antiNode+</title></head>"?>
- <BODY>
-
- HELLO WORLD<br/>
-
- <br/>request.parameters.night: <?=request.parameters.night?></br>
- <? if(request.parameters.night != undefined && request.parameters.night=="1"){
- ?>
- Good night!
- <?}else{?>
- Good Day!
- <?}?>
- <br/>
- <?for (index=0;index<5;index++){ commands.write(index);?>;<? }?>
- <br/>
- Testing the lib: <br/>
- Request headers: <?=lib.test.arrayToString(request.headers)?></br>
- <br/>
-
- </BODY>
-</HTML>
+night: <?=context.request.parameters.night?context.request.parameters.night:"nothing"?><br/>
+day: <?=context.request.parameters.day?context.request.parameters.day:"nothing"?><br/>
View
@@ -0,0 +1,3 @@
+this.page = function (context){context.writeEscapedText("night%3A%20");context.write(context.request.parameters.night?context.request.parameters.night:"nothing");context.writeEscapedText("%3Cbr/%3E%0A");
+context.writeEscapedText("day%3A%20");context.write(context.request.parameters.day?context.request.parameters.day:"nothing");context.writeEscapedText("%3Cbr/%3E%0A");
+};
Oops, something went wrong.

0 comments on commit 910addd

Please sign in to comment.