ditto 0.3 → 0.3.1
raw patch · 5 files changed
+35/−35 lines, 5 filesPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
API changes (from Hackage documentation)
- Ditto.Backend: class FormError err input | err -> input
+ Ditto.Backend: class FormError input err
- Ditto.Backend: commonFormError :: FormError err input => CommonFormError input -> err
+ Ditto.Backend: commonFormError :: FormError input err => CommonFormError input -> err
- Ditto.Backend: getInputFile :: (FormInput input, FormError error input) => input -> Either error (FileType input)
+ Ditto.Backend: getInputFile :: (FormInput input, FormError input err) => input -> Either err (FileType input)
- Ditto.Backend: getInputString :: (FormInput input, FormError error input) => input -> Either error String
+ Ditto.Backend: getInputString :: (FormInput input, FormError input err) => input -> Either err String
- Ditto.Backend: getInputText :: (FormInput input, FormError error input) => input -> Either error Text
+ Ditto.Backend: getInputText :: (FormInput input, FormError input err) => input -> Either err Text
- Ditto.Generalized: input :: (Monad m, FormError err input) => (input -> Either err a) -> (FormId -> a -> view) -> a -> Form m input err view a
+ Ditto.Generalized: input :: (Monad m, FormError input err) => (input -> Either err a) -> (FormId -> a -> view) -> a -> Form m input err view a
- Ditto.Generalized: inputChoice :: forall a m err input lbl view. (FormError err input, FormInput input, Monad m) => (a -> Bool) -> [(a, lbl)] -> (FormId -> [(FormId, Int, lbl, Bool)] -> view) -> Form m input err view a
+ Ditto.Generalized: inputChoice :: forall a m err input lbl view. (FormError input err, FormInput input, Monad m) => (a -> Bool) -> [(a, lbl)] -> (FormId -> [(FormId, Int, lbl, Bool)] -> view) -> Form m input err view a
- Ditto.Generalized: inputChoiceForms :: forall a m err input lbl view. (Monad m, FormError err input, FormInput input) => a -> [(Form m input err view a, lbl)] -> (FormId -> [(FormId, Int, FormId, view, lbl, Bool)] -> view) -> Form m input err view a
+ Ditto.Generalized: inputChoiceForms :: forall a m err input lbl view. (Monad m, FormError input err, FormInput input) => a -> [(Form m input err view a, lbl)] -> (FormId -> [(FormId, Int, FormId, view, lbl, Bool)] -> view) -> Form m input err view a
- Ditto.Generalized: inputFile :: forall m input err view. (Monad m, FormInput input, FormError err input) => (FormId -> view) -> Form m input err view (FileType input)
+ Ditto.Generalized: inputFile :: forall m input err view. (Monad m, FormInput input, FormError input err) => (FormId -> view) -> Form m input err view (FileType input)
- Ditto.Generalized: inputMaybe :: (Monad m, FormError err input) => (input -> Either err a) -> (FormId -> Maybe a -> view) -> Maybe a -> Form m input err view (Maybe a)
+ Ditto.Generalized: inputMaybe :: (Monad m, FormError input err) => (input -> Either err a) -> (FormId -> Maybe a -> view) -> Maybe a -> Form m input err view (Maybe a)
- Ditto.Generalized: inputMaybeReq :: (Monad m, FormError err input) => (input -> Either err a) -> (FormId -> Maybe a -> view) -> Maybe a -> Form m input err view a
+ Ditto.Generalized: inputMaybeReq :: (Monad m, FormError input err) => (input -> Either err a) -> (FormId -> Maybe a -> view) -> Maybe a -> Form m input err view a
- Ditto.Generalized: inputMulti :: forall m input err view a lbl. (FormError err input, FormInput input, Monad m) => [(a, lbl)] -> (FormId -> [(FormId, Int, lbl, Bool)] -> view) -> (a -> Bool) -> Form m input err view [a]
+ Ditto.Generalized: inputMulti :: forall m input err view a lbl. (FormError input err, FormInput input, Monad m) => [(a, lbl)] -> (FormId -> [(FormId, Int, lbl, Bool)] -> view) -> (a -> Bool) -> Form m input err view [a]
- Ditto.Generalized.Named: input :: (Monad m, FormError err input) => String -> (input -> Either err a) -> (FormId -> a -> view) -> a -> Form m input err view a
+ Ditto.Generalized.Named: input :: (Monad m, FormError input err) => String -> (input -> Either err a) -> (FormId -> a -> view) -> a -> Form m input err view a
- Ditto.Generalized.Named: inputChoice :: forall a m err input lbl view. (FormError err input, FormInput input, Monad m) => String -> (a -> Bool) -> [(a, lbl)] -> (FormId -> [(FormId, Int, lbl, Bool)] -> view) -> Form m input err view a
+ Ditto.Generalized.Named: inputChoice :: forall a m err input lbl view. (FormError input err, FormInput input, Monad m) => String -> (a -> Bool) -> [(a, lbl)] -> (FormId -> [(FormId, Int, lbl, Bool)] -> view) -> Form m input err view a
- Ditto.Generalized.Named: inputChoiceForms :: forall a m err input lbl view. (Monad m, FormError err input, FormInput input) => String -> a -> [(Form m input err view a, lbl)] -> (FormId -> [(FormId, Int, FormId, view, lbl, Bool)] -> view) -> Form m input err view a
+ Ditto.Generalized.Named: inputChoiceForms :: forall a m err input lbl view. (Monad m, FormError input err, FormInput input) => String -> a -> [(Form m input err view a, lbl)] -> (FormId -> [(FormId, Int, FormId, view, lbl, Bool)] -> view) -> Form m input err view a
- Ditto.Generalized.Named: inputFile :: forall m input err view. (Monad m, FormInput input, FormError err input) => String -> (FormId -> view) -> Form m input err view (FileType input)
+ Ditto.Generalized.Named: inputFile :: forall m input err view. (Monad m, FormInput input, FormError input err) => String -> (FormId -> view) -> Form m input err view (FileType input)
- Ditto.Generalized.Named: inputMaybe :: (Monad m, FormError err input) => String -> (input -> Either err a) -> (FormId -> Maybe a -> view) -> Maybe a -> Form m input err view (Maybe a)
+ Ditto.Generalized.Named: inputMaybe :: (Monad m, FormError input err) => String -> (input -> Either err a) -> (FormId -> Maybe a -> view) -> Maybe a -> Form m input err view (Maybe a)
- Ditto.Generalized.Named: inputMaybeReq :: (Monad m, FormError err input) => String -> (input -> Either err a) -> (FormId -> Maybe a -> view) -> Maybe a -> Form m input err view a
+ Ditto.Generalized.Named: inputMaybeReq :: (Monad m, FormError input err) => String -> (input -> Either err a) -> (FormId -> Maybe a -> view) -> Maybe a -> Form m input err view a
- Ditto.Generalized.Named: inputMulti :: forall m input err view a lbl. (FormError err input, FormInput input, Monad m) => String -> [(a, lbl)] -> (FormId -> [(FormId, Int, lbl, Bool)] -> view) -> (a -> Bool) -> Form m input err view [a]
+ Ditto.Generalized.Named: inputMulti :: forall m input err view a lbl. (FormError input err, FormInput input, Monad m) => String -> [(a, lbl)] -> (FormId -> [(FormId, Int, lbl, Bool)] -> view) -> (a -> Bool) -> Form m input err view [a]
Files
- ditto.cabal +1/−1
- src/Ditto/Backend.hs +4/−4
- src/Ditto/Generalized.hs +7/−7
- src/Ditto/Generalized/Internal.hs +16/−16
- src/Ditto/Generalized/Named.hs +7/−7
ditto.cabal view
@@ -1,5 +1,5 @@ Name: ditto-Version: 0.3+Version: 0.3.1 Synopsis: ditto is a type-safe HTML form generation and validation library Description: ditto follows in the footsteps of formlets and digestive-functors <= 0.2. It provides a
src/Ditto/Backend.hs view
@@ -56,7 +56,7 @@ MissingDefaultValue -> "Missing default value." -- | A Class to lift a 'CommonFormError' into an application-specific error type-class FormError err input | err -> input where+class FormError input err where commonFormError :: CommonFormError input -> err instance FormError Text Text where@@ -73,7 +73,7 @@ -- | Parse the input into a string. This is used for simple text fields -- among other things --- getInputString :: (FormError error input) => input -> Either error String+ getInputString :: (FormError input err) => input -> Either err String getInputString input = case getInputStrings input of [] -> Left (commonFormError $ NoStringFound input)@@ -86,7 +86,7 @@ -- | Parse the input value into 'Text' --- getInputText :: (FormError error input) => input -> Either error Text+ getInputText :: (FormError input err) => input -> Either err Text getInputText input = case getInputTexts input of [] -> Left (commonFormError $ NoStringFound input)@@ -100,4 +100,4 @@ -- | Get a file descriptor for an uploaded file --- getInputFile :: (FormError error input) => input -> Either error (FileType input)+ getInputFile :: (FormError input err) => input -> Either err (FileType input)
src/Ditto/Generalized.hs view
@@ -11,12 +11,12 @@ import qualified Ditto.Generalized.Internal as G -- | used for constructing elements like @\<input type=\"text\"\>@, which pure a single input value.-input :: (Monad m, FormError err input) => (input -> Either err a) -> (FormId -> a -> view) -> a -> Form m input err view a+input :: (Monad m, FormError input err) => (input -> Either err a) -> (FormId -> a -> view) -> a -> Form m input err view a input = G.input getFormId -- | used for elements like @\<input type=\"submit\"\>@ which are not always present in the form submission data. inputMaybe- :: (Monad m, FormError err input)+ :: (Monad m, FormError input err) => (input -> Either err a) -> (FormId -> Maybe a -> view) -> Maybe a@@ -25,7 +25,7 @@ -- | used to construct elements with optional initial values, which are still required inputMaybeReq- :: (Monad m, FormError err input)+ :: (Monad m, FormError input err) => (input -> Either err a) -> (FormId -> Maybe a -> view) -> Maybe a@@ -41,14 +41,14 @@ -- | used for @\<input type=\"file\"\>@ inputFile- :: forall m input err view. (Monad m, FormInput input, FormError err input)+ :: forall m input err view. (Monad m, FormInput input, FormError input err) => (FormId -> view) -> Form m input err view (FileType input) inputFile = G.inputFile getFormId -- | used for groups of checkboxes, @\<select multiple=\"multiple\"\>@ boxes inputMulti- :: forall m input err view a lbl. (FormError err input, FormInput input, Monad m)+ :: forall m input err view a lbl. (FormError input err, FormInput input, Monad m) => [(a, lbl)] -- ^ value, label, initially checked -> (FormId -> [(FormId, Int, lbl, Bool)] -> view) -- ^ function which generates the view -> (a -> Bool) -- ^ isChecked/isSelected initially@@ -57,7 +57,7 @@ -- | radio buttons, single @\<select\>@ boxes inputChoice- :: forall a m err input lbl view. (FormError err input, FormInput input, Monad m)+ :: forall a m err input lbl view. (FormError input err, FormInput input, Monad m) => (a -> Bool) -- ^ is default -> [(a, lbl)] -- ^ value, label -> (FormId -> [(FormId, Int, lbl, Bool)] -> view) -- ^ function which generates the view@@ -66,7 +66,7 @@ -- | radio buttons, single @\<select\>@ boxes inputChoiceForms- :: forall a m err input lbl view. (Monad m, FormError err input, FormInput input)+ :: forall a m err input lbl view. (Monad m, FormError input err, FormInput input) => a -> [(Form m input err view a, lbl)] -- ^ value, label -> (FormId -> [(FormId, Int, FormId, view, lbl, Bool)] -> view) -- ^ function which generates the view
src/Ditto/Generalized/Internal.hs view
@@ -18,7 +18,7 @@ -- | used for constructing elements like @\<input type=\"text\"\>@, which pure a single input value. input- :: (Monad m, FormError err input)+ :: forall m input err a view. (Monad m, FormError input err) => FormState m input FormId -> (input -> Either err a) -> (FormId -> a -> view)@@ -57,11 +57,11 @@ ) Missing -> pure ( View $ const $ toView i initialValue- , pure $ Error [(unitRange i, commonFormError (InputMissing i))]+ , pure $ Error [(unitRange i, commonFormError (InputMissing i :: CommonFormError input) :: err)] ) inputMaybeReq- :: (Monad m, FormError err input)+ :: forall m input err a view. (Monad m, FormError input err) => FormState m input FormId -> (input -> Either err a) -> (FormId -> Maybe a -> view)@@ -82,7 +82,7 @@ , unProved = x } )- Nothing -> pure $ Error [(unitRange i, commonFormError MissingDefaultValue)]+ Nothing -> pure $ Error [(unitRange i, commonFormError (MissingDefaultValue :: CommonFormError input) :: err)] ) Found x -> case fromInput x of Right a -> pure@@ -101,13 +101,13 @@ ) Missing -> pure ( View $ const $ toView i initialValue- , pure $ Error [(unitRange i, commonFormError (InputMissing i))]+ , pure $ Error [(unitRange i, commonFormError (InputMissing i :: CommonFormError input) :: err)] ) -- | used for elements like @\<input type=\"submit\"\>@ which are not always present in the form submission data. inputMaybe- :: (Monad m, FormError err input)+ :: (Monad m, FormError input err) => FormState m input FormId -> (input -> Either err a) -> (FormId -> Maybe a -> view)@@ -176,7 +176,7 @@ -- | used for @\<input type=\"file\"\>@ inputFile- :: forall m input err view. (Monad m, FormInput input, FormError err input)+ :: forall m input err view. (Monad m, FormInput input, FormError input err) => FormState m input FormId -> (FormId -> view) -> Form m input err view (FileType input)@@ -188,7 +188,7 @@ Default -> pure ( View $ const $ toView i- , pure $ Error [(unitRange i, commonFormError (InputMissing i))]+ , pure $ Error [(unitRange i, commonFormError (InputMissing i :: CommonFormError input) :: err)] ) Found x -> case getInputFile' x of Right a -> pure@@ -208,16 +208,16 @@ Missing -> pure ( View $ const $ toView i- , pure $ Error [(unitRange i, commonFormError (InputMissing i))]+ , pure $ Error [(unitRange i, commonFormError (InputMissing i :: CommonFormError input) ::err)] ) where -- just here for the type-signature to make the type-checker happy- getInputFile' :: (FormError err input) => input -> Either err (FileType input)+ getInputFile' :: (FormError input err) => input -> Either err (FileType input) getInputFile' = getInputFile -- | used for groups of checkboxes, @\<select multiple=\"multiple\"\>@ boxes inputMulti- :: forall m input err view a lbl. (FormError err input, FormInput input, Monad m)+ :: forall m input err view a lbl. (FormError input err, FormInput input, Monad m) => FormState m input FormId -> [(a, lbl)] -- ^ value, label, initially checked -> (FormId -> [(FormId, Int, lbl, Bool)] -> view) -- ^ function which generates the view@@ -274,7 +274,7 @@ -- | radio buttons, single @\<select\>@ boxes inputChoice- :: forall a m err input lbl view. (FormError err input, FormInput input, Monad m)+ :: forall a m err input lbl view. (FormError input err, FormInput input, Monad m) => FormState m input FormId -> (a -> Bool) -- ^ is default -> [(a, lbl)] -- ^ value, label@@ -318,7 +318,7 @@ Nothing -> pure ( View $ const view'- , pure $ Error [(unitRange i, commonFormError (InputMissing i))]+ , pure $ Error [(unitRange i, commonFormError (InputMissing i :: CommonFormError input) :: err)] ) (Just val) -> mkOk i view' val where@@ -326,7 +326,7 @@ mkOk' i view' Nothing = pure ( View $ const $ view'- , pure $ Error [(unitRange i, commonFormError MissingDefaultValue)]+ , pure $ Error [(unitRange i, commonFormError (MissingDefaultValue :: CommonFormError input) :: err)] ) markSelected :: [(a, lbl)] -> ([(a, lbl, Bool)], Maybe a) markSelected cs =@@ -349,7 +349,7 @@ -- | radio buttons, single @\<select\>@ boxes inputChoiceForms- :: forall a m err input lbl view. (Monad m, FormError err input, FormInput input)+ :: forall a m err input lbl view. (Monad m, FormError input err, FormInput input) => FormState m input FormId -> a -> [(Form m input err view a, lbl)] -- ^ value, label@@ -397,7 +397,7 @@ (v0, _) <- unForm frm pure ((fid, val, iview, unView v0 [], lbl, selected) : views, res) )- ([], pure $ Error [(unitRange i, commonFormError (InputMissing i))])+ ([], pure $ Error [(unitRange i, commonFormError (InputMissing i :: CommonFormError input) :: err)]) (choices') let view' = mkView i (reverse choices'') pure (View (const view'), mres)
src/Ditto/Generalized/Named.hs view
@@ -12,13 +12,13 @@ import qualified Ditto.Generalized.Internal as G -- | used for constructing elements like @\<input type=\"text\"\>@, which pure a single input value.-input :: (Monad m, FormError err input) => String -> (input -> Either err a) -> (FormId -> a -> view) -> a -> Form m input err view a+input :: (Monad m, FormError input err) => String -> (input -> Either err a) -> (FormId -> a -> view) -> a -> Form m input err view a input name = G.input (getNamedFormId name) -- | used to construct elements with optional initial values, which are still required inputMaybeReq- :: (Monad m, FormError err input)+ :: (Monad m, FormError input err) => String -> (input -> Either err a) -> (FormId -> Maybe a -> view)@@ -28,7 +28,7 @@ -- | used for elements like @\<input type=\"submit\"\>@ which are not always present in the form submission data. inputMaybe- :: (Monad m, FormError err input)+ :: (Monad m, FormError input err) => String -> (input -> Either err a) -> (FormId -> Maybe a -> view)@@ -46,7 +46,7 @@ -- | used for @\<input type=\"file\"\>@ inputFile- :: forall m input err view. (Monad m, FormInput input, FormError err input)+ :: forall m input err view. (Monad m, FormInput input, FormError input err) => String -> (FormId -> view) -> Form m input err view (FileType input)@@ -54,7 +54,7 @@ -- | used for groups of checkboxes, @\<select multiple=\"multiple\"\>@ boxes inputMulti- :: forall m input err view a lbl. (FormError err input, FormInput input, Monad m)+ :: forall m input err view a lbl. (FormError input err, FormInput input, Monad m) => String -> [(a, lbl)] -- ^ value, label, initially checked -> (FormId -> [(FormId, Int, lbl, Bool)] -> view) -- ^ function which generates the view@@ -64,7 +64,7 @@ -- | radio buttons, single @\<select\>@ boxes inputChoice- :: forall a m err input lbl view. (FormError err input, FormInput input, Monad m)+ :: forall a m err input lbl view. (FormError input err, FormInput input, Monad m) => String -> (a -> Bool) -- ^ is default -> [(a, lbl)] -- ^ value, label@@ -74,7 +74,7 @@ -- | radio buttons, single @\<select\>@ boxes inputChoiceForms- :: forall a m err input lbl view. (Monad m, FormError err input, FormInput input)+ :: forall a m err input lbl view. (Monad m, FormError input err, FormInput input) => String -> a -> [(Form m input err view a, lbl)] -- ^ value, label