# HG changeset patch # User Adam Chlipala # Date 1449335046 18000 # Node ID 6eae499c56cb2c4666d72fce856794ea854ee8da # Parent 100352dbae3676d2ede67a9c809b4f7da18b4657 New .urp directive: jsFile diff -r 100352dbae36 -r 6eae499c56cb src/cjr_print.sml --- a/src/cjr_print.sml Fri Nov 27 15:28:12 2015 -0500 +++ b/src/cjr_print.sml Sat Dec 05 12:04:06 2015 -0500 @@ -2944,17 +2944,10 @@ file = "app." ^ timestamp ^ ".js"} val allScripts = - let - val scripts = - "\\n" - in - foldl (fn (x, scripts) => - scripts - ^ "\\n") - scripts (Settings.getScripts ()) - end + foldl (fn (x, scripts) => + scripts + ^ "\\n") + "" (Settings.getScripts () @ [app_js]) fun p_page (ek, s, n, ts, ran, side, dbmode, tellSig) = let diff -r 100352dbae36 -r 6eae499c56cb src/compiler.sml --- a/src/compiler.sml Fri Nov 27 15:28:12 2015 -0500 +++ b/src/compiler.sml Sat Dec 05 12:04:06 2015 -0500 @@ -875,6 +875,10 @@ 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 -r 100352dbae36 -r 6eae499c56cb src/jscomp.sml --- a/src/jscomp.sml Fri Nov 27 15:28:12 2015 -0500 +++ b/src/jscomp.sml Sat Dec 05 12:04:06 2015 -0500 @@ -1358,8 +1358,9 @@ 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 -r 100352dbae36 -r 6eae499c56cb src/settings.sig --- a/src/settings.sig Fri Nov 27 15:28:12 2015 -0500 +++ b/src/settings.sig Sat Dec 05 12:04:06 2015 -0500 @@ -288,4 +288,7 @@ 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 -r 100352dbae36 -r 6eae499c56cb src/settings.sml --- a/src/settings.sml Fri Nov 27 15:28:12 2015 -0500 +++ b/src/settings.sml Sat Dec 05 12:04:06 2015 -0500 @@ -903,6 +903,25 @@ 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 @@ noMimeFile := false; mimeTypes := NONE; files := SM.empty; + jsFiles := SM.empty; filePath := ".") end