packages feed

xml-lens 0.1.1 → 0.1.2

raw patch · 2 files changed

+39/−13 lines, 2 files

Files

Text/XML/Lens.hs view
@@ -1,4 +1,4 @@-{-# LANGUAGE Rank2Types #-}+{-# LANGUAGE Rank2Types, FlexibleContexts #-} ----------------------------------------------------------------------------- -- | -- Module      :  Text.XML.Lens@@ -8,22 +8,26 @@ -- Maintainer  :  Fumiaki Kinoshita <fumiexcel@gmail.com> -- Stability   :  experimental -- Portability :  non-portable---+-- Useful traversals inspired by XPath ---------------------------------------------------------------------------- module Text.XML.Lens (-    -- * Useful traversals inspired by XPath+    -- * Lenses, traversals for 'Element'     (./)+    -- ** Names+    , name     , el+    -- ** Attributes     , attributeIs     , attributeSatisfies+    , attr+    , attribute+    , attrs+    -- ** Contents     , text     , comment-    -- * Lenses, traversals for 'Element'-    , name-    , attrs+    -- ** Children+    , entire     , nodes-    , attr-    , attribute     -- * Prisms for 'Node'     , _Element     , _Content@@ -38,6 +42,9 @@     , _nameLocalName     , _nameNamespace     , _namePrefix+    -- * Lenses for 'Instruction'+    , _instructionTarget+    , _instructionData     ) where import Text.XML import Control.Lens@@ -50,6 +57,7 @@ prologue :: Lens' Document Prologue prologue f doc = fmap (\p -> doc { documentPrologue = p} ) $ f $ documentPrologue doc +-- | The root element of the document. root :: Lens' Document Element root f doc = fmap (\p -> doc { documentRoot = p} ) $ f $ documentRoot doc @@ -62,6 +70,12 @@ class AsInstruction t where     _Instruction :: Prism' t Instruction +_instructionTarget :: Lens' Instruction Text+_instructionTarget f (Instruction t d) = f t <&> \t' -> Instruction t' d++_instructionData :: Lens' Instruction Text+_instructionData f (Instruction t d) = f d <&> \d' -> Instruction t d'+ instance AsInstruction Node where     _Instruction = prism' NodeInstruction $ \s -> case s of         NodeInstruction e -> Just e@@ -113,12 +127,18 @@ nodes :: Lens' Element [Node] nodes f e = fmap (\x -> e { elementNodes = x }) $ f $ elementNodes e -attr :: Name -> Traversal' Element Text+attr :: Name -> IndexedTraversal' Name Element Text attr n = attrs . ix n -attribute :: Name -> Lens' Element (Maybe Text)+attribute :: Name -> IndexedLens' Name Element (Maybe Text) attribute n = attrs . at n +-- | Traverse itself with its all children.+entire :: Traversal' Element Element+entire f e@(Element _ _ ns) = com <$> f e <*> traverse (_Element (entire f)) ns where+    com (Element n a _) ns = Element n a ns++-- | Traverse elements which has the specified name. el :: Name -> Traversal' Element Element el n f s     | elementName s == n = f s@@ -130,14 +150,21 @@ attributeIs :: Name -> Text -> Traversal' Element Element attributeIs n v = attributeSatisfies n (==v) +-- | Traverse all contents of the element. text :: Traversal' Element Text text = nodes . traverse . _Content +-- | Traverse all comments of the element. comment :: Traversal' Element Text comment = nodes . traverse . _Comment  instance Plated Element where     plate = nodes . traverse . _Element +-- | Combine two 'Traversal's just like XPath's slash.+-- +-- @ +-- l ./ m ≡ l . 'plate' . m+-- @ (./) :: Plated a => Traversal s t a a -> Traversal a a u v -> Traversal s t u v l ./ m = l . plate . m
xml-lens.cabal view
@@ -1,7 +1,7 @@ name:                xml-lens-version:             0.1.1+version:             0.1.2 synopsis:            Lenses, traversals, prisms for xml-conduit-description:         +description:         Lens-based DOM selector homepage:            https://github.com/fumieval/xml-lens license:             BSD3 license-file:        LICENSE@@ -20,5 +20,4 @@   default-language:   Haskell2010   ghc-options: -Wall   exposed-modules:     Text.XML.Lens-  -- other-modules:          build-depends:       base ==4.*, lens >= 3.8 && < 4.2, containers >= 0.4.0 && < 0.6, text == 0.11.*, xml-conduit >= 1.1