packages feed

yesod-pagination 0.3.0.0 → 0.3.1.0

raw patch · 3 files changed

+16/−3 lines, 3 files

Files

src/Yesod/Paginate.hs view
@@ -43,6 +43,7 @@ -- | 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)@@ -94,10 +95,12 @@      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+                wantPage $ Page [] Nothing 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+                wantPage $ Page [Entity k (Item "hello, world!")] Nothing Nothing Nothing              yit "with two pages" $ do                 clearOut pool@@ -79,6 +79,16 @@                 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.0.0+version:             0.3.1.0 synopsis:            Pagination in Yesod description:         Easy pagination for Yesod. homepage:            https://github.com/joelteon/yesod-pagination