Mercurial > urweb
changeset 2197:6eae499c56cb
New .urp directive: jsFile
author | Adam Chlipala <adam@chlipala.net> |
---|---|
date | Sat, 05 Dec 2015 12:04:06 -0500 |
parents | 100352dbae36 |
children | cf2abef213d8 |
files | src/cjr_print.sml src/compiler.sml src/jscomp.sml src/settings.sig src/settings.sml |
diffstat | 5 files changed, 34 insertions(+), 13 deletions(-) [+] |
line wrap: on
line diff
--- 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 = - "<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
--- 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
--- 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
--- 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
--- 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