diff options
author | Adam Chlipala <adam@chlipala.net> | 2013-12-09 15:47:14 -0500 |
---|---|---|
committer | Adam Chlipala <adam@chlipala.net> | 2013-12-09 15:47:14 -0500 |
commit | db0aff13453186d3f6edf46b42e43690ea113aea (patch) | |
tree | e034f612a841d48eb9db72b593b77bd4c07c909e | |
parent | fa448e6a07ce4435d596019497a3da8e4eb33f23 (diff) |
Rename <activeHead> to <script> and make it work properly
-rw-r--r-- | doc/manual.tex | 8 | ||||
-rw-r--r-- | lib/ur/basis.urs | 2 | ||||
-rw-r--r-- | src/monoize.sml | 10 | ||||
-rw-r--r-- | tests/ahead.ur | 8 |
4 files changed, 22 insertions, 6 deletions
diff --git a/doc/manual.tex b/doc/manual.tex index ac12c3b7..db1bfe1c 100644 --- a/doc/manual.tex +++ b/doc/manual.tex @@ -2103,6 +2103,14 @@ $$\begin{array}{l} \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. diff --git a/lib/ur/basis.urs b/lib/ur/basis.urs index 66e65804..73cef3d2 100644 --- a/lib/ur/basis.urs +++ b/lib/ur/basis.urs @@ -782,7 +782,7 @@ val dyn : ctx ::: {Unit} -> use ::: {Type} -> bind ::: {Type} -> [ctx ~ [Dyn]] = 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 [] [] diff --git a/src/monoize.sml b/src/monoize.sml index d382194f..291c0fa3 100644 --- a/src/monoize.sml +++ b/src/monoize.sml @@ -3264,7 +3264,7 @@ fun monoExp (env, st, fm) (all as (e, loc)) = 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 @@ fun monoExp (env, st, fm) (all as (e, loc)) = 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) diff --git a/tests/ahead.ur b/tests/ahead.ur new file mode 100644 index 00000000..29938d07 --- /dev/null +++ b/tests/ahead.ur @@ -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> |