aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Text
diff options
context:
space:
mode:
authorJohannes Gerer <oss@johannesgerer.com>2016-10-26 03:39:23 +0200
committerJohannes Gerer <oss@johannesgerer.com>2016-10-26 03:39:23 +0200
commit86d89e47d648770ae36dba01f7ae09d34f2ee171 (patch)
tree504457544a461b341bf5a8c9f56368b5e2cba554 /src/Text
parent675085c2e0b0b851378da08b7d73024766107c87 (diff)
downloadblazeT-86d89e47d648770ae36dba01f7ae09d34f2ee171.tar.gz
blazeT-86d89e47d648770ae36dba01f7ae09d34f2ee171.tar.zst
blazeT-86d89e47d648770ae36dba01f7ae09d34f2ee171.zip
a
Diffstat (limited to 'src/Text')
-rw-r--r--src/Text/BlazeT.hs2
-rw-r--r--src/Text/BlazeT/Internal.hs14
-rw-r--r--src/Text/BlazeT/Renderer/Pretty.hs10
-rw-r--r--src/Text/BlazeT/Renderer/String.hs8
-rw-r--r--src/Text/BlazeT/Renderer/Text.hs50
-rw-r--r--src/Text/BlazeT/Renderer/Utf8.hs34
6 files changed, 31 insertions, 87 deletions
diff --git a/src/Text/BlazeT.hs b/src/Text/BlazeT.hs
index 27228fa..b3e7c8d 100644
--- a/src/Text/BlazeT.hs
+++ b/src/Text/BlazeT.hs
@@ -62,6 +62,8 @@ module Text.BlazeT
62 ,runMarkupT 62 ,runMarkupT
63 ,execMarkup 63 ,execMarkup
64 ,execMarkupT 64 ,execMarkupT
65 ,runWith
66 ,execWith
65 ) where 67 ) where
66 68
67import qualified Text.Blaze as B 69import qualified Text.Blaze as B
diff --git a/src/Text/BlazeT/Internal.hs b/src/Text/BlazeT/Internal.hs
index 24ef1fe..f0c3edb 100644
--- a/src/Text/BlazeT/Internal.hs
+++ b/src/Text/BlazeT/Internal.hs
@@ -83,8 +83,11 @@ module Text.BlazeT.Internal
83 ,wrapMarkupT 83 ,wrapMarkupT
84 ,wrapMarkup2 84 ,wrapMarkup2
85 ,wrapMarkupT2 85 ,wrapMarkupT2
86 ,runWith
87 ,execWith
86 ) where 88 ) where
87 89
90import Control.Arrow
88import Control.Monad.Identity 91import Control.Monad.Identity
89import Control.Monad.Trans.Class 92import Control.Monad.Trans.Class
90import Control.Monad.Writer.Strict 93import Control.Monad.Writer.Strict
@@ -121,10 +124,21 @@ runMarkupT :: MarkupT m a -> m (a,B.Markup)
121runMarkupT = runWriterT . fromMarkupT 124runMarkupT = runWriterT . fromMarkupT
122{-# INLINE runMarkupT #-} 125{-# INLINE runMarkupT #-}
123 126
127-- | run the MarkupT and return a pair consisting of the result of the
128-- computation and the blaze markup rendered with a blaze renderer
129-- like 'Text.Blaze.Renderer.Text.renderHtml'
130runWith :: Monad m => (MarkupM () -> c) -> MarkupT m a -> m (a, c)
131runWith renderer = liftM (second $ renderer . wrapMarkup) . runMarkupT
132{-# INLINE runWith #-}
133
124execMarkupT :: Monad m => MarkupT m a -> m B.Markup 134execMarkupT :: Monad m => MarkupT m a -> m B.Markup
125execMarkupT = liftM snd . runMarkupT 135execMarkupT = liftM snd . runMarkupT
126{-# INLINE execMarkupT #-} 136{-# INLINE execMarkupT #-}
127 137
138execWith :: Monad m => (MarkupM () -> c) -> MarkupT m a -> m c
139execWith renderer = liftM snd . runWith renderer
140{-# INLINE execWith #-}
141
128runMarkup :: MarkupM a -> (a,B.Markup) 142runMarkup :: MarkupM a -> (a,B.Markup)
129runMarkup = runIdentity . runMarkupT 143runMarkup = runIdentity . runMarkupT
130{-# INLINE runMarkup #-} 144{-# INLINE runMarkup #-}
diff --git a/src/Text/BlazeT/Renderer/Pretty.hs b/src/Text/BlazeT/Renderer/Pretty.hs
index 8977c94..fa8cdad 100644
--- a/src/Text/BlazeT/Renderer/Pretty.hs
+++ b/src/Text/BlazeT/Renderer/Pretty.hs
@@ -1,22 +1,14 @@
1module Text.BlazeT.Renderer.Pretty 1module Text.BlazeT.Renderer.Pretty
2 ( renderMarkup 2 ( renderMarkup
3 , renderHtml 3 , renderHtml
4 , renderMarkupT
5 , renderHtmlT
6 ) where 4 ) where
7 5
8import Control.Monad
9import Control.Monad.Identity
10import qualified Text.Blaze.Renderer.Pretty as BU 6import qualified Text.Blaze.Renderer.Pretty as BU
11import Text.BlazeT 7import Text.BlazeT
12 8
13renderMarkup :: MarkupM a -> String 9renderMarkup :: MarkupM a -> String
14renderMarkup = runIdentity . renderMarkupT 10renderMarkup = BU.renderMarkup . execMarkup
15renderMarkupT :: Monad m => MarkupT m a -> m String
16renderMarkupT = liftM BU.renderMarkup . execMarkupT
17 11
18renderHtml :: MarkupM a -> String 12renderHtml :: MarkupM a -> String
19renderHtml = renderMarkup 13renderHtml = renderMarkup
20renderHtmlT :: Monad m => MarkupT m a -> m String
21renderHtmlT = renderMarkupT
22 14
diff --git a/src/Text/BlazeT/Renderer/String.hs b/src/Text/BlazeT/Renderer/String.hs
index 0a2de8a..9f0e0a0 100644
--- a/src/Text/BlazeT/Renderer/String.hs
+++ b/src/Text/BlazeT/Renderer/String.hs
@@ -2,8 +2,6 @@ module Text.BlazeT.Renderer.String
2 ( fromChoiceString 2 ( fromChoiceString
3 , renderMarkup 3 , renderMarkup
4 , renderHtml 4 , renderHtml
5 , renderMarkupT
6 , renderHtmlT
7 ) where 5 ) where
8 6
9import Control.Monad 7import Control.Monad
@@ -16,12 +14,8 @@ fromChoiceString :: ChoiceString -> String -> String
16fromChoiceString = BU.fromChoiceString 14fromChoiceString = BU.fromChoiceString
17 15
18renderMarkup :: MarkupM a -> String 16renderMarkup :: MarkupM a -> String
19renderMarkup = runIdentity . renderMarkupT 17renderMarkup = BU.renderMarkup . execMarkup
20renderMarkupT :: Monad m => MarkupT m a -> m String
21renderMarkupT = liftM BU.renderMarkup . execMarkupT
22 18
23renderHtml :: MarkupM a -> String 19renderHtml :: MarkupM a -> String
24renderHtml = renderMarkup 20renderHtml = renderMarkup
25renderHtmlT :: Monad m => MarkupT m a -> m String
26renderHtmlT = renderMarkupT
27 21
diff --git a/src/Text/BlazeT/Renderer/Text.hs b/src/Text/BlazeT/Renderer/Text.hs
index 31181eb..991c81c 100644
--- a/src/Text/BlazeT/Renderer/Text.hs
+++ b/src/Text/BlazeT/Renderer/Text.hs
@@ -1,13 +1,5 @@
1module Text.BlazeT.Renderer.Text 1module Text.BlazeT.Renderer.Text
2 ( renderMarkupBuilderT 2 ( renderMarkupBuilder
3 , renderMarkupBuilder
4 , renderMarkupBuilderWithT
5 , renderMarkupT
6 , renderMarkupWithT
7 , renderHtmlBuilderT
8 , renderHtmlBuilderWithT
9 , renderHtmlT
10 , renderHtmlWithT
11 , renderMarkupBuilderWith 3 , renderMarkupBuilderWith
12 , renderMarkup 4 , renderMarkup
13 , renderMarkupWith 5 , renderMarkupWith
@@ -17,9 +9,7 @@ module Text.BlazeT.Renderer.Text
17 , renderHtmlWith 9 , renderHtmlWith
18 ) where 10 ) where
19 11
20import Control.Monad
21import Data.ByteString (ByteString) 12import Data.ByteString (ByteString)
22import Control.Monad.Identity
23import Data.Text (Text) 13import Data.Text (Text)
24import qualified Data.Text.Lazy as L 14import qualified Data.Text.Lazy as L
25import qualified Data.Text.Lazy.Builder as B 15import qualified Data.Text.Lazy.Builder as B
@@ -28,48 +18,26 @@ import qualified Text.Blaze.Renderer.Text as BU
28import Text.BlazeT 18import Text.BlazeT
29 19
30renderMarkupBuilder :: MarkupM a -> B.Builder 20renderMarkupBuilder :: MarkupM a -> B.Builder
31renderMarkupBuilder = runIdentity . renderMarkupBuilderT 21renderMarkupBuilder = BU.renderMarkupBuilder . execMarkup
32
33renderMarkupBuilderT :: Monad m => MarkupT m a -> m B.Builder
34renderMarkupBuilderT = liftM BU.renderMarkupBuilder . execMarkupT
35 22
36renderHtmlBuilder :: MarkupM a -> B.Builder 23renderHtmlBuilder :: MarkupM a -> B.Builder
37renderHtmlBuilder = renderMarkupBuilder 24renderHtmlBuilder = renderMarkupBuilder
38 25
39renderHtmlBuilderT :: Monad m => MarkupT m a -> m B.Builder
40renderHtmlBuilderT = renderMarkupBuilderT
41
42renderMarkup :: MarkupM a -> L.Text 26renderMarkup :: MarkupM a -> L.Text
43renderMarkup = runIdentity . renderMarkupT 27renderMarkup = BU.renderMarkup . execMarkup
44renderMarkupT :: Monad m => MarkupT m a -> m L.Text
45renderMarkupT = liftM BU.renderMarkup . execMarkupT
46 28
47renderHtml :: MarkupM a -> L.Text 29renderHtml :: MarkupM a -> L.Text
48renderHtml = renderMarkup 30renderHtml = renderMarkup
49renderHtmlT :: Monad m => MarkupT m a -> m L.Text
50renderHtmlT = renderMarkupT
51
52renderMarkupWithT :: Monad m => (ByteString -> Text) -> MarkupT m a -> m L.Text
53renderMarkupWithT g = liftM (BU.renderMarkupWith g) . execMarkupT
54 31
55renderMarkupWith :: (ByteString -> Text) -> MarkupM a -> L.Text 32renderMarkupWith :: (ByteString -> Text) -> MarkupM a -> L.Text
56renderMarkupWith g = runIdentity . renderMarkupWithT g 33renderMarkupWith g = (BH.renderHtmlWith g) . execMarkup
57
58renderHtmlWithT :: Monad m => (ByteString -> Text) -> MarkupT m a -> m L.Text
59renderHtmlWithT g = liftM (BH.renderHtmlWith g) . execMarkupT
60 34
61renderHtmlWith :: (ByteString -> Text) -> MarkupM a -> L.Text 35renderHtmlWith :: (ByteString -> Text) -> MarkupM a -> L.Text
62renderHtmlWith g = runIdentity . renderHtmlWithT g 36renderHtmlWith = renderMarkupWith
63
64renderHtmlBuilderWithT :: Monad m => (ByteString -> Text) -> MarkupT m a -> m B.Builder
65renderHtmlBuilderWithT g = liftM (BH.renderHtmlBuilderWith g) . execMarkupT
66
67renderHtmlBuilderWith :: (ByteString -> Text) -> MarkupM a -> B.Builder
68renderHtmlBuilderWith g = runIdentity . renderHtmlBuilderWithT g
69 37
38renderMarkupBuilderWith :: (ByteString -> Text) -> MarkupM a -> B.Builder
39renderMarkupBuilderWith g = (BU.renderMarkupBuilderWith g) . execMarkup
70 40
71renderMarkupBuilderWithT :: Monad m => (ByteString -> Text) -> MarkupT m a -> m B.Builder 41renderHtmlBuilderWith :: (ByteString -> Text) -> MarkupM a -> B.Builder
72renderMarkupBuilderWithT g = liftM (BU.renderMarkupBuilderWith g) . execMarkupT 42renderHtmlBuilderWith = renderHtmlBuilderWith
73 43
74renderMarkupBuilderWith :: (ByteString -> Text) -> MarkupM a -> B.Builder
75renderMarkupBuilderWith g = runIdentity . renderMarkupBuilderWithT g
diff --git a/src/Text/BlazeT/Renderer/Utf8.hs b/src/Text/BlazeT/Renderer/Utf8.hs
index 292f81f..b5fd656 100644
--- a/src/Text/BlazeT/Renderer/Utf8.hs
+++ b/src/Text/BlazeT/Renderer/Utf8.hs
@@ -13,54 +13,28 @@ module Text.BlazeT.Renderer.Utf8
13 , renderHtmlBuilder 13 , renderHtmlBuilder
14 , renderHtml 14 , renderHtml
15 , renderHtmlToByteStringIO 15 , renderHtmlToByteStringIO
16
17 -- * new BlazeT stuff
18 , renderMarkupBuilderT
19 , renderMarkupT
20 , renderMarkupToByteStringIOT
21 , renderHtmlToByteStringIOT
22 , renderHtmlBuilderT
23 , renderHtmlT
24 ) where 16 ) where
25 17
26import qualified Blaze.ByteString.Builder as B 18import qualified Blaze.ByteString.Builder as B
27import Control.Monad
28import Control.Monad.Identity
29import qualified Data.ByteString as BS 19import qualified Data.ByteString as BS
30import qualified Data.ByteString.Lazy as BL 20import qualified Data.ByteString.Lazy as BL
31import qualified Text.Blaze.Renderer.Utf8 as BU 21import qualified Text.Blaze.Renderer.Utf8 as BU
32import Text.BlazeT 22import Text.BlazeT
33 23
34renderMarkupBuilder :: MarkupM a -> B.Builder 24renderMarkupBuilder :: MarkupM a -> B.Builder
35renderMarkupBuilder = runIdentity . renderMarkupBuilderT 25renderMarkupBuilder = BU.renderMarkupBuilder . execMarkup
36
37renderMarkupBuilderT :: Monad m => MarkupT m a -> m B.Builder
38renderMarkupBuilderT = liftM BU.renderMarkupBuilder . execMarkupT
39 26
40renderHtmlBuilder :: MarkupM a -> B.Builder 27renderHtmlBuilder :: MarkupM a -> B.Builder
41renderHtmlBuilder = renderMarkupBuilder 28renderHtmlBuilder = renderMarkupBuilder
42 29
43renderHtmlBuilderT :: Monad m => MarkupT m a -> m B.Builder
44renderHtmlBuilderT = renderMarkupBuilderT
45
46renderMarkup :: MarkupM a -> BL.ByteString 30renderMarkup :: MarkupM a -> BL.ByteString
47renderMarkup = runIdentity . renderMarkupT 31renderMarkup = BU.renderMarkup . execMarkup
48renderMarkupT :: Monad m => MarkupT m a -> m BL.ByteString
49renderMarkupT = liftM BU.renderMarkup . execMarkupT
50 32
51renderHtml :: MarkupM a -> BL.ByteString 33renderHtml :: MarkupM a -> BL.ByteString
52renderHtml = renderMarkup 34renderHtml = renderMarkup
53renderHtmlT :: Monad m => MarkupT m a -> m BL.ByteString
54renderHtmlT = renderMarkupT
55 35
56renderMarkupToByteStringIO :: (BS.ByteString -> IO ()) -> MarkupM a -> IO () 36renderMarkupToByteStringIO :: (BS.ByteString -> IO ()) -> MarkupM a -> IO ()
57renderMarkupToByteStringIO g = runIdentity . renderMarkupToByteStringIOT g 37renderMarkupToByteStringIO g = BU.renderMarkupToByteStringIO g . execMarkup
58renderMarkupToByteStringIOT :: Monad m => (BS.ByteString -> IO ()) ->
59 MarkupT m a -> m (IO ())
60renderMarkupToByteStringIOT g = liftM (BU.renderMarkupToByteStringIO g) . execMarkupT
61 38
62renderHtmlToByteStringIO :: (BS.ByteString -> IO ()) -> MarkupM a -> IO () 39renderHtmlToByteStringIO :: (BS.ByteString -> IO ()) -> MarkupM a -> IO ()
63renderHtmlToByteStringIO g = runIdentity . renderMarkupToByteStringIOT g 40renderHtmlToByteStringIO = renderMarkupToByteStringIO
64renderHtmlToByteStringIOT :: Monad m => (BS.ByteString -> IO ()) ->
65 MarkupT m a -> m (IO ())
66renderHtmlToByteStringIOT g = liftM (BU.renderMarkupToByteStringIO g) . execMarkupT