git.iko.soy/typeable/dom-parser
on master help sign in
Upd: pre-release fixups
9636ea0Aleksey Uimanov
CHANGELOG.md+6
@@ -1,4 +1,10 @@
1# CHANGELOG
1# CHANGELOG
2
2
3+## 1.0.0
4+* Added support for parsing attributes
5+* Changed public interface for 'parseContent'
6+* Added usefull functions
7+* Dropped unnecessary dependency from shakespeare
8+
3## 0.1.0
9## 0.1.0
4* Public release
10* Public release
dom-parser.cabal+8
@@ -10,6 +10,14 @@ build-type: Simple
10extra-source-files: CHANGELOG.md
10extra-source-files: CHANGELOG.md
11cabal-version: >=1.10
11cabal-version: >=1.10
12
12
13+extra-source-files: CHANGELOG.md
14+
15+homepage: https://github.com/typeable/dom-parser
16+
17+source-repository head
18+ type: git
19+ location: git@github.com:typeable/dom-parser.git
20+
13library
21library
14 hs-source-dirs: src
22 hs-source-dirs: src
15 default-language: Haskell2010
23 default-language: Haskell2010
src/Text/XML/DOM/Parser/Class.hs+4
@@ -105,6 +105,9 @@ stringFromDom = parseContent $ Right . T.unpack
105charFromDom :: (Monad m) => DomParserT Identity m Char
105charFromDom :: (Monad m) => DomParserT Identity m Char
106charFromDom = parseContent readChar
106charFromDom = parseContent readChar
107
107
108+-- | Expects text to be single character
109+--
110+-- @since 1.0.0
108readChar :: Text -> Either Text Char
111readChar :: Text -> Either Text Char
109readChar t = case T.unpack $ T.strip t of
112readChar t = case T.unpack $ T.strip t of
110 [c] -> Right c
113 [c] -> Right c
@@ -130,6 +133,7 @@ fixedFromDom = parseContent readContent
130boolFromDom :: (Monad m) => DomParserT Identity m Bool
133boolFromDom :: (Monad m) => DomParserT Identity m Bool
131boolFromDom = parseContent readBool
134boolFromDom = parseContent readBool
132
135
136+-- | @since 1.0.0
133readBool :: Text -> Either Text Bool
137readBool :: Text -> Either Text Bool
134readBool t =
138readBool t =
135 let
139 let
src/Text/XML/DOM/Parser/Combinators.hs+16
@@ -207,6 +207,8 @@ ignoreBlank = ignoreElem test
207 | otherwise -> False
207 | otherwise -> False
208
208
209-- | Returns name of current element.
209-- | Returns name of current element.
210+--
211+-- @since 1.0.0
210getCurrentName :: (Monad m) => DomParserT Identity m Text
212getCurrentName :: (Monad m) => DomParserT Identity m Text
211getCurrentName = view $ pdElements . to runIdentity . localName
213getCurrentName = view $ pdElements . to runIdentity . localName
212
214
@@ -227,6 +229,8 @@ checkCurrentName n = do
227
229
228-- | Get current content. If current element contains no content or
230-- | Get current content. If current element contains no content or
229-- have inner elements then Nothing returned
231-- have inner elements then Nothing returned
232+--
233+-- @since 1.0.0
230getCurrentContent :: (Monad m) => DomParserT Identity m (Maybe Text)
234getCurrentContent :: (Monad m) => DomParserT Identity m (Maybe Text)
231getCurrentContent = do
235getCurrentContent = do
232 nds <- view $ pdElements . to runIdentity . nodes
236 nds <- view $ pdElements . to runIdentity . nodes
@@ -254,6 +258,10 @@ parseContent parse = getCurrentContent >>= \case
254 Left e -> throwParserError $ PEWrongFormat e
258 Left e -> throwParserError $ PEWrongFormat e
255 Right a -> return a
259 Right a -> return a
256
260
261+-- | If reader returns 'Nothing' then resulting function returns 'Left
262+-- "error message"'
263+--
264+-- @since 1.0.0
257maybeReadContent
265maybeReadContent
258 :: forall a
266 :: forall a
259 . (Typeable a)
267 . (Typeable a)
@@ -275,9 +283,15 @@ readContent
275 -> Either Text a
283 -> Either Text a
276readContent = maybeReadContent $ readMaybe . T.unpack . T.strip
284readContent = maybeReadContent $ readMaybe . T.unpack . T.strip
277
285
286+-- | Retuns map of attributes of current element
287+--
288+-- @since 1.0.0
278getCurrentAttributes :: (Monad m) => DomParserT Identity m (M.Map Name Text)
289getCurrentAttributes :: (Monad m) => DomParserT Identity m (M.Map Name Text)
279getCurrentAttributes = view $ pdElements . to runIdentity . attrs
290getCurrentAttributes = view $ pdElements . to runIdentity . attrs
280
291
292+-- | Returns element with given name or 'Nothing'
293+--
294+-- @since 1.0.0
281getCurrentAttribute :: (Monad m) => Text -> DomParserT Identity m (Maybe Text)
295getCurrentAttribute :: (Monad m) => Text -> DomParserT Identity m (Maybe Text)
282getCurrentAttribute attrName'
296getCurrentAttribute attrName'
283 = preview $ pdElements . to runIdentity . attr attrName
297 = preview $ pdElements . to runIdentity . attr attrName
@@ -285,6 +299,8 @@ getCurrentAttribute attrName'
285 attrName = Name attrName' Nothing Nothing
299 attrName = Name attrName' Nothing Nothing
286
300
287-- | Parses attribute with given name, throws error if attribute is not found.
301-- | Parses attribute with given name, throws error if attribute is not found.
302+--
303+-- @since 1.0.0
288parseAttribute
304parseAttribute
289 :: (Monad m)
305 :: (Monad m)
290 => Text
306 => Text