yaml 0.8.23.3 → 0.8.24
raw patch · 4 files changed
+35/−12 lines, 4 files
Files
- ChangeLog.md +4/−0
- Data/Yaml/Pretty.hs +29/−10
- libyaml/yaml.h +1/−1
- yaml.cabal +1/−1
ChangeLog.md view
@@ -1,3 +1,7 @@+## 0.8.24++* New encodePretty option `setConfDropNull` to drop null values from objects [#116](https://github.com/snoyberg/yaml/issues/116)+ ## 0.8.23.3 * Avoid over-escaping `*` [#113](https://github.com/snoyberg/yaml/issues/113)
Data/Yaml/Pretty.hs view
@@ -1,12 +1,14 @@ {-# LANGUAGE CPP #-} -- | Prettier YAML encoding. ----- Since 0.8.13+-- @since 0.8.13 module Data.Yaml.Pretty ( encodePretty , Config , getConfCompare , setConfCompare+ , getConfDropNull+ , setConfDropNull , defConfig ) where @@ -29,30 +31,47 @@ import Data.Yaml.Builder -- |--- Since 0.8.13+-- @since 0.8.13 data Config = Config { confCompare :: Text -> Text -> Ordering -- ^ Function used to sort keys in objects+ , confDropNull :: Bool } --- | The default configuration: do not sort objects.+-- | The default configuration: do not sort objects or drop keys ----- Since 0.8.13+-- @since 0.8.13 defConfig :: Config-defConfig = Config mempty+defConfig = Config mempty False -- |--- Since 0.8.13+-- @since 0.8.13 getConfCompare :: Config -> Text -> Text -> Ordering getConfCompare = confCompare --- |--- Since 0.8.13+-- | Sets ordering for object keys+--+-- @since 0.8.13 setConfCompare :: (Text -> Text -> Ordering) -> Config -> Config setConfCompare cmp c = c { confCompare = cmp } +-- |+-- @since 0.8.24+getConfDropNull :: Config -> Bool+getConfDropNull = confDropNull++-- | Drop entries with `Null` value from objects, if set to `True`+--+-- @since 0.8.24+setConfDropNull :: Bool -> Config -> Config+setConfDropNull m c = c { confDropNull = m }+ pretty :: Config -> Value -> YamlBuilder pretty cfg = go- where go (Object o) = mapping (sortBy (confCompare cfg `on` fst) $ HM.toList $ HM.map go o)+ where go (Object o) = let sort = sortBy (confCompare cfg `on` fst)+ select+ | confDropNull cfg = HM.filter (/= Null)+ | otherwise = id+ in mapping (sort $ HM.toList $ HM.map go $ select o) go (Array a) = array (go <$> V.toList a) go Null = null go (String s) = string s@@ -61,6 +80,6 @@ -- | Configurable 'encode'. ----- Since 0.8.13+-- @since 0.8.13 encodePretty :: ToJSON a => Config -> a -> ByteString encodePretty cfg = toByteString . pretty cfg . toJSON
libyaml/yaml.h view
@@ -1091,7 +1091,7 @@ yaml_error_type_t error; /** Error description. */ const char *problem;- /** The byte about which the problem occured. */+ /** The byte about which the problem occurred. */ size_t problem_offset; /** The problematic value (@c -1 is none). */ int problem_value;
yaml.cabal view
@@ -1,5 +1,5 @@ name: yaml-version: 0.8.23.3+version: 0.8.24 license: BSD3 license-file: LICENSE author: Michael Snoyman <michael@snoyman.com>, Anton Ageev <antage@gmail.com>,Kirill Simonov