From 96439258db5cdc5cd7be62cbf91d7be69f7f8aac Mon Sep 17 00:00:00 2001 From: Kris Zyp Date: Fri, 14 Oct 2011 12:58:16 -0600 Subject: [PATCH] Adjustments for the rewrite to use root packages and run on Ringo --- index.js | 7 ++-- jackconfig.js | 42 +++++++++++---------- jsgi/redirect-root.js | 3 -- jsgi/redirect.js | 7 +++- model/page.js | 3 +- public/edit.html | 19 ++++++---- edit.js => public/js/edit.js | 10 +++-- monitor.js => public/js/monitor.js | 2 + ringo-index.js | 60 ++++++++++++++++++++++++++++++ templates/Page.template | 10 ++--- templates/error/404.template | 10 ++--- 11 files changed, 122 insertions(+), 51 deletions(-) rename edit.js => public/js/edit.js (93%) rename monitor.js => public/js/monitor.js (97%) create mode 100644 ringo-index.js diff --git a/index.js b/index.js index 82f7991..b5f741c 100644 --- a/index.js +++ b/index.js @@ -1,6 +1,4 @@ // helpful for debugging -print = require("promised-io/process").print; - var pinturaApp, settings = require("commonjs-utils/settings"), Static = require("pintura/jsgi/static").Static, @@ -15,11 +13,12 @@ start( // uncomment this to enable compression with node-compress //require("pintura/jsgi/compress").Compress( // make the root url redirect to /Page/Root - require("./jsgi/redirect-root").RedirectRoot(require("jack/lib/jack/redirect").Redirect, + require("./jsgi/redirect-root").RedirectRoot( require("pintura/jsgi/cascade").Cascade([ // cascade from static to pintura REST handling // the main place for static files accessible from the web - Static({urls:[""], root: "public", directoryListing: true}), + Static({urls:["/public"], root: "public", directoryListing: true}), + Static({urls:["/packages"], root: "/c/packages", directoryListing: true}), Static({urls:["/explorer"], root: require("nodules").getCachePath("persevere-client/") + "/explorer"}), // this will provide access to the server side JS libraries from the client require("transporter/jsgi/transporter").Transporter({ diff --git a/jackconfig.js b/jackconfig.js index 0f0e8f7..9c45690 100644 --- a/jackconfig.js +++ b/jackconfig.js @@ -1,21 +1,28 @@ /** * The starting point for Pintura running as a Jack app. */ -var pinturaApp; -require("nodules").useLocal().ensure(["pintura/pintura", "app", "tunguska/jack-connector", "narwhal/narwhal/repl"], function(require){ - require.reloadable(function(){ - pinturaApp = require("pintura/pintura").app; - require("app"); - }); + +var Transporter, pinturaApp; +//require("nodules").useLocal().ensure(["pintura/pintura", "lib/app", "tunguska/jack-connector", "narwhal/lib/narwhal/repl", "transporter/jsgi/transporter"], function(require){ + Transporter = require("transporter/jsgi/transporter").Transporter; + //require.reloadable(function(){ + // this will provide access to the server side JS libraries from the client + pinturaApp = //Transporter({loader: require("nodules").forEngine("browser").useLocal().getModuleSource}, + // the main app + require("pintura/pintura").app; + require("./app"); + //}); require("tunguska/jack-connector").observe("worker", pinturaApp.addConnection); // we start the REPL (the interactive JS console) because it is really helpful - if(require("jack/handler/simple-worker").options.firstWorker){ - require("narwhal/narwhal/repl").repl(true); + if(require("jack/lib/jack/handler/simple-worker").options.firstWorker){ + require("narwhal/lib/narwhal/repl").repl(true); } -}); + + +//}); -var File = require("file"), - Transporter = require("jsgi/transporter").Transporter; +var File = require("file"); + var perseverePath, Static = require("jack/static").Static, @@ -30,7 +37,7 @@ if(path){ // for better performance exports.app = exports.development = function(app, options){ // make the root url redirect to /Page/Root - return require("./lib/jsgi/redirect-root").RedirectRoot( + return require("./lib/jsgi/redirect-root").RedirectRoot(require("jack/redirect").Redirect, require("jack/cascade").Cascade([ // cascade from static to pintura REST handling /* // this will provide module wrapping for the Dojo modules for the client @@ -42,13 +49,10 @@ exports.app = exports.development = function(app, options){ // the main place for static files accessible from the web Directory("public", Static(null, {urls:[""], root: "public"})), Static(null, {urls:["/explorer"], root: perseverePath + "/explorer"}), - // this will provide access to the server side JS libraries from the client - Transporter({loader: require("nodules").forEngine("browser").useLocal().getModuleSource}), - - // main Pintura handler - function(request){ - return pinturaApp(request); - } + // main Pintura handler + function(request){ + return pinturaApp(request); + } ]) ); }; diff --git a/jsgi/redirect-root.js b/jsgi/redirect-root.js index 3793812..ad46715 100644 --- a/jsgi/redirect-root.js +++ b/jsgi/redirect-root.js @@ -1,5 +1,3 @@ -exports.RedirectRoot = function(Redirect, app){ -// var redirector = Redirect("/Page/Example"); var redirector = require("./redirect").Redirect("/Page/Example"); exports.RedirectRoot = function(app){ return function(request){ @@ -9,4 +7,3 @@ exports.RedirectRoot = function(app){ return app(request); }; }; -}; \ No newline at end of file diff --git a/jsgi/redirect.js b/jsgi/redirect.js index 5f105a3..9f68f4b 100644 --- a/jsgi/redirect.js +++ b/jsgi/redirect.js @@ -1,4 +1,9 @@ -var uri = require("url"); +try{ + var uri = require("url"); +}catch(e){ + var uri = require("narwhal/lib/uri"); + +} exports.Redirect = function (path, status) { diff --git a/model/page.js b/model/page.js index 04aa1ee..2377232 100644 --- a/model/page.js +++ b/model/page.js @@ -29,7 +29,7 @@ pageStore = require("store/full-text").FullText(pageStore, "Page"); */ // to add events -originalPageStore = pageStore; +var originalPageStore = pageStore; pageStore = Notifying(Inherited(pageStore)); exports.PageSuper = PageSuper = Model(Inherited(originalPageStore)); @@ -68,7 +68,6 @@ Page = exports.Page = Model(pageStore, { return page; }, put: function(page, options){ // handle puts to add to history and define attribution - print("put called"); page.lastModifiedBy = promiseModule.currentContext.currentUser; page.status = "published"; // do the default action of saving to the store diff --git a/public/edit.html b/public/edit.html index dc260ce..293c81b 100644 --- a/public/edit.html +++ b/public/edit.html @@ -28,16 +28,19 @@ - - - + require = { + baseUrl: "../packages/", + paths: { + example: "../public/js/" + } + }; + - - + + diff --git a/edit.js b/public/js/edit.js similarity index 93% rename from edit.js rename to public/js/edit.js index b80e58d..3edd13d 100644 --- a/edit.js +++ b/public/js/edit.js @@ -1,14 +1,15 @@ +define(function(require){ var JSON = require("commonjs-utils/json"); pageName = location.search.match(/page=([^&]+)/); pageName = decodeURIComponent(pageName && pageName[1]); -require("monitor"); +require("./monitor"); document.title = "Editing " + pageName; var request = require("promised-io/http-client").request; document.getElementById("main-header").innerHTML = escapeHTML("Editing " + pageName); request({ - url: "Page/" + pageName, + url: "/Page/" + pageName, headers: { "accept": "application/javascript, application/json" } @@ -74,7 +75,7 @@ function login(){ function userRpc(method, params){ return request({ - url: "User/", + url: "/User/", method: "POST", body: JSON.stringify({ id:"call-id", @@ -103,4 +104,5 @@ function errorHandler(error){ function escapeHTML(html){ return html.replace(/&/g, "&") .replace(/ {{pageName}} - - - - + + + +
{{pageName}}

{{content}}

- Edit this page + Edit this page
diff --git a/templates/error/404.template b/templates/error/404.template index f307d23..db32e3c 100644 --- a/templates/error/404.template +++ b/templates/error/404.template @@ -1,16 +1,16 @@ {{pageName}} - - - - + + + +
{{pageName}}

This page does not yet exist. Click below to create the page.

- Create this page + Create this page