{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeFamilies #-}
{-# OPTIONS_GHC -fno-warn-orphans #-}
module Ditto.Lucid where
import Data.Foldable (traverse_)
import Data.Text (Text)
import Ditto.Core
import Ditto.Generalized.Unnamed as G
import Lucid
formGenGET
:: (Applicative m)
=> Text
-> [(Text, Text)]
-> HtmlT m b
-> HtmlT m b
formGenGET action hidden children = do
form_ [action_ action, method_ "GET", enctype_ "application/xxx-form-urlencoded"] $
traverse_ mkHidden hidden *>
children
where
mkHidden (name, value) = input_ [type_ "hidden", name_ name, value_ value]
formGenPOST
:: (Applicative m)
=> Text
-> [(Text, Text)]
-> HtmlT m b
-> HtmlT m b
formGenPOST action hidden children = do
form_ [action_ action, method_ "POST", enctype_ "application/xxx-form-urlencoded"] $
traverse_ mkHidden hidden *>
children
where
mkHidden (name, value) = input_ [type_ "hidden", name_ name, value_ value]
setAttr
:: (Environment m input, Functor m, Applicative f)
=> [Attribute]
-> Form m input error (HtmlT f ()) a
-> Form m input error (HtmlT f ()) a
setAttr attr form = mapView (\x -> x `with` attr) form
errorList
:: (Environment m input, ToHtml error, Monad f)
=> Form m input error (HtmlT f ()) ()
errorList = G.errors mkErrors
where
mkErrors :: Monad f => ToHtml a => [a] -> HtmlT f ()
mkErrors [] = mempty
mkErrors errs = ul_ [class_ "ditto-error-list"] $ traverse_ mkError errs
mkError :: Monad f => ToHtml a => a -> HtmlT f ()
mkError e = li_ [] $ toHtml e
childErrorList
:: (Environment m input, ToHtml error, Monad f)
=> Form m input error (HtmlT f ()) ()
childErrorList = G.childErrors mkErrors
where
mkErrors :: Monad f => ToHtml a => [a] -> HtmlT f ()
mkErrors [] = mempty
mkErrors errs = ul_ [class_ "ditto-error-list"] $ traverse_ mkError errs
mkError :: Monad f => ToHtml a => a -> HtmlT f ()
mkError e = li_ [] $ toHtml e
withErrors
:: (Environment m input, ToHtml error, Monad f)
=> (HtmlT f () -> [error] -> HtmlT f ())
-> Form m input error (HtmlT f ()) a
-> Form m input error (HtmlT f ()) a
withErrors renderError form = G.withErrors renderError form
withChildErrors
:: (Environment m input, ToHtml error, Monad f)
=> (HtmlT f () -> [error] -> HtmlT f ())
-> Form m input error (HtmlT f ()) a
-> Form m input error (HtmlT f ()) a
withChildErrors renderError form = G.withChildErrors renderError form
br :: (Environment m input, Applicative f) => Form m input error (HtmlT f ()) ()
br = view (br_ [])
fieldset
:: (Environment m input, Functor m, Applicative f)
=> Form m input error (HtmlT f ()) a
-> Form m input error (HtmlT f ()) a
fieldset frm = mapView (fieldset_ [class_ "ditto"]) frm
ol
:: (Environment m input, Functor m, Applicative f)
=> Form m input error (HtmlT f ()) a
-> Form m input error (HtmlT f ()) a
ol frm = mapView (ol_ [class_ "ditto"]) frm
ul
:: (Environment m input, Functor m, Applicative f)
=> Form m input error (HtmlT f ()) a
-> Form m input error (HtmlT f ()) a
ul frm = mapView (ul_ [class_ "ditto"]) frm
li
:: (Environment m input, Functor m, Applicative f)
=> Form m input error (HtmlT f ()) a
-> Form m input error (HtmlT f ()) a
li frm = mapView (li_ [class_ "ditto"]) frm