yesod-pagination 0.3.1.0 → 0.4.0.0
raw patch · 3 files changed
+4/−16 lines, 3 filesdep +shakespeare
Dependencies added: shakespeare
Files
- src/Yesod/Paginate.hs +0/−3
- tests/main.hs +2/−12
- yesod-pagination.cabal +2/−1
src/Yesod/Paginate.hs view
@@ -43,7 +43,6 @@ -- | Returned by 'paginate' and friends. data Page r = Page { pageResults :: [r] -- ^ Returned entities.- , firstPage :: Maybe Text -- ^ Link to first page. Will be 'Nothing' on page 1 or page 2, @'Just' link@ otherwise. , nextPage :: Maybe Text -- ^ Link to next page, pre-rendered. , previousPage :: Maybe Text -- ^ Link to previous page, pre-rendered. } deriving (Eq, Read, Show)@@ -95,12 +94,10 @@ let rt = fromMaybe (error "Attempting to use paginate on a server error page.") rt' qs = snd $ renderRoute rt- fp = rend rt $ updateQs qs ("page", "1") np = rend rt $ updateQs qs ("page", [st|#{cp + 1}|]) pp = rend rt $ updateQs qs ("page", [st|#{cp - 1}|]) return Page { pageResults = take (fromIntegral $ pageSize c) es- , firstPage = if cp >= 2 then Just fp else Nothing , nextPage = if fromIntegral (length es) == pageSize c + 1 then Just np else Nothing
tests/main.hs view
@@ -57,14 +57,14 @@ clearOut pool get ItemsR- wantPage $ Page [] Nothing Nothing Nothing+ wantPage $ Page [] Nothing Nothing yit "with some items" $ do clearOut pool k <- liftIO $ runSqlPersistMPool (insert $ Item "hello, world!") pool get ItemsR- wantPage $ Page [Entity k (Item "hello, world!")] Nothing Nothing Nothing+ wantPage $ Page [Entity k (Item "hello, world!")] Nothing Nothing yit "with two pages" $ do clearOut pool@@ -79,16 +79,6 @@ cp' <- getPage liftIO $ length (pageResults cp') `shouldBe` 8 liftIO $ nextPage cp' `shouldBe` Nothing-- yit "with three pages" $ do- clearOut pool- liftIO $ runSqlPersistMPool (replicateM_ 28 $ insert $ Item "hello, world!") pool-- get ItemsR- get . fromJust . nextPage =<< getPage- get . fromJust . nextPage =<< getPage- p <- getPage- liftIO $ firstPage p `shouldBe` Just "/items?page=1" yit "caps at the maximum page" $ do clearOut pool
yesod-pagination.cabal view
@@ -1,5 +1,5 @@ name: yesod-pagination-version: 0.3.1.0+version: 0.4.0.0 synopsis: Pagination in Yesod description: Easy pagination for Yesod. homepage: https://github.com/joelteon/yesod-pagination@@ -16,6 +16,7 @@ build-depends: base >= 4.4 && < 4.7 , data-default , esqueleto+ , shakespeare , shakespeare-text , text , yesod