From f1c421a22a684a5eebc3e44f08228b23716b95e8 Mon Sep 17 00:00:00 2001 From: Paul J R Date: Mon, 31 Dec 2012 08:43:37 +1100 Subject: [PATCH] commenting example code --- examples/simple/myapp.js | 13 ++++++++----- examples/simple/purls/justlayout.js | 10 ++++++++++ examples/simple/purls/main.js | 5 +++++ 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/examples/simple/myapp.js b/examples/simple/myapp.js index c0065e1..ae2ac7f 100644 --- a/examples/simple/myapp.js +++ b/examples/simple/myapp.js @@ -1,21 +1,24 @@ -// require the main njspurls modules +// require the main njspurls module var app = require("njspurls"); // below we set a bunch of things globally for the app // set the port to listen to app.setPort(8888); -// location for loading "purls" +// location for loading "purls" - this is the default app.setPurlPath("./purls"); -// location for static resources +// location for static resources - default app.setResPath("./res"); // purl to load for main page, i.e. / // this will search for main.js from purls/ (this is the default) +// note - if none is provided, it defaults to layouts from layouts.js app.setDefaultMainPurl("main"); -// add some menu items for the default menu builder +// add some menu items for the default menu builder - a simple menu +// building mechanism which creates an array in global that can then be +// rendered via the layout.menu function app.addMenu("Home", "/"); app.addMenu("SimpleLayout", "/simplelayout"); app.addMenu("LayoutOnly", "/justlayout"); @@ -24,7 +27,7 @@ app.addMenu("LayoutOnly", "/justlayout"); // builders where a name is required app.setAppName("MyExampleApp"); -// set some default footer text (typically a copyright notice or something +// set some default footer text (typically a copyright notice or something) app.setFooterText("

Copyright PJR.cc 2012 ©"); diff --git a/examples/simple/purls/justlayout.js b/examples/simple/purls/justlayout.js index a108a99..050a4fc 100644 --- a/examples/simple/purls/justlayout.js +++ b/examples/simple/purls/justlayout.js @@ -1,3 +1,13 @@ +/* + * this is an example of a purl that simply contains a layout and only a layout + * + * this is useful when you can do everything synchronously and just need to fling back + * some content - if you tie layout to preRequest you can make preRequest determine + * if you can simply use layout to push some simple html out and this simplifies the + * whole request pipeline. + */ + + exports.layout = function(request, response) { var tkl = "

Just a Layout

this purl is simply a layout"; tkl += " and nothing else!"; diff --git a/examples/simple/purls/main.js b/examples/simple/purls/main.js index 888876c..f279247 100644 --- a/examples/simple/purls/main.js +++ b/examples/simple/purls/main.js @@ -1,8 +1,13 @@ + +// the standard layout (which can be seen in layouts.js) includes a body - +// this function is responsible for rendering that body exports.body = function(request, response, callback) { response.write("new body for main"); callback(); } +// before any data is written for a request, this is called and this is where you +// might process post data for example. exports.preResponse = function(request, response, callback) { console.log("this is preresponse for main"); callback(); -- 1.7.0.4