summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Adam Chlipala <adam@chlipala.net>2015-12-05 12:04:06 -0500
committerGravatar Adam Chlipala <adam@chlipala.net>2015-12-05 12:04:06 -0500
commitbad7adde120773d46af83ab972967f26823e37b4 (patch)
treea1e8aac4d22273e103ddf675ee88f19b3fee2e0a
parent4635acd2d4e4404b2b1a89909cd765ac310d62c5 (diff)
New .urp directive: jsFile
-rw-r--r--src/cjr_print.sml15
-rw-r--r--src/compiler.sml4
-rw-r--r--src/jscomp.sml5
-rw-r--r--src/settings.sig3
-rw-r--r--src/settings.sml20
5 files changed, 34 insertions, 13 deletions
diff --git a/src/cjr_print.sml b/src/cjr_print.sml
index 9c456863..774b95b9 100644
--- a/src/cjr_print.sml
+++ b/src/cjr_print.sml
@@ -2944,17 +2944,10 @@ fun p_file env (ds, ps) =
file = "app." ^ timestamp ^ ".js"}
val allScripts =
- let
- val scripts =
- "<script type=\\\"text/javascript\\\" src=\\\""
- ^ app_js
- ^ "\\\"></script>\\n"
- in
- foldl (fn (x, scripts) =>
- scripts
- ^ "<script type=\\\"text/javascript\\\" src=\\\"" ^ x ^ "\\\"></script>\\n")
- scripts (Settings.getScripts ())
- end
+ foldl (fn (x, scripts) =>
+ scripts
+ ^ "<script type=\\\"text/javascript\\\" src=\\\"" ^ x ^ "\\\"></script>\\n")
+ "" (Settings.getScripts () @ [app_js])
fun p_page (ek, s, n, ts, ran, side, dbmode, tellSig) =
let
diff --git a/src/compiler.sml b/src/compiler.sml
index 99f2ff31..e2d590b4 100644
--- a/src/compiler.sml
+++ b/src/compiler.sml
@@ -875,6 +875,10 @@ fun parseUrp' accLibs fname =
url := {action = Settings.Allow, kind = Settings.Exact, pattern = uri} :: !url)
| _ => ErrorMsg.error "Bad 'file' arguments")
+ | "jsFile" =>
+ (Settings.setFilePath thisPath;
+ Settings.addJsFile arg)
+
| _ => ErrorMsg.error ("Unrecognized command '" ^ cmd ^ "'");
read ()
end
diff --git a/src/jscomp.sml b/src/jscomp.sml
index 3709bcd3..9c8effd7 100644
--- a/src/jscomp.sml
+++ b/src/jscomp.sml
@@ -1358,8 +1358,9 @@ fun process (file : file) =
val script =
if !foundJavaScript then
- lines ^ urlRules ^ String.concat (rev (#script st))
- ^ "\ntime_format = \"" ^ Prim.toCString (Settings.getTimeFormat ()) ^ "\";\n"
+ String.concatWith "" ((lines ^ urlRules ^ String.concat (rev (#script st))
+ ^ "\ntime_format = \"" ^ Prim.toCString (Settings.getTimeFormat ()) ^ "\";\n")
+ :: map (fn r => "\n// " ^ #Filename r ^ "\n\n" ^ #Content r ^ "\n") (Settings.listJsFiles ()))
else
""
in
diff --git a/src/settings.sig b/src/settings.sig
index d918f0c5..3f39d3e2 100644
--- a/src/settings.sig
+++ b/src/settings.sig
@@ -288,4 +288,7 @@ signature SETTINGS = sig
val addFile : {Uri : string, LoadFromFilename : string} -> unit
val listFiles : unit -> {Uri : string, ContentType : string option, LastModified : Time.time, Bytes : Word8Vector.vector} list
+
+ val addJsFile : string (* filename *) -> unit
+ val listJsFiles : unit -> {Filename : string, Content : string} list
end
diff --git a/src/settings.sml b/src/settings.sml
index 8300d621..650122ca 100644
--- a/src/settings.sml
+++ b/src/settings.sml
@@ -903,6 +903,25 @@ fun addFile {Uri, LoadFromFilename} =
fun listFiles () = map #2 (SM.listItems (!files))
+val jsFiles = ref (SM.empty : {Filename : string, Content : string} SM.map)
+
+fun addJsFile LoadFromFilename =
+ let
+ val path = OS.Path.concat (!filePath, LoadFromFilename)
+ val inf = TextIO.openIn path
+ in
+ jsFiles := SM.insert (!jsFiles,
+ path,
+ {Filename = LoadFromFilename,
+ Content = TextIO.inputAll inf});
+ TextIO.closeIn inf
+ end handle IO.Io _ =>
+ ErrorMsg.error ("Error loading file " ^ LoadFromFilename)
+ | OS.SysErr (s, _) =>
+ ErrorMsg.error ("Error loading file " ^ LoadFromFilename ^ " (" ^ s ^ ")")
+
+fun listJsFiles () = SM.listItems (!jsFiles)
+
fun reset () =
(urlPrefixFull := "/";
urlPrefix := "/";
@@ -945,6 +964,7 @@ fun reset () =
noMimeFile := false;
mimeTypes := NONE;
files := SM.empty;
+ jsFiles := SM.empty;
filePath := ".")
end