on master help sign in
Add BlazeHtml integration
commitbe685e6fcdbdb8d1bf49a09212413922a2e1ea82 authorJasper Van der Jeugt <jaspervdj@gmail.com> dateFri 4 Mar 2011, 11:46 (16 years ago) parent40f503e
4 files changed+47−2
hakyll.cabal+1 src/Hakyll.hs+2 src/Hakyll/Core/Writable.hs+10−2 src/Hakyll/Web/Blaze.hs+34
hakyll.cabal+1
@@ -65,6 +65,7 @@ library
6565 strict-concurrency >= 0.2
6666 exposed-modules: Hakyll
6767 Hakyll.Main
68+ Hakyll.Web.Blaze
6869 Hakyll.Web.Util.Url
6970 Hakyll.Web.Preview.Server
7071 Hakyll.Web.Preview.Poll
src/Hakyll.hs+2
@@ -16,6 +16,7 @@ module Hakyll
1616 , module Hakyll.Core.Writable.CopyFile
1717 , module Hakyll.Core.Writable.WritableTuple
1818 , module Hakyll.Main
19+ , module Hakyll.Web.Blaze
1920 , module Hakyll.Web.CompressCss
2021 , module Hakyll.Web.Feed
2122 , module Hakyll.Web.FileType
@@ -44,6 +45,7 @@ import Hakyll.Core.Writable
4445import Hakyll.Core.Writable.CopyFile
4546import Hakyll.Core.Writable.WritableTuple
4647import Hakyll.Main
48+import Hakyll.Web.Blaze
4749import Hakyll.Web.CompressCss
4850import Hakyll.Web.Feed
4951import Hakyll.Web.FileType
src/Hakyll/Core/Writable.hs+10−2
@@ -1,6 +1,6 @@
11-- | Describes writable items; items that can be saved to the disk
22--
3−{-# LANGUAGE FlexibleInstances #-}
3+{-# LANGUAGE FlexibleInstances, TypeSynonymInstances #-}
44module Hakyll.Core.Writable
55 ( Writable (..)
66 ) where
@@ -8,6 +8,8 @@ module Hakyll.Core.Writable
88import Data.Word (Word8)
99
1010import qualified Data.ByteString as SB
11+import Text.Blaze (Html)
12+import Text.Blaze.Renderer.String (renderHtml)
1113
1214-- | Describes an item that can be saved to the disk
1315--
@@ -18,5 +20,11 @@ class Writable a where
1820instance Writable [Char] where
1921 write = writeFile
2022
23+instance Writable SB.ByteString where
24+ write p = SB.writeFile p
25+
2126instance Writable [Word8] where
22− write p = SB.writeFile p . SB.pack
27+ write p = write p . SB.pack
28+
29+instance Writable Html where
30+ write p html = write p $ renderHtml html
src/Hakyll/Web/Blaze.hsnew file+34
@@ -0,0 +1,34 @@
1+-- | Module providing BlazeHtml support for hakyll
2+--
3+module Hakyll.Web.Blaze
4+ ( getFieldHtml
5+ , getFieldHtml'
6+ , getBodyHtml
7+ , getBodyHtml'
8+ ) where
9+
10+import Text.Blaze (Html, toHtml, preEscapedString)
11+
12+import Hakyll.Web.Page
13+import Hakyll.Web.Page.Metadata
14+
15+-- | Get a field from a page and convert it to HTML. This version does escape
16+-- the given HTML
17+--
18+getFieldHtml :: String -> Page a -> Html
19+getFieldHtml key = preEscapedString . getField key
20+
21+-- | Version of 'getFieldHtml' that escapes the HTML content
22+--
23+getFieldHtml' :: String -> Page a -> Html
24+getFieldHtml' key = toHtml . getField key
25+
26+-- | Get the body as HTML
27+--
28+getBodyHtml :: Page String -> Html
29+getBodyHtml = preEscapedString . pageBody
30+
31+-- | Version of 'getBodyHtml' that escapes the HTML content
32+--
33+getBodyHtml' :: Page String -> Html
34+getBodyHtml' = toHtml . pageBody