req = require("./wsrequest.js"),
localPort = 8888,
defaultLayout = "standard",
- defaultMain = null;
+ defaultMain = null,
+ addCss = null,
+ addJs = null;
localPort = port;
}
-exports.start = function() {
- // initialise req
- req.setDefaultLayout(defaultLayout);
- req.setDefaultMain(defaultMain);
-
+exports.addCss = function(cssname) {
+ if(addCss == null) {
+ addCss = new Array();
+ // turn it into an array;
+ addCss.push(cssname);
+ } else {
+ addCss.push(cssname);
+ }
- http.createServer(req.wsRequest).listen(localPort);
+}
- console.log("Server running on port: ", localPort);
+exports.addJS = function(js) {
+ if(addJs == null) {
+ addJs = new Array();
+ addJs.push(js);
+ } else {
+ addJs.push(js);
+ }
}
exports.setDefaultLayout = function(layout) {
defaultLayout = layout;
}
-exports.setDefaultMain = function(main) {
+exports.setDefaultMainPurl = function(main) {
defaultMain = main;
-}
\ No newline at end of file
+}
+
+
+exports.start = function() {
+ // initialise req
+ //req.setDefaultLayout(defaultLayout);
+ //req.setDefaultMain(defaultMain);
+ //req.setExtraCss(addCss);
+ //req.setExtraJs(assJs);
+
+
+ http.createServer(req.wsRequest).listen(localPort);
+
+ console.log("Server running on port: ", localPort);
+}
exports.standard = function () {
- var lay = "<html><head><?njs header ?></head><body><?nfs title ?>";
+ var lay = "<html><head><?njs header ?></head><body><?njs title ?>";
lay += "<table width=\"100%\"><tr><td><?njs menu ?></td></tr>";
- lay += "<tr valign=\"top\"><td></td><?njs sidebar ?><td><?njs body ?></td></tr>";
- lay += "<tr><td><?njs footer ?></td></tr></table>";
+ lay += "<tr valign=\"top\"><td width=\"120px\"><?njs sidebar ?></td><td><?njs body ?></td></tr>";
+ lay += "<tr><td><?njs footer ?></td></tr></table><?njs totalend ?></body></html>";
return lay;
}
var lay = "<html><head><?njs header ?></head><body><?nfs title ?>";
lay += "<table width=\"100%\"><tr><td><?njs menu ?></td></tr>";
lay += "<tr valign=\"top\"><td></td><?njs sidebar ?><td><?njs body ?></td></tr>";
- lay += "<tr><td><?njs footer ?></td></tr></table>";
+ lay += "<tr><td><?njs footer ?></td></tr></table><?njs totalend ?></body></html>";
return lay;
-}
\ No newline at end of file
+}
+
+exports.header = function(request, response, callback) {
+ // this function is the default header builder.
+ response.write("<title>mainname</title>");
+ callback(request, response);
+}
+
+exports.title = function(request, response, callback) {
+ // this is the default title builder
+ response.write("<h1>mainname</h1>");
+ callback(request, response);
+}
+
+exports.menu = function(request, response, callback) {
+ // this is the default title builder
+ response.write("<table><tr><th>Menu</th><td>item 1</td><td>item2</td></tr></table>");
+ callback(request, response);
+}
+
+exports.sidebar = function(request, response, callback) {
+ // this is the default title builder
+ response.write("Sidebar!");
+ callback(request, response);
+}
+
+exports.body = function(request, response, callback) {
+ // this is the default title builder
+ response.write("Body!");
+ callback(request, response);
+}
+
+exports.footer = function(request, response, callback) {
+ // this is the default title builder
+ response.write("<br><br><font size=\"-1\"><i>Copyright PJR.cc</i></font>");
+ callback(request, response);
+}
+
+exports.preResponse = function(request, response, callback) {
+ console.log("in preresponse - doing nothing");
+ callback();
+}
+++ /dev/null
-var path = require("fs");
-
-function useBody() {
- return;
-}
-
-function parse(base, purl, response, servicer) {
- var pathCheck = "./lib/web_"+base+".js";
- console.log("path check on ", pathCheck);
- fs.exists(pathCheck, function (exists) {
- if(!exists) console.log("not exists: ", base);
- else {
- servicer(purl, response, parse);
- console.log("base exists: ", base);
- }
- });
-}
-
-exports.useBody = useBody;
-exports.parse = parse;
-exports.process = process;
var url = require("url");
var path = require("path");
var fs = require("fs");
-var myparse = require("./myparse.js");
+//var myparse = require("./myparse.js");
var webmain = require("./webmain.js");
+var layouts = require("./layouts.js");
+
+// global stuff
+var extraCss = new Array();
+var extraJs = new Array();
+//var defaultLayout = null;
+var defaultMainPurl = null;
//var staticExtensions = ["html", "gif", "jpg", "css", "js", "ico"];
// now we need to find the extension used
// to serve the request based no the first purl
+
+
+ /*
+ *
if(purl.pathname == "/") {
console.log("Serv main");
webmain.serveMain(request, response, function (request, response) {
}
return;
});
+ */
+
+ urlServicer(request, response, purl);
+
+
+ return;
+}
+
+function urlServicer(request, response, purl) {
+ console.log("url servicer called for ", purl);
+
+ // first resolve the module making the call and determine layout/purl
+ var purlClass = layouts;
+ var purlLayout = layouts.standard();
+
+ if(purl.pathname == "/") {
+ if(defaultMainPurl == null) {
+ console.log("set purl class to layouts");
+ purlClass = layouts;
+ } else {
+ // find and load the purl
+ }
+
+ if(typeof purlClass.layout == "undefined") {
+ console.log("set via undefined");
+ purlLayout = layouts.standard();
+ } else {
+ // find and resolve the layout
+ }
+ } else {
+ // handle the purls
+ }
+
+ // now we should have a layout and a class
+ if(typeof purlClass.preResponse != "undefined") {
+ purlClass.preResponse(request, response, function() {
+ serviceLayout(request, response, purlClass, purlLayout);
+ });
+ } else {
+ serviceLayout(request, response, purlClass, purlLayout);
+ }
+ return;
+}
+
+function serviceLayout(request, response, purlClass, purlLayout) {
+ var reallay = "start:"+purlLayout+":end";
+ var splitup = reallay.split("<?njs");
+ var offset=0;
+
+ console.log("inservicer: ", purlLayout);
+ function processLayout() {
+ var output = "";
+
+ console.log("begin process layout");
+
+ if(offset >= splitup.length) {
+ response.write("end of caller");
+ response.end();
+ return;
+ } else if(offset == 0) {
+ console.log("write for offset 0");
+ output = splitup[0].replace(/^start:/g, "");
+ if(splitup.length == 1) output = output.replace(/:end$/g, "");
+ console.log("did write: ", output);
+ response.write(output);
+ offset++;
+ processLayout();
+ } else {
+ var thispart = splitup[offset].split("?>");
+ var caller = thispart[0].trim();
+
+ console.log("in parts for bits: ", thispart);
+ console.log("and caller is: ", caller);
+
+ // here we resolve and call the caller....
+ //response.write("calling: " + caller);
+ resolveAndCall(request, response, caller, purlClass, function () {
+ output = thispart[1].replace(/:end$/g, "");
+ response.write(output);
+ offset++;
+ processLayout();
+ });
+ }
+ }
+
+ processLayout();
+
+ //response.write("servicer");
+ //response.end();
+}
+
+function resolveAndCall(request, response, caller, purlClass, callback) {
+ //response.write("resolving: \"" + caller + "\"");
+ if(typeof purlClass[caller] != "undefined") {
+ purlClass[caller](request, response, callback);
+ } else if(typeof purlClass[caller] != "undefined"){
+ layouts[caller](request, response, callback);
+ } else {
+ response.write("<hr><br>Undefined layout section<br><hr>");
+ callback();
+ }
+ //callback();
return;
}
--- /dev/null
+var app = require("./lib/app.js");
+
+app.setPort(8888);
+//app.setDefaultLayout("standard");
+app.setDefaultMainPurl("main.js");
+
+app.start();