diff --git a/resource/compile-time.rkt b/resource/compile-time.rkt index 24151a9..a9d40b3 100644 --- a/resource/compile-time.rkt +++ b/resource/compile-time.rkt @@ -28,7 +28,6 @@ (syntax-e #'path)))] [munged-path (munge-path normal-path)] [content (call-with-input-file normal-path port->bytes)]) - (printf "Read ~s\n" content) (with-syntax ([normal-path normal-path] [munged-path munged-path] [content content]) diff --git a/resource/munge-path.rkt b/resource/munge-path.rkt index 6ae7b32..06be511 100644 --- a/resource/munge-path.rkt +++ b/resource/munge-path.rkt @@ -15,4 +15,5 @@ "") (get-output-string op))) (define-values (base path dir?) (split-path a-path)) - (string-append encoding-prefix "_" (path->string path))) + (string-append ;; encoding-prefix "_" + (path->string path))) diff --git a/web-world/examples/hello/hello.rkt b/web-world/examples/hello/hello.rkt index 062d9a6..b7061af 100644 --- a/web-world/examples/hello/hello.rkt +++ b/web-world/examples/hello/hello.rkt @@ -1,19 +1,19 @@ #lang planet dyoo/whalesong (require (planet dyoo/whalesong/web-world) - (planet dyoo/whalesong/resource) - (planet dyoo/whalesong/resource/structs)) + (planet dyoo/whalesong/resource)) + (define-resource index.html) +(define-resource style.css) +;; (printf "I see the path is: ~s\n" +;; (resource-path index.html)) -(printf "I see the path is: ~s\n" - (resource-path index.html)) +;; (printf "I see the key is: ~s\n" +;; (resource-key index.html)) -(printf "I see the key is: ~s\n" - (resource-key index.html)) +;; (printf "I see the content is: ~s\n" +;; (resource-content index.html)) -(printf "I see the content is: ~s\n" - (resource-content index.html)) - -;; (big-bang "don't care" -;; (initial-view index.html)) +(big-bang "don't care" + (initial-view index.html)) diff --git a/web-world/examples/hello/index.html b/web-world/examples/hello/index.html index 3d4ee39..53d1437 100644 --- a/web-world/examples/hello/index.html +++ b/web-world/examples/hello/index.html @@ -1,4 +1,6 @@ -Hello world +Hello world + +

Hello world

diff --git a/web-world/js-impl.js b/web-world/js-impl.js index 540128c..b52e9a4 100644 --- a/web-world/js-impl.js +++ b/web-world/js-impl.js @@ -18,11 +18,19 @@ var View = function(top, focused, eventHandlers, pendingActions) { this.eventHandlers = eventHandlers; this.pendingActions = pendingActions; }; +View.prototype.toString = function() { return "#"; } View.prototype.updateFocused = function(focused) { return new View(this.top, focused, eventHandlers, pendingActions); }; +View.prototype.initialRender = function(top) { + top.empty(); + $(document.head).append(this.top.find("head").children()); + top.append(this.top.find("body").children()); +}; + + var isView = plt.baselib.makeClassPredicate(View); var isResource = resourceStructType.predicate; @@ -45,20 +53,19 @@ var checkView = plt.baselib.check.makeCheckArgumentType( // coerseToView: (U resource View) -> View var coerseToView = function(x, onSuccess, onFail) { + var dom, v; if (isView(x)) { return onSuccess(x); } else if (isResource(x)) { - console.log(resourcePath(x), resourceKey(x), resourceContent(x).toString()); - $.ajax({ - url: "res/" + resourceKey(x), - dataType : "html", - success: function(data, textStatus, jqXHR) { - console.log("data is: ", data); - return onSuccess(new View(data, [], [], [])); - }, - error: function(jqXHR, textStatus, errorThrown) { - return onFail(new Error(errorThrown)); - }}); + dom = $(resourceContent(x).toString()) + .css("margin", "0px") + .css("padding", "0px") + .css("border", "0px"); + dom.children("body").css("margin", "0px"); + return onSuccess(new View(dom, + [], + [], + [])); } else { return onFail(new Error("Unable to coerse to view")); } @@ -79,6 +86,8 @@ var InitialViewHandler = function(args, view) { }; InitialViewHandler.prototype = plt.baselib.heir(WorldHandler.prototype); +InitialViewHandler.prototype.toString = function() { return "#"; }; +var isInitialViewHandler = plt.baselib.makeClassPredicate(InitialViewHandler); @@ -89,11 +98,22 @@ var StopWhenHandler = function(args, stopWhen) { }; StopWhenHandler.prototype = plt.baselib.heir(WorldHandler.prototype); +StopWhenHandler.prototype.toString = function() { return "#"; }; + +var isStopWhenHandler = plt.baselib.makeClassPredicate(StopWhenHandler); - +var findHandler = function(MACHINE, pred) { + var i; + for (i = 1; i < MACHINE.argcount; i++) { + if (pred(MACHINE.env[MACHINE.env.length - 1 - i])) { + return MACHINE.env[MACHINE.env.length - 1 - i]; + } + } + return undefined; +}; ////////////////////////////////////////////////////////////////////// @@ -103,11 +123,15 @@ EXPORTS['big-bang'] = makeClosure( 'big-bang', plt.baselib.arity.makeArityAtLeast(1), function(MACHINE) { - var oldArgcount = MACHINE.argcount; + var world = MACHINE.env[MACHINE.env.length - 1]; + var initialViewHandler = findHandler(MACHINE, isInitialViewHandler); + var oldArgcount = MACHINE.argcount; + var top = $("
"); + MACHINE.params.currentDisplayer(MACHINE, top); PAUSE(function(restart) { - // FILL ME IN + initialViewHandler.view.initialRender(top); var onRestart = function() { restart(function(MACHINE) {