[web-devel] [Haskell-cafe] Adding Html formatting to formlets
Alberto G. Corona
agocorona at gmail.com
Fri Feb 3 10:57:51 CET 2012
Hi Jeremy
If the signature of a formlet or digestive functor is
View *format m a *
with `*m*` a monad, `*a*` the resulting value and `*format*` the
formatting (Usually HTML)
then the signatures of the operators for Text.XHtml format are:
*(<<<) :: Monad m => (Html -> Html) -> View Html m a -> View Html m a
(<++) :: Monad m => Html -> View Html m a -> View Html m a
(++>) :: Monad m => View Html m a -> Html -> View Html m a
(<+>) :: Monad m => View Html m a -> View Html m b -> View Html m
(Either a' b')*
My mplementation is tightly integrated with other non related
functionalities in an app server that I´m developing so a translation to
diggestive functors is not trivial, but I too would love to have this
integrated in digestive functors for the shake of modularity.
2012/2/3 Jeremy Shaw <jeremy at n-heptane.com>:
> Hello,
>
> Formlets is deprecated in favor of digestive functors. If you have not
looked at the digestive-functors package I highly recommend that you do. It
fixes a lot of little issues that formlets had -- but is basically the same
thing.
>
> The (<<<) operator is a already a standard operator in Control.Category /
Control.Arrow. So, it is probably confusing to reuse that symbol for
something else…
>
> The digestive functors library defines two new operators (++>) and (<++)
which are somewhat related to what you are trying to do.
>
> In HTML, the <label> tag is supposed to reference the 'id' of the field
is it labeling. For example, you might have:
>
> <label for="username">Username: </label><input text="text" id="username"
name="username" value="">
>
> In formlets, there was no way to do that because the 'ids' are not
accessible to the user. In digestive functors you can use the ++> operator
to 'share' an id between to elements. That allows you to write:
>
> label "Username :" ++> inputText Nothing
>
> Anyway, I would love to see:
>
> a) your new combinators renamed and reimplemented for digestive-functors
> b) the type signatures of these new operators
>
> With out the type signatures it is a bit hard to decipher what your new
operators are actually doing..
>
> But, I love seeing any new improvements to the
formlets/digestive-functors concept!
>
> - jeremy
>
>
>
> On Feb 2, 2012, at 6:50 PM, Alberto G. Corona wrote:
>
>> I came across the idea that is easy to define additional operators to
>> Text.FormLets for adding custom HTML formatting.
>> Had anyone tried that?
>>
>>
>> For example to enclose the Prod formulary in a Table using Text.XHtml
>> tags. I defined additional operators <<< and <++ for enclosing and
>> prepending
>> Html to a formLet, respectively:
>>
>>> data Prod= Prod{pname :: String, pprice :: Int}
>>
>>> getProd= table <<< (
>>> Prod <$> tr <<< (td << "enter the name" <++ td <<< getString
(pname <$> mp))
>>> <*> tr <<< (td << "enter the price" <++ td <<< getInt
( pprice <$> mp)))
>>
>>
>> even:
>>
>>> p << "paragraph" <++ getProd ++> (more Html stuff)
>>
>> is possible
>>
>> or even it is possible an operator <+>
>>
>>> getProd <+> someOtherStuff
>>
>> to return Either Prod OtherStuff
>>
>>
>> I did it in my own version of FormLets. So It is too heavy to put
>> here a running example. It is part of a package that I will upload
>> soon to hackage.
>>
>>
>>
>> This also may work for embedding formLets in other haskell HTML
>> formats besides Text.XHtml.
>>
>> _______________________________________________
>> Haskell-Cafe mailing list
>> Haskell-Cafe at haskell.org
>> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/web-devel/attachments/20120203/c63bf238/attachment.htm>
More information about the web-devel
mailing list