Merge pull request #5 from Dretch/toArray
Feature request: toArray function
This commit is contained in:
commit
e02796e6a4
@ -13,9 +13,13 @@ module Cheerio (
|
|||||||
parent,
|
parent,
|
||||||
prev,
|
prev,
|
||||||
siblings,
|
siblings,
|
||||||
text
|
text,
|
||||||
|
toArray
|
||||||
) where
|
) where
|
||||||
|
|
||||||
|
import Prelude
|
||||||
|
|
||||||
|
import Data.Array ((..))
|
||||||
import Data.Function.Uncurried (Fn2, Fn3, Fn4, runFn2, runFn3, runFn4)
|
import Data.Function.Uncurried (Fn2, Fn3, Fn4, runFn2, runFn3, runFn4)
|
||||||
import Data.Maybe (Maybe(..))
|
import Data.Maybe (Maybe(..))
|
||||||
|
|
||||||
@ -67,4 +71,12 @@ html = runFn3 htmlImpl Nothing Just
|
|||||||
foreign import text :: Cheerio -> String
|
foreign import text :: Cheerio -> String
|
||||||
|
|
||||||
-- Miscellaneous
|
-- Miscellaneous
|
||||||
|
|
||||||
|
-- | Get how many elements there are in the given Cheerio
|
||||||
foreign import length :: Cheerio -> Int
|
foreign import length :: Cheerio -> Int
|
||||||
|
|
||||||
|
-- | Seperate each element out into its own Cheerio
|
||||||
|
toArray :: Cheerio -> Array Cheerio
|
||||||
|
toArray c
|
||||||
|
| length c == 0 = []
|
||||||
|
| otherwise = map (\i -> eq i c) (0 .. (length c - 1))
|
||||||
|
@ -24,6 +24,7 @@ import Cheerio
|
|||||||
, prev
|
, prev
|
||||||
, siblings
|
, siblings
|
||||||
, text
|
, text
|
||||||
|
, toArray
|
||||||
)
|
)
|
||||||
|
|
||||||
import Cheerio.Static (loadRoot)
|
import Cheerio.Static (loadRoot)
|
||||||
@ -138,6 +139,25 @@ suites = do
|
|||||||
""
|
""
|
||||||
(emptyCheerio # text)
|
(emptyCheerio # text)
|
||||||
|
|
||||||
|
suite "Miscellaneous" do
|
||||||
|
test "length" do
|
||||||
|
Assert.equal
|
||||||
|
0
|
||||||
|
(emptyCheerio # length)
|
||||||
|
|
||||||
|
Assert.equal
|
||||||
|
3
|
||||||
|
(loadRoot htmlEx # find "li" # length)
|
||||||
|
|
||||||
|
test "toArray" do
|
||||||
|
Assert.equal
|
||||||
|
[]
|
||||||
|
(emptyCheerio # toArray # map (attr "class"))
|
||||||
|
|
||||||
|
Assert.equal
|
||||||
|
(map Just ["apple", "orange", "pear"])
|
||||||
|
(loadRoot htmlEx # find "li" # toArray # map (attr "class"))
|
||||||
|
|
||||||
suite "More" do
|
suite "More" do
|
||||||
test "Long chain" do
|
test "Long chain" do
|
||||||
Assert.equal
|
Assert.equal
|
||||||
|
Loading…
Reference in New Issue
Block a user