digestive-functors 0.8.2.0 → 0.8.3.0
raw patch · 5 files changed
+52/−40 lines, 5 filesdep ~HUnitdep ~QuickCheckdep ~timePVP ok
version bump matches the API change (PVP)
Dependency ranges changed: HUnit, QuickCheck, time
API changes (from Hackage documentation)
Files
- CHANGELOG +6/−0
- digestive-functors.cabal +23/−14
- src/Text/Digestive/Form.hs +4/−8
- src/Text/Digestive/Form/Internal/Field.hs +16/−15
- tests/Text/Digestive/View/Tests.hs +3/−3
CHANGELOG view
@@ -1,3 +1,9 @@+- 0.8.3.0 (2017-12-26)+ * Fix input element values for choice forms+ * Bump `time` to 1.8+ * Bump `HUnit` to 1.6+ * Bump `QuickCheck` to 2.10+ - 0.8.2.0 * Update `QuickCheck` version bound * Updated CHoice type to allow for multiple choices
digestive-functors.cabal view
@@ -1,5 +1,5 @@ Name: digestive-functors-Version: 0.8.2.0+Version: 0.8.3.0 Synopsis: A practical formlet library Description:@@ -67,7 +67,7 @@ mtl >= 1.1.0.0 && < 3, old-locale >= 1.0 && < 1.1, text >= 0.10 && < 1.3,- time >= 1.4 && < 1.7+ time >= 1.4 && < 1.9 Extensions: CPP Test-suite digestive-functors-tests@@ -77,19 +77,28 @@ Ghc-options: -Wall Other-modules:- Text.Digestive.Field.Tests- Text.Digestive.Field.QTests- Text.Digestive.Form.Encoding.Tests- Text.Digestive.Form.Encoding.QTests- Text.Digestive.Form.List.QTests- Text.Digestive.Form.QTests- Text.Digestive.Tests.Fixtures- Text.Digestive.View.Tests- Text.Digestive.Types.QTests+ Text.Digestive.Field.QTests+ Text.Digestive.Field.Tests+ Text.Digestive.Form+ Text.Digestive.Form.Encoding+ Text.Digestive.Form.Encoding.QTests+ Text.Digestive.Form.Encoding.Tests+ Text.Digestive.Form.Internal+ Text.Digestive.Form.Internal.Field+ Text.Digestive.Form.List+ Text.Digestive.Form.List.QTests+ Text.Digestive.Form.QTests+ Text.Digestive.Ref+ Text.Digestive.Tests.Fixtures+ Text.Digestive.Types+ Text.Digestive.Types.QTests+ Text.Digestive.Util+ Text.Digestive.View+ Text.Digestive.View.Tests Build-depends:- HUnit >= 1.2 && < 1.6,- QuickCheck >= 2.5 && < 2.10,+ HUnit >= 1.2 && < 1.7,+ QuickCheck >= 2.5 && < 2.11, test-framework >= 0.4 && < 0.9, test-framework-hunit >= 0.3 && < 0.4, test-framework-quickcheck2 >= 0.3 && < 0.4,@@ -100,7 +109,7 @@ mtl >= 1.1.0.0 && < 3, old-locale >= 1.0 && < 1.1, text >= 0.10 && < 1.3,- time >= 1.4 && < 1.7+ time >= 1.4 && < 1.9 Source-repository head Type: git
src/Text/Digestive/Form.hs view
@@ -146,12 +146,10 @@ choiceWith' :: (Monad m, Monoid v) => [(Text, (a, v))] -> Maybe Int -> Form v m a choiceWith' [] _ = error "choice expects a list with at least one item in it"-choiceWith' items def = fromMaybe defaultItem . listToMaybe . map fst <$> (Pure $ Choice [("", items)] def')+choiceWith' items def = fromMaybe defaultItem . listToMaybe . map fst <$> (Pure $ Choice [("", items)] [def']) where- defaultItem = fst $ snd $ head items- def' = case def of- Just x -> [x]- Nothing -> [0]+ defaultItem = fst $ snd $ items !! def'+ def' = fromMaybe 0 def --------------------------------------------------------------------------------@@ -187,9 +185,7 @@ :: (Monad m, Monoid v) => [(Text, (a, v))] -> Maybe [Int] -> Form v m [a] choiceWithMultiple' items def = map fst <$> (Pure $ Choice [("", items)] def') where- def' = case def of- Just x -> x- Nothing -> []+ def' = fromMaybe [] def --------------------------------------------------------------------------------
src/Text/Digestive/Form/Internal/Field.hs view
@@ -15,6 +15,8 @@ -------------------------------------------------------------------------------- import Control.Arrow (second) import Data.Maybe (listToMaybe, mapMaybe, catMaybes)+import Data.Functor ((<$>))+import Data.List (findIndex) import Data.Text (Text) @@ -62,12 +64,8 @@ evalField _ ts@(TextInput _ : _) (Choice ls _) = let ls' = concat (map snd ls) in catMaybes $- map (\(TextInput x) -> do- -- Expects input in the form of "foo.bar.2". This is not needed for- -- <select> fields, but we need it for labels for radio buttons.- t <- listToMaybe . reverse $ toPath x- (c, i) <- lookupIdx t ls'- return (fst c, i)) ts+ map (\(TextInput x) ->+ (\i -> (fst $ snd $ ls' !! i, i)) <$> findIndex (isSelectedChoice x . fst) ls') ts evalField Get _ (Choice ls x) = -- this populates the default values when displaying a view let ls' = concat (map snd ls) in@@ -95,12 +93,15 @@ ----------------------------------------------------------------------------------- | Retrieve the value and position of the value referenced to by the given--- key in an association list, if the key is in the list.-lookupIdx :: Eq k => k -> [(k, v)] -> Maybe (v, Int)-lookupIdx key = go 0- where- go _ [] = Nothing- go !i ((k, v) : xs)- | key == k = Just (v, i)- | otherwise = go (i + 1) xs+-- | Determines if the choiceVal is equal to the selectedVal. Works with older+-- versions that submit "foo.bar.2" rather than "2" for Choice fields.+-- > isSelectedChoice "0" "0" == True+-- > isSelectedChoice "foo.bar.0" "0" == True+-- > isSelectedChoice "foo.bar.10" "0" == False+isSelectedChoice :: Text -> Text -> Bool+isSelectedChoice selectedVal choiceVal+ | selectedVal == choiceVal = True+ | otherwise =+ case listToMaybe (reverse $ toPath selectedVal) of+ Just x -> x == choiceVal+ _ -> False
tests/Text/Digestive/View/Tests.hs view
@@ -38,8 +38,8 @@ [ ("f.name", "charmander") , ("f.level", "5") , ("f.type", "type.1")- , ("f.weakness", "weakness.0")- , ("f.weakness", "weakness.3")+ , ("f.weakness", "0") -- NOTE: this is the newer style of Choice values+ , ("f.weakness", "3") ] , testCase "optional unspecified" $ (@=?)@@ -47,7 +47,7 @@ snd $ runTrainerM $ postForm "f" pokemonForm $ testEnv [ ("f.name", "magmar") , ("f.type", "type.1")- , ("f.weakness", "weakness.0")+ , ("f.weakness", "weakness.0") -- NOTE: this is the older style of Choice values , ("f.weakness", "weakness.3") ]