packages feed

digestive-functors-blaze 0.1.1.0 → 0.2.0.0

raw patch · 2 files changed

+80/−23 lines, 2 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

+ Text.Digestive.Blaze.Html5: inputHidden' :: (Monad m, Functor m, FormInput i f) => Formlet m i e BlazeFormHtml String
+ Text.Digestive.Blaze.Html5: inputPassword' :: (Monad m, Functor m, FormInput i f) => Form m i e BlazeFormHtml String
+ Text.Digestive.Blaze.Html5: inputSelect :: (Monad m, Functor m, FormInput i f, Eq a) => a -> [(a, Html)] -> Form m i e BlazeFormHtml a
+ Text.Digestive.Blaze.Html5: inputText' :: (Monad m, Functor m, FormInput i f) => Formlet m i e BlazeFormHtml String
+ Text.Digestive.Blaze.Html5: inputTextArea' :: (Monad m, Functor m, FormInput i f) => Maybe Int -> Maybe Int -> Maybe String -> Form m i e BlazeFormHtml String
- Text.Digestive.Blaze.Html5: inputHidden :: (Monad m, Functor m, FormInput i f) => Formlet m i e BlazeFormHtml String
+ Text.Digestive.Blaze.Html5: inputHidden :: (Monad m, Functor m, FormInput i f) => Formlet m i e BlazeFormHtml Text
- Text.Digestive.Blaze.Html5: inputPassword :: (Monad m, Functor m, FormInput i f) => Form m i e BlazeFormHtml String
+ Text.Digestive.Blaze.Html5: inputPassword :: (Monad m, Functor m, FormInput i f) => Form m i e BlazeFormHtml Text
- Text.Digestive.Blaze.Html5: inputTextArea :: (Monad m, Functor m, FormInput i f) => Maybe Int -> Maybe Int -> Maybe String -> Form m i e BlazeFormHtml String
+ Text.Digestive.Blaze.Html5: inputTextArea :: (Monad m, Functor m, FormInput i f) => Maybe Int -> Maybe Int -> Maybe Text -> Form m i e BlazeFormHtml Text

Files

digestive-functors-blaze.cabal view
@@ -1,5 +1,5 @@ Name:          digestive-functors-blaze-Version:       0.1.1.0+Version:       0.2.0.0 Synopsis:      Blaze frontend for the digestive-functors library Description:   This is a blaze frontend for the digestive-functors library. @@ -10,10 +10,11 @@ Maintainer:    Jasper Van der Jeugt <m@jaspervdj.be> Category:      Web Build-type:    Simple-Cabal-version: >=1.6+Cabal-version: >= 1.6  Library   Hs-source-dirs: src+  GHC-options:    -Wall -fwarn-tabs    Exposed-modules:     Text.Digestive.Blaze.Html5
src/Text/Digestive/Blaze/Html5.hs view
@@ -2,13 +2,18 @@ module Text.Digestive.Blaze.Html5     ( BlazeFormHtml     , inputText+    , inputText'     , inputHidden+    , inputHidden'     , inputTextArea+    , inputTextArea'     , inputTextRead     , inputPassword+    , inputPassword'     , inputCheckBox     , inputRadio     , inputFile+    , inputSelect     , submit     , label     , errors@@ -21,8 +26,10 @@ import Control.Monad (forM_, unless, when) import Data.Maybe (fromMaybe) import Data.Monoid (mempty)+import Data.String (IsString(..)) import Data.Text (Text) +import Text.Blaze (Attribute) import Text.Blaze.Html5 (Html, (!), toValue, toHtml) import qualified Text.Blaze.Html5 as H import qualified Text.Blaze.Html5.Attributes as A@@ -46,24 +53,31 @@ applyClasses' = applyClasses $ \element value ->     element ! A.class_ (toValue value) +-- | Applies an attribute to some HTML, but only if an associated+-- boolean value is true.+attrWhenTrue :: Attribute -> Bool -> Html -> Html+attrWhenTrue a True  h = h ! a+attrWhenTrue _ False h = h+ -- | Checks the input element when the argument is true--- checked :: Bool -> Html -> Html-checked False x = x-checked True  x = x ! A.checked "checked"+checked = attrWhenTrue (A.checked "checked") -inputString :: (Monad m, Functor m, FormInput i f)-            => Formlet m i e BlazeFormHtml String-inputString = Forms.inputString $ \id' inp -> createFormHtml $ \cfg ->-    applyClasses' [htmlInputClasses] cfg $-        H.input ! A.type_ "text"-                ! A.name (toValue $ show id')-                ! A.id (toValue $ show id')-                ! A.value (toValue $ fromMaybe "" inp)+-- | Selects an @<option>@ when the argument is true.+selected :: Bool -> Html -> Html+selected = attrWhenTrue (A.selected "selected")  inputText :: (Monad m, Functor m, FormInput i f)           => Formlet m i e BlazeFormHtml Text-inputText = Forms.inputText $ \id' inp -> createFormHtml $ \cfg ->+inputText = Forms.inputText inputTextHTML++inputText' :: (Monad m, Functor m, FormInput i f)+           => Formlet m i e BlazeFormHtml String+inputText' = Forms.inputString inputTextHTML++inputTextHTML :: (H.ToValue b, IsString b, Show a)+              => a -> Maybe b -> FormHtml Html+inputTextHTML id' inp = createFormHtml $ \cfg ->     applyClasses' [htmlInputClasses] cfg $         H.input ! A.type_ "text"                 ! A.name (toValue $ show id')@@ -71,8 +85,16 @@                 ! A.value (toValue $ fromMaybe "" inp)  inputHidden :: (Monad m, Functor m, FormInput i f)-            => Formlet m i e BlazeFormHtml String-inputHidden = Forms.inputString $ \id' inp -> createFormHtml $ \cfg ->+            => Formlet m i e BlazeFormHtml Text+inputHidden = Forms.inputText inputHiddenHTML++inputHidden' :: (Monad m, Functor m, FormInput i f)+             => Formlet m i e BlazeFormHtml String+inputHidden' = Forms.inputString inputHiddenHTML++inputHiddenHTML :: (H.ToValue b, IsString b, Show a)+                => a -> Maybe b -> FormHtml Html+inputHiddenHTML id' inp = createFormHtml $ \cfg ->     applyClasses' [htmlInputClasses] cfg $         H.input ! A.type_ "hidden"                 ! A.name (toValue $ show id')@@ -82,9 +104,20 @@ inputTextArea :: (Monad m, Functor m, FormInput i f)               => Maybe Int                        -- ^ Rows               -> Maybe Int                        -- ^ Columns-              -> Maybe String                     -- ^ Default input-              -> Form m i e BlazeFormHtml String  -- ^ Result-inputTextArea r c = Forms.inputString $ \id' inp -> createFormHtml $ \cfg ->+              -> Maybe Text                       -- ^ Default input+              -> Form m i e BlazeFormHtml Text    -- ^ Result+inputTextArea r c = Forms.inputText $ inputTextAreaHTML r c++inputTextArea' :: (Monad m, Functor m, FormInput i f)+               => Maybe Int                        -- ^ Rows+               -> Maybe Int                        -- ^ Columns+               -> Maybe String                     -- ^ Default input+               -> Form m i e BlazeFormHtml String  -- ^ Result+inputTextArea' r c = Forms.inputString $ inputTextAreaHTML r c++inputTextAreaHTML :: (H.ToHtml d, IsString d, Show b, Show c, Show a)+                  => Maybe a -> Maybe b -> c -> Maybe d -> FormHtml Html+inputTextAreaHTML r c id' inp = createFormHtml $ \cfg ->     applyClasses' [htmlInputClasses] cfg $ rows r $ cols c $         H.textarea ! A.name (toValue $ show id')                    ! A.id (toValue $ show id')@@ -107,8 +140,16 @@                 ! A.value (toValue $ fromMaybe "" inp)  inputPassword :: (Monad m, Functor m, FormInput i f)-              => Form m i e BlazeFormHtml String-inputPassword = flip Forms.inputString Nothing $ \id' inp ->+              => Form m i e BlazeFormHtml Text+inputPassword = Forms.inputText inputPasswordHTML Nothing++inputPassword' :: (Monad m, Functor m, FormInput i f)+               => Form m i e BlazeFormHtml String+inputPassword' = Forms.inputString inputPasswordHTML Nothing++inputPasswordHTML :: (H.ToValue b, IsString b, Show a)+                  => a -> Maybe b -> FormHtml Html+inputPasswordHTML id' inp =     createFormHtml $ \cfg -> applyClasses' [htmlInputClasses] cfg $         H.input ! A.type_ "password"                 ! A.name (toValue $ show id')@@ -141,11 +182,26 @@                 $ fromMaybe mempty $ lookup val choices         when br H.br +inputSelect :: (Monad m, Functor m, FormInput i f, Eq a)+            => a                           -- ^ Default option+            -> [(a, Html)]                 -- ^ Choices with their names+            -> Form m i e BlazeFormHtml a  -- ^ Resulting form+inputSelect def choices = Form $ do+    id' <- getFormId+    unForm $ mapViewHtml (H.select ! A.name (toValue $ show id') ) $+        Forms.inputChoice toView def (map fst choices)+  where+    toView _ id' sel val = createFormHtml $ \cfg -> do+        applyClasses' [htmlInputClasses] cfg $ selected sel $+            H.option ! A.type_ "radio"+                     ! A.value (toValue id')+                     $ fromMaybe mempty $ lookup val choices+ inputFile :: (Monad m, Functor m, FormInput i f)           => Form m i e BlazeFormHtml (Maybe f)  -- ^ Form inputFile = Forms.inputFile toView   where-    toView id' = createFormHtmlWith MultiPart $ \cfg -> do+    toView id' = createFormHtmlWith MultiPart $ \cfg ->         applyClasses' [htmlInputClasses] cfg $             H.input ! A.type_ "file"                     ! A.name (toValue $ show id')@@ -204,7 +260,7 @@     mapView (fmap addControls) $ Forms.inputList hidden s d   where     s def = mapView (fmap (H.div ! A.class_ "inputListItem")) $ single def-    addControls form = do+    addControls form =         H.div ! A.class_ "inputList" $ do             H.div $ do                 H.input ! A.type_ "button"