changeset 1926:44f607a7f4cd

Rename <activeHead> to <script> and make it work properly
author Adam Chlipala <adam@chlipala.net>
date Mon, 09 Dec 2013 15:47:14 -0500
parents 15802a00816c
children b6aee1d5b9b1
files doc/manual.tex lib/ur/basis.urs src/monoize.sml tests/ahead.ur
diffstat 4 files changed, 22 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/doc/manual.tex	Fri Dec 06 14:52:47 2013 +0400
+++ b/doc/manual.tex	Mon Dec 09 15:47:14 2013 -0500
@@ -2103,6 +2103,14 @@
   \mt{val} \; \mt{stopPropagation} : \mt{transaction} \; \mt{unit}
 \end{array}$$
 
+Finally, here is an HTML tag to leave a marker in the \cd{<head>} of a document asking for some side-effecting code to be run.  This pattern is \emph{much} less common in Ur/Web applications than in normal HTML/JavaScript applications; see Section \ref{signals} for the more idiomatic, functional way of manipulating the visible page.
+
+$$\begin{array}{l}
+  \mt{val} \; \mt{script} : \mt{unit} \to \mt{tag} \; [\mt{Code} = \mt{transaction} \; \mt{unit}] \; \mt{head} \; [] \; [] \; []
+\end{array}$$
+
+Note that the Ur/Web version of \cd{<script>} is used like \cd{<script code=\{...\}/>}, rather than \cd{<script>...</script>}.
+
 \subsubsection{Node IDs}
 
 There is an abstract type of node IDs that may be assigned to \cd{id} attributes of most HTML tags.
--- a/lib/ur/basis.urs	Fri Dec 06 14:52:47 2013 +0400
+++ b/lib/ur/basis.urs	Mon Dec 09 15:47:14 2013 -0500
@@ -782,7 +782,7 @@
 val active : unit
              -> tag [Code = transaction xbody] body [] [] []
 
-val activeHead : unit
+val script : unit
              -> tag [Code = transaction unit] head [] [] []
 
 val head : unit -> tag [] html head [] []
--- a/src/monoize.sml	Fri Dec 06 14:52:47 2013 +0400
+++ b/src/monoize.sml	Mon Dec 09 15:47:14 2013 -0500
@@ -3264,7 +3264,7 @@
                 val (style, fm) = monoExp (env, st, fm) style
                 val (dynStyle, fm) = monoExp (env, st, fm) dynStyle
 
-                val dynamics = ["dyn", "ctextbox", "ccheckbox", "cselect", "coption", "ctextarea", "active", "activeHead"]
+                val dynamics = ["dyn", "ctextbox", "ccheckbox", "cselect", "coption", "ctextarea", "active", "script"]
 
                 fun isSome (e, _) =
                     case e of
@@ -3600,15 +3600,15 @@
 			      fm)
                            | _ => raise Fail "Monoize: Bad <active> attributes")
 
-                      | "activeHead" =>
+                      | "script" =>
                         (case attrs of
 			     [("Code", e, _)] =>
 			     ((L'.EStrcat
-                                   ((L'.EPrim (Prim.String ("<script type=\"text/javascript\">execD(")), loc),
+                                   ((L'.EPrim (Prim.String ("<script type=\"text/javascript\">execF(execD(")), loc),
                                     (L'.EStrcat ((L'.EJavaScript (L'.Script, e), loc),
-                                                 (L'.EPrim (Prim.String (")</script>")), loc)), loc)), loc),
+                                                 (L'.EPrim (Prim.String ("))</script>")), loc)), loc)), loc),
 			      fm)
-                           | _ => raise Fail "Monoize: Bad <activeHead> attributes")
+                           | _ => raise Fail "Monoize: Bad <script> attributes")
 
                       | "submit" => normal ("input type=\"submit\"", NONE)
                       | "image" => normal ("input type=\"image\"", NONE)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/ahead.ur	Mon Dec 09 15:47:14 2013 -0500
@@ -0,0 +1,8 @@
+fun main () : transaction page = return <xml>
+  <head>
+    <script code={alert "Hi!"}/>
+  </head>
+  <body>
+    <active code={alert "Bye!"; return <xml/>}/>
+  </body>
+</xml>