diff src/monoize.sml @ 606:5145181b02fa

Use normal fields of ctextboxes
author Adam Chlipala <adamc@hcoop.net>
date Tue, 27 Jan 2009 09:53:51 -0500
parents b1064de2b1f9
children 0dd40b6bfdf3
line wrap: on
line diff
--- a/src/monoize.sml	Sat Jan 17 09:55:12 2009 -0500
+++ b/src/monoize.sml	Tue Jan 27 09:53:51 2009 -0500
@@ -1777,12 +1777,12 @@
                                 L'.ERecord xes => xes
                               | _ => raise Fail "Non-record attributes!"
 
+                fun lowercaseFirst "" = ""
+                  | lowercaseFirst s = String.str (Char.toLower (String.sub (s, 0)))
+                                       ^ String.extract (s, 1, NONE)
+
                 fun tagStart tag =
                     let
-                        fun lowercaseFirst "" = ""
-                          | lowercaseFirst s = String.str (Char.toLower (String.sub (s, 0)))
-                                               ^ String.extract (s, 1, NONE)
-
                         val s = (L'.EPrim (Prim.String (String.concat ["<", tag])), loc)
                     in
                         foldl (fn (("Action", _, _), acc) => acc
@@ -1897,6 +1897,26 @@
                                 normal ()
                           | _ => normal ()
                     end
+
+                fun setAttrs jexp =
+                    let
+                        val s = (L'.EPrim (Prim.String (String.concat ["<", tag])), loc)
+
+                        val assgns = List.mapPartial
+                                     (fn ("Source", _, _) => NONE
+                                       | (x, e, _) =>
+                                         SOME (strcat [str ("d." ^ lowercaseFirst x ^ "="),
+                                                       (L'.EJavaScript (L'.Script, e, NONE), loc),
+                                                       str ";"]))
+                                     attrs
+                    in
+                        case assgns of
+                            [] => jexp
+                          | _ => strcat (str "var d="
+                                         :: jexp
+                                         :: str ";"
+                                         :: assgns)
+                    end
             in
                 case tag of
                     "body" => normal ("body", NONE,
@@ -2002,12 +2022,17 @@
                                loc), fm)
                          end
                        | SOME (_, src, _) =>
-                         (strcat [str "<script type=\"text/javascript\">inp(\"input\",",
-                                  (L'.EJavaScript (L'.Script, src, NONE), loc),
-                                  str ")</script>"],
-                          fm))
-
-                  | "option" => normal ("option", NONE, NONE)
+                         let
+                             val sc = strcat [str "inp(\"input\",",
+                                              (L'.EJavaScript (L'.Script, src, NONE), loc),
+                                              str ")"]
+                             val sc = setAttrs sc
+                         in
+                             (strcat [str "<script type=\"text/javascript\">",
+                                      sc,
+                                      str "</script>"],
+                              fm)
+                         end)
 
                   | "tabl" => normal ("table", NONE, NONE)
                   | _ => normal (tag, NONE, NONE)