{-# LANGUAGE QuasiQuotes, ScopedTypeVariables, TypeFamilies #-}
module Text.Reform.Hamlet.Common where
import Data.Text.Lazy (Text, pack)
import qualified Data.Text as T
import Text.Blaze (ToMarkup(..))
import Text.Reform.Backend
import Text.Reform.Core
import Text.Reform.Generalized as G
import Text.Reform.Result (FormId, Result(Ok), unitRange)
import Text.Hamlet (hamlet, HtmlUrl)
instance ToMarkup FormId where
toMarkup fid = toMarkup (show fid)
inputText :: (FormError error, Monad m, ToMarkup text) => (input -> Either error text) -> text -> Form m input error (HtmlUrl url) () text
inputText getInput initialValue = G.input getInput inputField initialValue
where
inputField i a = [hamlet||]
inputPassword :: (Monad m, FormError error, ToMarkup text) =>
(input -> Either error text)
-> text
-> Form m input error (HtmlUrl url) () text
inputPassword getInput initialValue = G.input getInput inputField initialValue
where
inputField i a = [hamlet||]
inputSubmit :: (Monad m, FormError error, ToMarkup text) =>
(input -> Either error text)
-> text
-> Form m input error (HtmlUrl url) () (Maybe text)
inputSubmit getInput initialValue = G.inputMaybe getInput inputField initialValue
where
inputField i a = [hamlet||]
inputReset :: (Monad m, FormError error, ToMarkup text) =>
text
-> Form m input error (HtmlUrl url) () ()
inputReset lbl = G.inputNoData inputField lbl
where
inputField i a = [hamlet||]
inputHidden :: (Monad m, FormError error, ToMarkup text) =>
(input -> Either error text)
-> text
-> Form m input error (HtmlUrl url) () text
inputHidden getInput initialValue = G.input getInput inputField initialValue
where
inputField i a = [hamlet||]
inputButton :: (Monad m, FormError error, ToMarkup text) =>
text
-> Form m input error (HtmlUrl url) () ()
inputButton label = G.inputNoData inputField label
where
inputField i a = [hamlet||]
textarea :: (Monad m, FormError error, ToMarkup text) =>
(input -> Either error text)
-> Int -- ^ cols
-> Int -- ^ rows
-> text -- ^ initial text
-> Form m input error (HtmlUrl url) () text
textarea getInput cols rows initialValue = G.input getInput textareaView initialValue
where
textareaView i txt = [hamlet|