@@ -1,23 +1,15 @@
11-- | A module for dealing with @Page@s. This module is mostly internally used.
22module Text.Hakyll.Internal.Page
3− ( Page
4− , fromContext
5− , getValue
6− , getBody
7− , readPage
3+ ( readPage
84 ) where
95
106import qualified Data.Map as M
117import Data.List (isPrefixOf)
128import Data.Char (isSpace)
13−import Data.Maybe (fromMaybe)
14−import Control.Monad (liftM, replicateM)
159import Control.Monad.Reader (liftIO)
1610import System.FilePath
1711
18−import Test.QuickCheck
1912import Text.Pandoc
20−import Data.Binary
2113
2214import Text.Hakyll.Context (Context)
2315import Text.Hakyll.File
@@ -26,25 +18,6 @@ import Text.Hakyll.Regex (substituteRegex, matchesRegex)
2618import Text.Hakyll.Util (trim)
2719import Text.Hakyll.Internal.Cache
2820
29−-- | A Page is basically key-value mapping. Certain keys have special
30−-- meanings, like for example url, body and title.
31−data Page = Page Context
32− deriving (Ord, Eq, Show, Read)
33−
34−-- | Create a Page from a key-value mapping.
35−fromContext :: Context -> Page
36−fromContext = Page
37−
38−-- | Obtain a value from a page. Will resturn an empty string when nothing is
39−-- found.
40−getValue :: String -> Page -> String
41−getValue str (Page page) = fromMaybe [] $ M.lookup str page
42−
43−-- | Get the body for a certain page. When not defined, the body will be
44−-- empty.
45−getBody :: Page -> String
46−getBody (Page page) = fromMaybe [] $ M.lookup "body" page
47−
4821-- | The default reader options for pandoc parsing.
4922readerOptions :: ParserState
5023readerOptions = defaultParserState
@@ -143,22 +116,3 @@ readPage path = do
143116 return page
144117 where
145118 fileName = "pages" </> path
146−
147−-- Make pages serializable.
148−instance Binary Page where
149− put (Page context) = put $ M.toAscList context
150− get = liftM (Page . M.fromAscList) get
151−
152−-- | Generate an arbitrary page.
153−arbitraryPage :: Gen Page
154−arbitraryPage = do keys <- listOf key'
155− values <- arbitrary
156− return $ Page $ M.fromList $ zip keys values
157− where
158− key' = do l <- choose (5, 10)
159− replicateM l $ choose ('a', 'z')
160−
161−-- Make pages testable
162−instance Arbitrary Page where
163− arbitrary = arbitraryPage
164− shrink (Page context) = map (Page . flip M.delete context) $ M.keys context