changeset 1099:118ab9641a64

ctextarea; s/header/include in the manual
author Adam Chlipala <adamc@hcoop.net>
date Tue, 29 Dec 2009 13:34:03 -0500
parents c023bc6ab914
children 9645e3c2978e
files doc/manual.tex lib/js/urweb.js lib/ur/basis.urs src/monoize.sml tests/ctextarea.ur tests/ctextarea.urp tests/ctextarea.urs
diffstat 7 files changed, 49 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/doc/manual.tex	Tue Dec 29 12:55:26 2009 -0500
+++ b/doc/manual.tex	Tue Dec 29 13:34:03 2009 -0500
@@ -140,7 +140,7 @@
 \item \texttt{effectful Module.ident} registers an FFI function or transaction as having side effects.  The optimizer avoids removing, moving, or duplicating calls to such functions.  Every effectful FFI function must be registered, or the optimizer may make invalid transformations.
 \item \texttt{exe FILENAME} sets the filename to which to write the output executable.  The default for file \texttt{P.urp} is \texttt{P.exe}.  
 \item \texttt{ffi FILENAME} reads the file \texttt{FILENAME.urs} to determine the interface to a new FFI module.  The name of the module is calculated from \texttt{FILENAME} in the same way as for normal source files.  See the files \texttt{include/urweb.h} and \texttt{src/c/urweb.c} for examples of C headers and implementations for FFI modules.  In general, every type or value \texttt{Module.ident} becomes \texttt{uw\_Module\_ident} in C.
-\item \texttt{header FILENAME} adds \texttt{FILENAME} to the list of files to be \texttt{\#include}d in C sources.  This is most useful for interfacing with new FFI modules.
+\item \texttt{include FILENAME} adds \texttt{FILENAME} to the list of files to be \texttt{\#include}d in C sources.  This is most useful for interfacing with new FFI modules.
 \item \texttt{jsFunc Module.ident=name} gives the JavaScript name of an FFI value.
 \item \texttt{library FILENAME} parses \texttt{FILENAME.urp} and merges its contents with the rest of the current file's contents.  If \texttt{FILENAME.urp} doesn't exist, the compiler also tries \texttt{FILENAME/lib.urp}.
 \item \texttt{link FILENAME} adds \texttt{FILENAME} to the list of files to be passed to the GCC linker at the end of compilation.  This is most useful for importing extra libraries needed by new FFI modules.
@@ -1992,7 +1992,7 @@
 \item \texttt{clientToServer Module.ident} declares a type as OK to marshal between clients and servers.  By default, abstract FFI types are not allowed to be marshalled, since your library might be maintaining invariants that the simple serialization code doesn't check.
 \item \texttt{effectful Module.ident} registers a function that can have side effects.  It is important to remember to use this directive for each such function, or else the optimizer might change program semantics.
 \item \texttt{ffi FILE.urs} names the file giving your library's signature.  You can include multiple such files in a single \texttt{.urp} file, and each file \texttt{mod.urp} defines an FFI module \texttt{Mod}.
-\item \texttt{header FILE} requests inclusion of a C header file.
+\item \texttt{include FILE} requests inclusion of a C header file.
 \item \texttt{jsFunc Module.ident=name} gives a mapping from an Ur name for a value to a JavaScript name.
 \item \texttt{link FILE} requests that \texttt{FILE} be linked into applications.  It should be a C object or library archive file, and you are responsible for generating it with your own build process.
 \item \texttt{script URL} requests inclusion of a JavaScript source file within application HTML.
--- a/lib/js/urweb.js	Tue Dec 29 12:55:26 2009 -0500
+++ b/lib/js/urweb.js	Tue Dec 29 13:34:03 2009 -0500
@@ -501,6 +501,15 @@
   return x;
 }
 
+function tbx(s) {
+  var x = input(document.createElement("textarea"), s,
+        function(x) { return function(v) { if (x.innerHTML != v) x.innerHTML = v; }; });
+  x.innerHTML = s.data;
+  x.onkeyup = function() { sv(s, x.value) };
+
+  return x;
+}
+
 function addOnChange(x, f) {
   var old = x.onchange;
   x.onchange = function() { old(); f (); };
--- a/lib/ur/basis.urs	Tue Dec 29 12:55:26 2009 -0500
+++ b/lib/ur/basis.urs	Tue Dec 29 13:34:03 2009 -0500
@@ -734,6 +734,9 @@
 val cselect : cformTag ([Source = source string, Onchange = transaction unit] ++ boxAttrs) cselect
 val coption : unit -> tag [Value = string, Selected = bool] cselect [] [] []
 
+val ctextarea : cformTag ([Value = string, Rows = int, Cols = int, Source = source string, Onchange = transaction unit,
+                           Ontext = transaction unit] ++ boxAttrs) []
+
 (*** Tables *)
 
 val tabl : other ::: {Unit} -> [other ~ [Body, Table]] => unit
--- a/src/monoize.sml	Tue Dec 29 12:55:26 2009 -0500
+++ b/src/monoize.sml	Tue Dec 29 13:34:03 2009 -0500
@@ -2985,6 +2985,29 @@
 
                    | "coption" => normal ("option", NONE, NONE)
 
+                   | "ctextarea" =>
+                     (case List.find (fn ("Source", _, _) => true | _ => false) attrs of
+                          NONE =>
+                          let
+                              val (ts, fm) = tagStart "textarea"
+                          in
+                              ((L'.EStrcat (ts,
+                                            (L'.EPrim (Prim.String " />"), loc)),
+                                loc), fm)
+                          end
+                        | SOME (_, src, _) =>
+                          let
+                              val sc = strcat [str "tbx(exec(",
+                                               (L'.EJavaScript (L'.Script, src), 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))
             end
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/ctextarea.ur	Tue Dec 29 13:34:03 2009 -0500
@@ -0,0 +1,8 @@
+fun main () =
+    s <- source "DEFAULT";
+    return <xml><body>
+      <ctextarea rows={2} source={s}/><br/>
+      <br/>
+
+      <dyn signal={s <- signal s; return (cdata s)}/>
+    </body></xml>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/ctextarea.urp	Tue Dec 29 13:34:03 2009 -0500
@@ -0,0 +1,3 @@
+debug
+
+ctextarea
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/ctextarea.urs	Tue Dec 29 13:34:03 2009 -0500
@@ -0,0 +1,1 @@
+val main : unit -> transaction page