# HG changeset patch # User Adam Chlipala # Date 1416164537 18000 # Node ID fde864eacd47b88cd68fefae568b150cde582c20 # Parent e48e09a1f583bcb890ae924dbc61ae6702782d4d Make 'required' and 'autofocus' attributes Boolean; add a syntax extension for parsing their usual HTML syntax diff -r e48e09a1f583 -r fde864eacd47 doc/manual.tex --- a/doc/manual.tex Sun Oct 12 10:03:36 2014 +0000 +++ b/doc/manual.tex Sun Nov 16 14:02:17 2014 -0500 @@ -2348,13 +2348,15 @@ &&& \texttt{<}g\texttt{>}l^*\texttt{} & \textrm{tag with children} \\ &&& \{e\} & \textrm{computed XML fragment} \\ &&& \{[e]\} & \textrm{injection of an Ur expression, via the $\mt{Top}.\mt{txt}$ function} \\ - \textrm{Tag} & g &::=& h \; (x = v)^* \\ + \textrm{Tag} & g &::=& h \; (x [= v])^* \\ \textrm{Tag head} & h &::=& x & \textrm{tag name} \\ &&& h\{c\} & \textrm{constructor parameter} \\ \textrm{Attribute value} & v &::=& \ell & \textrm{literal value} \\ &&& \{e\} & \textrm{computed value} \\ \end{array}$$ +When the optional $= v$ is omitted in an XML attribute, the attribute is assigned value $\mt{True}$ in Ur/Web, and it is rendered to HTML merely as including the attribute name without a value. If such a Boolean attribute is manually set to value $\mt{False}$, then it is omitted altogether in generating HTML. + Further, there is a special convenience and compatibility form for setting CSS classes of tags. If a \cd{class} attribute has a value that is a string literal, the literal is parsed in the usual HTML way and replaced with calls to appropriate Ur/Web combinators. Any dashes in the text are replaced with underscores to determine Ur identifiers. The same desugaring can be accessed in a normal expression context by calling the pseudo-function \cd{CLASS} on a string literal. Similar support is provided for \cd{style} attributes. Normal CSS syntax may be used in string literals that are \cd{style} attribute values, and the desugaring may be accessed elsewhere with the pseudo-function \cd{STYLE}. diff -r e48e09a1f583 -r fde864eacd47 lib/ur/basis.urs --- a/lib/ur/basis.urs Sun Oct 12 10:03:36 2014 +0000 +++ b/lib/ur/basis.urs Sun Nov 16 14:02:17 2014 -0500 @@ -949,7 +949,7 @@ nm :: Name -> unit -> tag attrs ([Form] ++ ctx) inner [] [nm = ty] -con inputAttrs = [Required = string, Autofocus = string] +con inputAttrs = [Required = bool, Autofocus = bool] val hidden : formTag string [] [Data = data_attr, Id = string, Value = string] diff -r e48e09a1f583 -r fde864eacd47 src/urweb.grm --- a/src/urweb.grm Sun Oct 12 10:03:36 2014 +0000 +++ b/src/urweb.grm Sun Nov 16 14:02:17 2014 -0500 @@ -1747,6 +1747,12 @@ else attrv) end) + | SYMBOL (let + val loc = s (SYMBOLleft, SYMBOLright) + in + Normal ((CName (makeAttr SYMBOL), loc), + (EVar (["Basis"], "True", Infer), loc)) + end) attrv : INT (EPrim (Prim.Int INT), s (INTleft, INTright)) | FLOAT (EPrim (Prim.Float FLOAT), s (FLOATleft, FLOATright)) diff -r e48e09a1f583 -r fde864eacd47 tests/html5_forms.ur --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/html5_forms.ur Sun Nov 16 14:02:17 2014 -0500 @@ -0,0 +1,12 @@ +fun handler r = return + + +fun main () = + return +
+ + + + + +
diff -r e48e09a1f583 -r fde864eacd47 tests/html5_forms.urs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/html5_forms.urs Sun Nov 16 14:02:17 2014 -0500 @@ -0,0 +1,1 @@ +val main : unit -> transaction page