Skip to content

Commit

Permalink
Adjustments for the rewrite to use root packages and run on Ringo
Browse files Browse the repository at this point in the history
  • Loading branch information
kriszyp committed Oct 14, 2011
1 parent c814334 commit 9643925
Show file tree
Hide file tree
Showing 11 changed files with 122 additions and 51 deletions.
7 changes: 3 additions & 4 deletions 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,
Expand All @@ -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({
Expand Down
42 changes: 23 additions & 19 deletions 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,
Expand All @@ -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
Expand All @@ -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);
}
])
);
};
3 changes: 0 additions & 3 deletions 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){
Expand All @@ -9,4 +7,3 @@ exports.RedirectRoot = function(app){
return app(request);
};
};
};
7 changes: 6 additions & 1 deletion 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) {

Expand Down
3 changes: 1 addition & 2 deletions model/page.js
Expand Up @@ -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));

Expand Down Expand Up @@ -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
Expand Down
19 changes: 11 additions & 8 deletions public/edit.html
Expand Up @@ -28,16 +28,19 @@
<button>Upload</button>
<iframe name="upload-target" id="upload-target" style="display:none"></iframe>
</form>
<!-- You can use RequireJS or Yabble (obviously you should download this and have it available locally) -->
<!--
RequireJS:
<script>
// Configure RequireJS
require = {baseUrl: "lib/"};
</script>-->
<!--<script src="require.js"></script>-->
require = {
baseUrl: "../packages/",
paths: {
example: "../public/js/"
}
};
</script>

<script src="lib/transporter/receiver.js"></script>
<script src="lib/edit.js"></script>
<script src="../packages/requirejs/require.js"></script>
<script>
require(["example/edit"]);
</script>
</body>
</html>
10 changes: 6 additions & 4 deletions edit.js → 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"
}
Expand Down Expand Up @@ -74,7 +75,7 @@ function login(){

function userRpc(method, params){
return request({
url: "User/",
url: "/User/",
method: "POST",
body: JSON.stringify({
id:"call-id",
Expand Down Expand Up @@ -103,4 +104,5 @@ function errorHandler(error){
function escapeHTML(html){
return html.replace(/&/g, "&amp;")
.replace(/</g, "&lt;");
}
}
});
Expand Down
2 changes: 2 additions & 0 deletions monitor.js → public/js/monitor.js
@@ -1,3 +1,4 @@
define(function(require){
var JSON = require("commonjs-utils/json"),
request = require("promised-io/http-client").request;

Expand Down Expand Up @@ -33,3 +34,4 @@ function monitor(){
});
}
setTimeout(monitor, 1000);
});
60 changes: 60 additions & 0 deletions ringo-index.js
@@ -0,0 +1,60 @@
/**
* The starting point for Pintura running as a Jack 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.main == module){
var server = new (require("ringo/httpserver").Server)({appName: "app", appModule: module.id});
server.getContext("/public").serveStatic("public");
server.getContext("/packages").serveStatic("C:/packages");
server.start();
}

//});


var perseverePath;/*,
Static = require("jack/lib/jack/static").Static,
Directory = require("jack/lib/jack/dir").Directory;*/

var path = require.paths[0].match(/(.*?)[\/\\]packages[\/\\]/);
if(path){
perseverePath = path[1] + "/packages/persevere/public";
}

// now setup the development environment, handle static files before reloading the app
// for better performance
//exports.app = exports.development = function(app, options){
// make the root url redirect to /Page/Root
//require("./jsgi/redirect-root").RedirectRoot(require("jack/lib/jack/redirect").Redirect,
exports.app =
// cascade from static to pintura REST handling
/* // this will provide module wrapping for the Dojo modules for the client
transporter.Transporter({
urlPrefix:"/js/",
paths:["../../persevere/public/js/"],
converter: transporter.Dojo
}),*/
// the main place for static files accessible from the web
//require('ringo/middleware/static').middleware(module.resolve('public')),
//Directory("public", Static(null, {urls:[""], root: "public"})),
//Static(null, {urls:["/explorer"], root: perseverePath + "/explorer"}),
// main Pintura handler
function(request){
print("request" + request);
return pinturaApp(request);
}
;

10 changes: 5 additions & 5 deletions templates/Page.template
@@ -1,16 +1,16 @@
<html>
<title>{{pageName}}</title>
<link rel="stylesheet" href="/css/common.css" />
<link rel="stylesheet" href="/css/wikiContent.css" />
<script src="/lib/transporter/receiver.js"></script>
<script src="/lib/monitor.js"></script>
<link rel="stylesheet" href="/public/css/common.css" />
<link rel="stylesheet" href="/public/css/wikiContent.css" />
<script src="/packages/requirejs/require.js"></script>
<script src="/packages/example/monitor.js"></script>
<body>
<div id="headerContainer"><span class="pageName">{{pageName}}<span></div>
<div id="content">
<p>{{content}}</p>
</div>
<div id="action">
<a href="/edit.html?page={{pageName}}">Edit this page</a>
<a href="/public/edit.html?page={{pageName}}">Edit this page</a>
</div>
</body>
</html>
10 changes: 5 additions & 5 deletions templates/error/404.template
@@ -1,16 +1,16 @@
<html>
<title>{{pageName}}</title>
<link rel="stylesheet" href="/css/common.css" />
<link rel="stylesheet" href="/css/wikiContent.css" />
<script src="/lib/transporter/receiver.js"></script>
<script src="/lib/monitor.js"></script>
<link rel="stylesheet" href="/public/css/common.css" />
<link rel="stylesheet" href="/public/css/wikiContent.css" />
<script src="/packages/requirejs/require.js"></script>
<script src="/packages/example/monitor.js"></script>
<body>
<div id="headerContainer"><span class="pageName">{{pageName}}<span></div>
<div id="content">
<p>This page does not yet exist. Click below to create the page.</p>
</div>
<div id="action">
<a href="/edit.html?page={{pageName}}">Create this page</a>
<a href="/public/edit.html?page={{pageName}}">Create this page</a>
</div>
</body>
</html>

0 comments on commit 9643925

Please sign in to comment.