changeset 1111:e1d738870086

JavaScript urlification; more lenient export pattern in Corify; only include scripts in pages that use JavaScript
author Adam Chlipala <adamc@hcoop.net>
date Sat, 02 Jan 2010 14:54:15 -0500
parents 7fc4e0087e50
children 7a31e0cf25e9
files lib/js/urweb.js src/cjr_print.sml src/corify.sml src/jscomp.sml
diffstat 4 files changed, 38 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- a/lib/js/urweb.js	Sat Jan 02 13:31:59 2010 -0500
+++ b/lib/js/urweb.js	Sat Jan 02 14:54:15 2010 -0500
@@ -691,6 +691,10 @@
   inFlight = remove(xhr, inFlight);
 }
 
+function unurlify(parse, s) {
+  return parse(s);
+}
+
 function rc(prefix, uri, parse, k, needsSig) {
   uri = cat(prefix, uri);
   uri = flattenLocal(uri);
--- a/src/cjr_print.sml	Sat Jan 02 13:31:59 2010 -0500
+++ b/src/cjr_print.sml	Sat Jan 02 14:54:15 2010 -0500
@@ -2591,15 +2591,19 @@
                                         val scripts =
                                             case side of
                                                 ServerOnly => ""
-                                              | _ => "<script src=\\\""
-                                                     ^ OS.Path.joinDirFile {dir = Settings.getUrlPrefix (),
-                                                                            file = "app.js"}
-                                                     ^ "\\\"></script>\\n"
-
-                                        val scripts = foldl (fn (x, scripts) =>
-                                                                scripts
-                                                                ^ "<script src=\\\"" ^ x ^ "\\\"></script>\\n")
-                                                      scripts (Settings.getScripts ())
+                                              | _ =>
+                                                let
+                                                    val scripts =
+                                                        "<script src=\\\""
+                                                        ^ OS.Path.joinDirFile {dir = Settings.getUrlPrefix (),
+                                                                               file = "app.js"}
+                                                        ^ "\\\"></script>\\n"
+                                                in
+                                                    foldl (fn (x, scripts) =>
+                                                              scripts
+                                                              ^ "<script src=\\\"" ^ x ^ "\\\"></script>\\n")
+                                                          scripts (Settings.getScripts ())
+                                                end
                                     in
                                         string scripts
                                     end,
--- a/src/corify.sml	Sat Jan 02 13:31:59 2010 -0500
+++ b/src/corify.sml	Sat Jan 02 14:54:15 2010 -0500
@@ -964,16 +964,15 @@
                          fun wrapSgi ((sgi, _), (wds, eds))  =
                              case sgi of
                                  L.SgiVal (s, _, t as (L.TFun (dom, ran), _)) =>
-                                 (case (#1 dom, #1 ran) of
-                                      (L.TRecord _,
-                                       L.CApp ((L.CModProj (basis, [], "transaction"), _),
-                                               ran' as
-                                                    (L.CApp
-                                                         ((L.CApp
-                                                               ((L.CApp ((L.CModProj (basis', [], "xml"), _),
-                                                                         (L.CRecord (_, [((L.CName "Html", _),
-                                                                                          _)]), _)), _), _),
-                                                           _), _), _))) =>
+                                 (case #1 ran of
+                                      L.CApp ((L.CModProj (basis, [], "transaction"), _),
+                                              ran' as
+                                                   (L.CApp
+                                                        ((L.CApp
+                                                              ((L.CApp ((L.CModProj (basis', [], "xml"), _),
+                                                                        (L.CRecord (_, [((L.CName "Html", _),
+                                                                                         _)]), _)), _), _),
+                                                          _), _), _)) =>
                                       let
                                           val ran = (L.TRecord (L.CRecord ((L.KType, loc), []), loc), loc)
                                           val ranT = (L.CApp ((L.CModProj (basis, [], "transaction"), loc),
--- a/src/jscomp.sml	Sat Jan 02 13:31:59 2010 -0500
+++ b/src/jscomp.sml	Sat Jan 02 14:54:15 2010 -0500
@@ -869,10 +869,21 @@
                           | EDml _ => unsupported "DML"
                           | ENextval _ => unsupported "Nextval"
                           | ESetval _ => unsupported "Nextval"
-                          | EUnurlify _ => unsupported "EUnurlify"
                           | EReturnBlob _ => unsupported "EUnurlify"
                           | ERedirect _ => unsupported "ERedirect"
 
+                          | EUnurlify (e, t) =>
+                            let
+                                val (e, st) = jsE inner (e, st)
+                                val (e', st) = unurlifyExp loc (t, st)
+                            in
+                                (strcat [str ("{c:\"f\",f:\"unurlify\",a:cons({c:\"c\",v:function(s){var t=s.split(\"/\");var i=0;return "
+                                              ^ e' ^ "}},cons("),
+                                         e,
+                                         str ",null))}"],
+                                 st)
+                            end
+
                           | ESignalReturn e =>
                             let
                                 val (e, st) = jsE inner (e, st)