comparison src/cjr_print.sml @ 1731:27e731a65934

Include JavaScript files properly in error handler pages
author Adam Chlipala <adam@chlipala.net>
date Sat, 28 Apr 2012 12:00:35 -0400
parents a1a1d66aebac
children c414850f206f
comparison
equal deleted inserted replaced
1730:02533f681ad2 1731:27e731a65934
2903 2903
2904 val timestamp = LargeInt.toString (Time.toMilliseconds (Time.now ())) 2904 val timestamp = LargeInt.toString (Time.toMilliseconds (Time.now ()))
2905 val app_js = OS.Path.joinDirFile {dir = Settings.getUrlPrefix (), 2905 val app_js = OS.Path.joinDirFile {dir = Settings.getUrlPrefix (),
2906 file = "app." ^ timestamp ^ ".js"} 2906 file = "app." ^ timestamp ^ ".js"}
2907 2907
2908 val allScripts =
2909 let
2910 val scripts =
2911 "<script type=\\\"text/javascript\\\" src=\\\""
2912 ^ app_js
2913 ^ "\\\"></script>\\n"
2914 in
2915 foldl (fn (x, scripts) =>
2916 scripts
2917 ^ "<script type=\\\"text/javascript\\\" src=\\\"" ^ x ^ "\\\"></script>\\n")
2918 scripts (Settings.getScripts ())
2919 end
2920
2908 fun p_page (ek, s, n, ts, ran, side, tellSig) = 2921 fun p_page (ek, s, n, ts, ran, side, tellSig) =
2909 let 2922 let
2910 val (ts, defInputs, inputsVar, fields) = 2923 val (ts, defInputs, inputsVar, fields) =
2911 case ek of 2924 case ek of
2912 Core.Action _ => 2925 Core.Action _ =>
3030 string "uw_set_script_header(ctx, \"", 3043 string "uw_set_script_header(ctx, \"",
3031 let 3044 let
3032 val scripts = 3045 val scripts =
3033 case side of 3046 case side of
3034 ServerOnly => "" 3047 ServerOnly => ""
3035 | _ => 3048 | _ => allScripts
3036 let
3037 val scripts =
3038 "<script type=\\\"text/javascript\\\" src=\\\""
3039 ^ app_js
3040 ^ "\\\"></script>\\n"
3041 in
3042 foldl (fn (x, scripts) =>
3043 scripts
3044 ^ "<script type=\\\"text/javascript\\\" src=\\\"" ^ x ^ "\\\"></script>\\n")
3045 scripts (Settings.getScripts ())
3046 end
3047 in 3049 in
3048 string scripts 3050 string scripts
3049 end, 3051 end,
3050 string "\");", 3052 string "\");",
3051 newline]), 3053 newline]),
3127 val sequences = ref [] 3129 val sequences = ref []
3128 val dbstring = ref "" 3130 val dbstring = ref ""
3129 val expunge = ref 0 3131 val expunge = ref 0
3130 val initialize = ref 0 3132 val initialize = ref 0
3131 val prepped = ref [] 3133 val prepped = ref []
3134 val hasJs = ref false
3132 3135
3133 val _ = foldl (fn (d, env) => 3136 val _ = foldl (fn (d, env) =>
3134 ((case #1 d of 3137 ((case #1 d of
3135 DDatabase {name = x, expunge = y, initialize = z} => (hasDb := true; 3138 DDatabase {name = x, expunge = y, initialize = z} => (hasDb := true;
3136 dbstring := x; 3139 dbstring := x;
3137 expunge := y; 3140 expunge := y;
3138 initialize := z) 3141 initialize := z)
3142 | DJavaScript _ => hasJs := true
3139 | DTable (s, xts, _, _) => tables := (s, map (fn (x, t) => 3143 | DTable (s, xts, _, _) => tables := (s, map (fn (x, t) =>
3140 (x, sql_type_in env t)) xts) :: !tables 3144 (x, sql_type_in env t)) xts) :: !tables
3141 | DView (s, xts, _) => views := (s, map (fn (x, t) => 3145 | DView (s, xts, _) => views := (s, map (fn (x, t) =>
3142 (x, sql_type_in env t)) xts) :: !views 3146 (x, sql_type_in env t)) xts) :: !views
3143 | DSequence s => sequences := s :: !sequences 3147 | DSequence s => sequences := s :: !sequences
3497 if Settings.getDebug () then 3501 if Settings.getDebug () then
3498 box [] 3502 box []
3499 else 3503 else
3500 box [string "uw_cutErrorLocation(msg);", 3504 box [string "uw_cutErrorLocation(msg);",
3501 newline], 3505 newline],
3506 if !hasJs then
3507 box [string "uw_set_script_header(ctx, \"",
3508 string allScripts,
3509 string "\");",
3510 newline]
3511 else
3512 box [],
3502 box [string "uw_write(ctx, ", 3513 box [string "uw_write(ctx, ",
3503 p_enamed env n, 3514 p_enamed env n,
3504 string "(ctx, msg, 0));", 3515 string "(ctx, msg, 0));",
3505 newline], 3516 newline],
3506 string "}", 3517 string "}",