diff options
author | Adam Chlipala <adam@chlipala.net> | 2014-11-16 14:02:17 -0500 |
---|---|---|
committer | Adam Chlipala <adam@chlipala.net> | 2014-11-16 14:02:17 -0500 |
commit | cd1df17a1dac04f2a353fbc49284b775e78817a5 (patch) | |
tree | ad2ce8905273af5770bd7217b18c7bb50be994e7 | |
parent | ff35b4cbd8c62fed584b48f660e4274c6e357893 (diff) |
Make 'required' and 'autofocus' attributes Boolean; add a syntax extension for parsing their usual HTML syntax
-rw-r--r-- | doc/manual.tex | 4 | ||||
-rw-r--r-- | lib/ur/basis.urs | 2 | ||||
-rw-r--r-- | src/urweb.grm | 6 | ||||
-rw-r--r-- | tests/html5_forms.ur | 12 | ||||
-rw-r--r-- | tests/html5_forms.urs | 1 |
5 files changed, 23 insertions, 2 deletions
diff --git a/doc/manual.tex b/doc/manual.tex index 0550d081..5935ccbf 100644 --- a/doc/manual.tex +++ b/doc/manual.tex @@ -2348,13 +2348,15 @@ $$\begin{array}{rrcll} &&& \texttt{<}g\texttt{>}l^*\texttt{</}x\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 --git a/lib/ur/basis.urs b/lib/ur/basis.urs index 170df50c..049d1864 100644 --- a/lib/ur/basis.urs +++ b/lib/ur/basis.urs @@ -949,7 +949,7 @@ con formTag = fn (ty :: Type) (inner :: {Unit}) (attrs :: {Type}) => 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 --git a/src/urweb.grm b/src/urweb.grm index edac345f..240f64cb 100644 --- a/src/urweb.grm +++ b/src/urweb.grm @@ -1747,6 +1747,12 @@ attr : SYMBOL EQ attrv (case SYMBOL of 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 --git a/tests/html5_forms.ur b/tests/html5_forms.ur new file mode 100644 index 00000000..2fa5c5c2 --- /dev/null +++ b/tests/html5_forms.ur @@ -0,0 +1,12 @@ +fun handler r = return <xml><body> +</body></xml> + +fun main () = + return <xml><body> + <form> + <textbox{#A} required placeholder="bobby"/> + <textbox{#B} placeholder="soggy" autofocus/> + + <submit action={handler}/> + </form> + </body></xml> diff --git a/tests/html5_forms.urs b/tests/html5_forms.urs new file mode 100644 index 00000000..6ac44e0b --- /dev/null +++ b/tests/html5_forms.urs @@ -0,0 +1 @@ +val main : unit -> transaction page |