packages feed

xml-conduit-microlens 0.1.0.0 → 0.2.0.0

raw patch · 3 files changed

+26/−6 lines, 3 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

+ Text.XML.Lens.Micro: remapAttributes :: (Name -> Text -> Maybe (Name, Text)) -> Getting r Element Element

Files

CHANGELOG.md view
@@ -8,4 +8,8 @@  ## Unreleased -## 0.1.0.0 - YYYY-MM-DD+## 0.2.0.0 - 2023-04-16++Add `remapAttributes`++## 0.1.0.0 - 2023-04-16
src/Text/XML/Lens/Micro.hs view
@@ -4,7 +4,7 @@ {-# language OverloadedStrings #-} {-# language RecordWildCards #-} {-# language Rank2Types #-}--- {-# options_ghc -Wno-unused-imports #-}+{-# options_ghc -Wno-unused-imports #-} ----------------------------------------------------------------------------- -- | -- Module      :  Text.XML.Lens.Micro@@ -28,6 +28,7 @@   attributeSatisfies,   attributeIs,   withoutAttribute,+  remapAttributes,                            ) where  @@ -37,14 +38,14 @@ -- case-insensitive import qualified Data.CaseInsensitive as CI -- containers-import qualified Data.Map as M (Map, foldrWithKey)+import qualified Data.Map as M (Map, singleton, fromList, foldrWithKey) -- microlens-import Lens.Micro.GHC (to, Getting, Lens', Traversal', ix, filtered)+import Lens.Micro.GHC (to, Getting, Lens', (^.), Traversal', ix, filtered) import Lens.Micro.Extras (preview) -- text import Data.Text (Text) -- xml-conduit-import Text.XML (Document(..), Element(..), Name(..), Node(..), Miscellaneous(..))+import Text.XML (Prologue(..), Doctype(..), Document(..), Element(..), Name(..), Node(..), Miscellaneous(..))   @@ -120,7 +121,22 @@       _ -> Nothing  +-- | Handy for editing HREF targets etc.+remapAttributes :: (Name -> Text -> Maybe (Name, Text)) -- ^ operate on element attribute (name, value)+                -> Getting r Element Element+remapAttributes f = to (_remapAttributes f) +_remapAttributes :: (Name -> Text -> Maybe (Name, Text))+               -> Element -> Element+_remapAttributes p el@(Element _ ats _) =+  el{ elementAttributes = M.foldrWithKey (\k v acc -> case p k v of+                                             Nothing -> M.singleton k v <> acc+                                             Just (k', v') -> M.singleton k' v' <> acc+                                         ) mempty ats,+      elementNodes = map (\nn -> case nn of+                             NodeElement e -> NodeElement (_remapAttributes p e)+                             x -> x+                         ) $ elementNodes el }   
xml-conduit-microlens.cabal view
@@ -1,5 +1,5 @@ name:                xml-conduit-microlens-version:             0.1.0.0+version:             0.2.0.0 synopsis:            Lenses and traversals for xml-conduit based on microlens description:         This package provides DOM selectors based on lenses, using microlens instead of lens for a smaller dependency footprint homepage:            https://github.com/ocramz/xml-conduit-microlens