aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJohannes Gerer <oss@johannesgerer.com>2016-10-27 02:18:13 +0200
committerJohannes Gerer <oss@johannesgerer.com>2016-10-27 02:18:13 +0200
commit95eb4d6a041305a27dc8fcd42ff1831d9961b7a3 (patch)
tree3433db574dc8d074354ae70232d29a9cb81ba136
parent675085c2e0b0b851378da08b7d73024766107c87 (diff)
downloadblazeT-95eb4d6a041305a27dc8fcd42ff1831d9961b7a3.tar.gz
blazeT-95eb4d6a041305a27dc8fcd42ff1831d9961b7a3.tar.zst
blazeT-95eb4d6a041305a27dc8fcd42ff1831d9961b7a3.zip
Docsv0.0.1
-rw-r--r--README.md85
-rw-r--r--Setup.hs3
-rw-r--r--src/Readme.hs23
-rw-r--r--src/Text/BlazeT.hs57
-rw-r--r--src/Text/BlazeT/Html.hs17
-rw-r--r--src/Text/BlazeT/Internal.hs234
-rw-r--r--src/Text/BlazeT/Renderer/Pretty.hs11
-rw-r--r--src/Text/BlazeT/Renderer/String.hs11
-rw-r--r--src/Text/BlazeT/Renderer/Text.hs51
-rw-r--r--src/Text/BlazeT/Renderer/Utf8.hs35
10 files changed, 306 insertions, 221 deletions
diff --git a/README.md b/README.md
index 0169fab..37e4be5 100644
--- a/README.md
+++ b/README.md
@@ -26,14 +26,14 @@ accumulating log or other diagnostic output
26doing `IO` (like database access) are the first things that come to 26doing `IO` (like database access) are the first things that come to
27mind. 27mind.
28 28
29The initial reason of existence of this library is its use 29The reason of existence of this library is its use
30in [Lykah](http://johannesgerer.com/Lykah), which powers my personal 30in [Lykah](http://johannesgerer.com/Lykah), which powers my personal
31website 31website
32[http://johannesgerer.com](http://johannesgerer.com/johannesgerer.com). In 32[http://johannesgerer.com](http://johannesgerer.com/johannesgerer.com). In
33Lykah, the HTML templates have access to the whole site structure (to 33Lykah, the HTML templates have access to the whole site structure (to
34build things like menus) and automatically check, insert and keep 34build things like menus or blog post lists) and automatically check,
35track of referenced pages and assets, which turns out to be very 35insert and keep track of referenced pages and assets, which turns out
36useful for the task of static website generation. 36to be very useful functionality of a static website generator.
37 37
38# How to use it? 38# How to use it?
39 39
@@ -51,27 +51,87 @@ their [documentation](https://jaspervdj.be/blaze/).
51 51
52## Unleash the monads 52## Unleash the monads
53 53
54[Text.BlazeT](https://hackage.haskell.org/package/blazeT/docs/Text-BlazeT.html)
55exports `runWith` and `execWith`, which work on any
56`Text.BlazeT.Renderer.*`. The rendered markup will be returned within
57the base monad, whose actions can be
58[`lift`ed](https://hackage.haskell.org/package/transformers-0.5.2.0/docs/Control-Monad-Trans-Class.html)
59into the Markup, as shown in the following example (from
60[here](src/Readme.hs)):
54 61
62```Haskell
63{-# LANGUAGE OverloadedStrings #-}
64
65import Data.Time (getCurrentTime)
66import Text.BlazeT.Html5 hiding (main)
67import Text.BlazeT.Renderer.String
68import Control.Monad.Trans.Class (lift)
69
70-- Backwords compatible Blaze HTML
71old :: Markup
72old = do
73 p $ "created with blaze-html"
74
75-- BlazeT HTML with lifted IO actions
76new :: MarkupT IO ()
77new = do
78 time <- lift getCurrentTime
79 p $ string $ "created with blazeT at " ++ show time
80
81main :: IO ()
82main = do
83 putStrLn $ renderMarkup old
84 putStrLn =<< execWith renderMarkup new
85
86```
87
88prints:
89
90```HTML
91<p>created with blaze-html</p>
92<p>created with blazeT at 2016-10-26 01:09:16.969147361 UTC</p>
93```
94
95# Installation
96
971. To make it available on your system (or sandbox) use `cabal install blazeT`.
98
992. To play around with the source, obtain by cloning this repo or use
100 `cabal get blazet`, enter the directory and run:
101
102```bash
103cabal sandbox init #optional
104cabal install
105```
106
107# Documentation on [Hackage](https://hackage.haskell.org/package/blazeT)
55 108
56# Implementation 109# Implementation
57 110
58... is located 111... is contained
59in 112in
60[Text.BlazeT.Internals](https://hackage.haskell.org/package/blazeT/docs/Text-BlazeT-Internals.html). 113[Text.BlazeT.Internals](https://hackage.haskell.org/package/blazeT/docs/Text-BlazeT-Internals.html).
61 114
62Everything build around the simple `newtype` definition of the 115Everything is build around the simple `newtype` definition of the
63`MarkupT` transformer, which makes use of the fact that `Blaze.Markup` 116`MarkupT` transformer, which makes use
64is 117the
65a 118[Monoid](https://hackage.haskell.org/package/base-4.7.0.2/docs/Data-Monoid.html) instance
66[Monoid](https://hackage.haskell.org/package/base-4.7.0.2/docs/Data-Monoid.html) and 119of `Blaze.Markup` and is basically a `WriterT` writing `Blaze.Markup`:
67which is basically a `WriterT` transformer writing `Blaze.Markup`:
68 120
69```Haskell 121```Haskell
70newtype MarkupT m a = MarkupT { fromMarkupT :: WriterT B.Markup m a } 122newtype MarkupT m a = MarkupT { fromMarkupT :: WriterT B.Markup m a }
71``` 123```
72 124
125The old `Text.Blaze.Markup` type is replaced by a rank-2 version of
126the transformer:
127
128```Haskell
129type Markup = forall m . Monad m => MarkupT m ()
130```
131
73Wrappers used to lift all `Blaze` entities into `BlazeT` are trivially 132Wrappers used to lift all `Blaze` entities into `BlazeT` are trivially
74expressible using basic `WriterT` class methods. Wrapping `Blaze.Markup` is simply `WriterT.tell`: 133expressible using basic `WriterT` class methods. Wrapping
134`Blaze.Markup` is simply `WriterT.tell`:
75 135
76```Haskell 136```Haskell
77wrapMarkupT :: Monad m => B.Markup -> MarkupT m () 137wrapMarkupT :: Monad m => B.Markup -> MarkupT m ()
@@ -84,4 +144,3 @@ wrapMarkupT2 :: Monad m => (B.Markup -> B.Markup) -> MarkupT m a -> MarkupT m a
84wrapMarkupT2 = censor 144wrapMarkupT2 = censor
85``` 145```
86 146
87
diff --git a/Setup.hs b/Setup.hs
index c67c506..7b0e237 100644
--- a/Setup.hs
+++ b/Setup.hs
@@ -3,9 +3,10 @@ import Distribution.Simple.Setup
3import Distribution.Simple.Haddock 3import Distribution.Simple.Haddock
4main = do 4main = do
5 defaultMainWithHooks simpleUserHooks{ 5 defaultMainWithHooks simpleUserHooks{
6 haddockHook = \p l h f -> haddockHook simpleUserHooks p l h f{ 6 haddockHook = \p l h flags -> haddockHook simpleUserHooks p l h flags{
7 haddockHoogle = Flag True, 7 haddockHoogle = Flag True,
8 haddockHtml = Flag True, 8 haddockHtml = Flag True,
9 haddockProgramArgs = [("-q",["aliased"])], -- does not seam to do anything
9 haddockExecutables = Flag True, 10 haddockExecutables = Flag True,
10 haddockHscolour = Flag True 11 haddockHscolour = Flag True
11 } 12 }
diff --git a/src/Readme.hs b/src/Readme.hs
new file mode 100644
index 0000000..3ccabad
--- /dev/null
+++ b/src/Readme.hs
@@ -0,0 +1,23 @@
1{-# LANGUAGE OverloadedStrings #-}
2
3import Data.Time (getCurrentTime)
4import Text.BlazeT.Html5 hiding (main)
5import Text.BlazeT.Renderer.String
6import Control.Monad.Trans.Class (lift)
7
8-- Backwords compatible Blaze HTML
9old :: Markup
10old = do
11 p $ "created with blaze-html"
12
13-- BlazeT HTML with lifted IO actions
14new :: MarkupT IO ()
15new = do
16 time <- lift getCurrentTime
17 p $ string $ "created with blazeT at " ++ show time
18
19main :: IO ()
20main = do
21 putStrLn $ renderMarkup old
22 putStrLn =<< execWith renderMarkup new
23
diff --git a/src/Text/BlazeT.hs b/src/Text/BlazeT.hs
index 27228fa..ffdd89b 100644
--- a/src/Text/BlazeT.hs
+++ b/src/Text/BlazeT.hs
@@ -1,19 +1,24 @@
1{-# LANGUAGE UndecidableInstances #-} 1{-# LANGUAGE UndecidableInstances #-}
2{-# LANGUAGE FlexibleInstances #-} 2{-# LANGUAGE FlexibleInstances #-}
3{-# LANGUAGE RankNTypes #-} 3{-# LANGUAGE RankNTypes #-}
4
4module Text.BlazeT 5module Text.BlazeT
5 ( 6 (
6 -- * Important types. 7 -- * DO NOT READ THIS. READ "Text.BlazeT.Internal" INSTEAD
8 -- $descr
9
10 -- * DO NOT READ THIS
11-- -- * Important types.
7 Markup 12 Markup
8 , Tag 13 , Tag
9 , Attribute 14 , Attribute
10 , AttributeValue 15 , AttributeValue
11 16
12 -- * Creating attributes. 17-- -- * Creating attributes.
13 , dataAttribute 18 , dataAttribute
14 , customAttribute 19 , customAttribute
15 20
16 -- * Converting values to Markup. 21-- -- * Converting values to Markup.
17 , ToMarkup (..) 22 , ToMarkup (..)
18 , text 23 , text
19 , preEscapedText 24 , preEscapedText
@@ -24,19 +29,19 @@ module Text.BlazeT
24 , unsafeByteString 29 , unsafeByteString
25 , unsafeLazyByteString 30 , unsafeLazyByteString
26 31
27 -- * Comments 32-- -- * Comments
28 , textComment 33 , textComment
29 , lazyTextComment 34 , lazyTextComment
30 , stringComment 35 , stringComment
31 , unsafeByteStringComment 36 , unsafeByteStringComment
32 , unsafeLazyByteStringComment 37 , unsafeLazyByteStringComment
33 38
34 -- * Creating tags. 39-- -- * Creating tags.
35 , textTag 40 , textTag
36 , stringTag 41 , stringTag
37 42
38 -- * Converting values to attribute values. 43-- -- * Converting values to attribute values.
39 , B.ToValue (..) 44 , Text.Blaze.ToValue (..)
40 , textValue 45 , textValue
41 , preEscapedTextValue 46 , preEscapedTextValue
42 , lazyTextValue 47 , lazyTextValue
@@ -46,26 +51,28 @@ module Text.BlazeT
46 , unsafeByteStringValue 51 , unsafeByteStringValue
47 , unsafeLazyByteStringValue 52 , unsafeLazyByteStringValue
48 53
49 -- * Setting attributes 54-- -- * Setting attributes
50 , (!) 55 , (!)
51 , (!?) 56 , (!?)
52 57
53 -- * Modifiying Markup trees 58-- -- * Modifiying Markup trees
54 , contents 59 , contents
55 60
56 -- * BlazeT new stuff 61 ,MarkupT(..)
62 ,MarkupI
63 ,mapMarkupT
57 ,MarkupM 64 ,MarkupM
58 ,Markup2 65 ,Markup2
59 ,mapMarkupT
60 ,MarkupT
61 ,runMarkup
62 ,runMarkupT 66 ,runMarkupT
63 ,execMarkup 67 ,runMarkup
68 ,runWith
64 ,execMarkupT 69 ,execMarkupT
70 ,execMarkup
71 ,execWith
65 ) where 72 ) where
66 73
67import qualified Text.Blaze as B 74import qualified Text.Blaze
68import Text.BlazeT.Internal 75import Text.BlazeT.Internal as Text.BlazeT.Internal
69 76
70class ToMarkup a where 77class ToMarkup a where
71 toMarkup :: a -> Markup 78 toMarkup :: a -> Markup
@@ -74,8 +81,20 @@ class ToMarkup a where
74-- test :: (ToMarkup a, Monad m) => a -> MarkupT m () 81-- test :: (ToMarkup a, Monad m) => a -> MarkupT m ()
75-- test = toMarkup 82-- test = toMarkup
76 83
77instance B.ToMarkup a => ToMarkup a where 84instance Text.Blaze.ToMarkup a => ToMarkup a where
78 toMarkup = wrapMarkup . B.toMarkup 85 toMarkup = wrapMarkup . Text.Blaze.toMarkup
79 {-# INLINE toMarkup #-} 86 {-# INLINE toMarkup #-}
80 preEscapedToMarkup = wrapMarkup . B.preEscapedToMarkup 87 preEscapedToMarkup = wrapMarkup . Text.Blaze.preEscapedToMarkup
81 {-# INLINE preEscapedToMarkup #-} 88 {-# INLINE preEscapedToMarkup #-}
89
90
91-- $descr
92--
93-- Due due a Haddock bug, this documentation is misleading. Please
94-- read "Text.BlazeT.Internal" instead.
95--
96-- (The bug shows both @Text.Blaze.Markup@ and @Text.BlazeT.Markup@ as
97-- "Markup".)
98--
99-- Use this documentation only to see which entities are exported by
100-- this module.
diff --git a/src/Text/BlazeT/Html.hs b/src/Text/BlazeT/Html.hs
index 4a21c03..d71e90a 100644
--- a/src/Text/BlazeT/Html.hs
+++ b/src/Text/BlazeT/Html.hs
@@ -1,18 +1,21 @@
1{-# LANGUAGE RankNTypes #-} 1{-# LANGUAGE RankNTypes #-}
2module Text.BlazeT.Html 2module Text.BlazeT.Html
3 ( module Text.BlazeT 3 (
4 module Text.BlazeT
5 -- * Entities exported only by the @blazeT@ version of this module
6 ,HtmlM
7 ,HtmlT
8 -- * Entities exported also by "Text.Blaze.Html"
9 -- $descr1
4 , Html 10 , Html
5 , toHtml 11 , toHtml
6 , preEscapedToHtml 12 , preEscapedToHtml
7 -- * BlazeT new stuff
8 ,HtmlM
9 ,HtmlT
10 ) where 13 ) where
11 14
12import Text.BlazeT 15import Text.BlazeT
13 16
14type HtmlT = MarkupT 17type HtmlT = MarkupT
15type HtmlM = MarkupM 18type HtmlM a = MarkupM a
16type Html = Markup 19type Html = Markup
17 20
18toHtml ::(ToMarkup a) => a -> Html 21toHtml ::(ToMarkup a) => a -> Html
@@ -20,3 +23,7 @@ toHtml = toMarkup
20 23
21preEscapedToHtml ::(ToMarkup a) => a -> Html 24preEscapedToHtml ::(ToMarkup a) => a -> Html
22preEscapedToHtml = preEscapedToMarkup 25preEscapedToHtml = preEscapedToMarkup
26
27-- $descr1 The following is an adaptation of all "Text.Blaze.Html"
28-- exports to @blazeT@ types. For their documentation consult the
29-- "Text.Blaze.Html" documentation.
diff --git a/src/Text/BlazeT/Internal.hs b/src/Text/BlazeT/Internal.hs
index 24ef1fe..aa56347 100644
--- a/src/Text/BlazeT/Internal.hs
+++ b/src/Text/BlazeT/Internal.hs
@@ -8,23 +8,49 @@
8#endif 8#endif
9module Text.BlazeT.Internal 9module Text.BlazeT.Internal
10 ( 10 (
11 -- * Important types. 11 -- * Entities exported only by the @blazeT@ version of this module
12 B.ChoiceString (..) 12 MarkupT(..)
13 , B.StaticString (..) 13 ,MarkupI
14 , MarkupM 14 ,mapMarkupT
15 , Markup 15 -- ** Specializations for @blaze-markup@ backwards compatibility
16 , B.Tag 16 ,MarkupM
17 , B.Attribute 17 ,Markup
18 , B.AttributeValue 18 ,Markup2
19 19 -- ** Running
20 -- * Creating custom tags and attributes. 20 ,runMarkupT
21 ,runMarkup
22 ,runWith
23 -- ** Executing
24 ,execMarkupT
25 ,execMarkup
26 ,execWith
27 -- ** Wrappers
28 ,wrapMarkupT
29 ,wrapMarkupT2
30 ,wrapMarkup
31 ,wrapMarkup2
32 ,
33
34 -- * Entities exported also by "Text.Blaze.Internal"
35 -- $descr1
36
37 -- ** Important types.
38 Text.Blaze.ChoiceString (..)
39 , Text.Blaze.StaticString (..)
40 -- , MarkupM
41 -- , Markup
42 , Text.Blaze.Tag
43 , Text.Blaze.Attribute
44 , Text.Blaze.AttributeValue
45
46 -- ** Creating custom tags and attributes.
21 , customParent 47 , customParent
22 , customLeaf 48 , customLeaf
23 , B.attribute 49 , Text.Blaze.attribute
24 , B.dataAttribute 50 , Text.Blaze.dataAttribute
25 , B.customAttribute 51 , Text.Blaze.customAttribute
26 52
27 -- * Converting values to Markup. 53 -- ** Converting values to Markup.
28 , text 54 , text
29 , preEscapedText 55 , preEscapedText
30 , lazyText 56 , lazyText
@@ -36,55 +62,44 @@ module Text.BlazeT.Internal
36 , unsafeByteString 62 , unsafeByteString
37 , unsafeLazyByteString 63 , unsafeLazyByteString
38 64
39 -- * Comments 65 -- ** Comments
40 , B.textComment 66 , Text.Blaze.textComment
41 , B.lazyTextComment 67 , Text.Blaze.lazyTextComment
42 , B.stringComment 68 , Text.Blaze.stringComment
43 , B.unsafeByteStringComment 69 , Text.Blaze.unsafeByteStringComment
44 , B.unsafeLazyByteStringComment 70 , Text.Blaze.unsafeLazyByteStringComment
45 71
46 -- * Converting values to tags. 72 -- ** Converting values to tags.
47 , B.textTag 73 , Text.Blaze.textTag
48 , B.stringTag 74 , Text.Blaze.stringTag
49 75
50 -- * Converting values to attribute values. 76 -- ** Converting values to attribute values.
51 , B.textValue 77 , Text.Blaze.textValue
52 , B.preEscapedTextValue 78 , Text.Blaze.preEscapedTextValue
53 , B.lazyTextValue 79 , Text.Blaze.lazyTextValue
54 , B.preEscapedLazyTextValue 80 , Text.Blaze.preEscapedLazyTextValue
55 , B.textBuilderValue 81 , Text.Blaze.textBuilderValue
56 , B.preEscapedTextBuilderValue 82 , Text.Blaze.preEscapedTextBuilderValue
57 , B.stringValue 83 , Text.Blaze.stringValue
58 , B.preEscapedStringValue 84 , Text.Blaze.preEscapedStringValue
59 , B.unsafeByteStringValue 85 , Text.Blaze.unsafeByteStringValue
60 , B.unsafeLazyByteStringValue 86 , Text.Blaze.unsafeLazyByteStringValue
61 87
62 -- * Setting attributes 88 -- ** Setting attributes
63 , B.Attributable 89 , Text.Blaze.Attributable
64 , (B.!) 90 , (Text.Blaze.!)
65 , (B.!?) 91 , (Text.Blaze.!?)
66 92
67 -- * Modifying Markup elements 93 -- ** Modifying Markup elements
68 , contents 94 , contents
69 , external 95 , external
70 96
71 -- * Querying Markup elements 97 -- ** Querying Markup elements
72 , null 98 , null
73 99
74 -- * BlazeT new stuff
75 ,Markup2
76 ,mapMarkupT
77 ,MarkupT
78 ,runMarkup
79 ,runMarkupT
80 ,execMarkup
81 ,execMarkupT
82 ,wrapMarkup
83 ,wrapMarkupT
84 ,wrapMarkup2
85 ,wrapMarkupT2
86 ) where 100 ) where
87 101
102import Control.Arrow
88import Control.Monad.Identity 103import Control.Monad.Identity
89import Control.Monad.Trans.Class 104import Control.Monad.Trans.Class
90import Control.Monad.Writer.Strict 105import Control.Monad.Writer.Strict
@@ -94,47 +109,63 @@ import Data.String
94import qualified Data.Text as T 109import qualified Data.Text as T
95import qualified Data.Text.Lazy as LT 110import qualified Data.Text.Lazy as LT
96import qualified Data.Text.Lazy.Builder as LTB 111import qualified Data.Text.Lazy.Builder as LTB
97import qualified Text.Blaze as B 112import qualified Text.Blaze
98import qualified Text.Blaze.Internal as B 113import qualified Text.Blaze.Internal as Text.Blaze
99 114
100newtype MarkupT m a= MarkupT { fromMarkupT :: WriterT B.Markup m a } 115{- | Everything is build around the simple @newtype@ definition of the
116'MarkupT' transformer, which makes use the 'Monoid' instance of Blaze
117'Text.Blaze.Markup' and is basically a 'WriterT' writing Blaze
118'Text.Blaze.Markup':
119-}
120newtype MarkupT m a= MarkupT { fromMarkupT :: WriterT Text.Blaze.Markup m a }
101 deriving (Functor 121 deriving (Functor
102#if MIN_VERSION_base(4,8,0) 122#if MIN_VERSION_base(4,8,0)
103 ,Applicative 123 ,Applicative
104#endif 124#endif
105 ,Monad 125 ,Monad
106 ,MonadWriter B.Markup 126 ,MonadWriter Text.Blaze.Markup
107 ,MonadTrans 127 ,MonadTrans
108 ) 128 )
109 129
130type MarkupI a = MarkupT Identity a
131
110-- | Map both the return value and markup of a computation using the 132-- | Map both the return value and markup of a computation using the
111-- given function 133-- given function
112mapMarkupT :: (m (a,B.Markup) -> n (b,B.Markup)) -> MarkupT m a -> MarkupT n b 134mapMarkupT :: (m (a,Text.Blaze.Markup) -> n (b,Text.Blaze.Markup)) -> MarkupT m a -> MarkupT n b
113mapMarkupT f = MarkupT . mapWriterT f . fromMarkupT 135mapMarkupT f = MarkupT . mapWriterT f . fromMarkupT
114{-# INLINE mapMarkupT #-} 136{-# INLINE mapMarkupT #-}
115 137
116type MarkupM = MarkupT Identity 138type MarkupM a = forall m . Monad m => MarkupT m a
117type Markup = forall m . Monad m => MarkupT m () 139type Markup = MarkupM ()
118type Markup2 = forall m . Monad m => MarkupT m () -> MarkupT m () 140type Markup2 = forall m . Monad m => MarkupT m () -> MarkupT m ()
119 141
120runMarkupT :: MarkupT m a -> m (a,B.Markup) 142runMarkupT :: MarkupT m a -> m (a,Text.Blaze.Markup)
121runMarkupT = runWriterT . fromMarkupT 143runMarkupT = runWriterT . fromMarkupT
122{-# INLINE runMarkupT #-} 144{-# INLINE runMarkupT #-}
123 145
124execMarkupT :: Monad m => MarkupT m a -> m B.Markup 146-- | run the MarkupT and return a pair consisting of the result of the
147-- computation and the blaze markup rendered with a blaze renderer
148-- like 'Text.BlazeT.Renderer.Text.renderHtml'
149runWith :: Monad m => (Markup -> c) -> MarkupT m a -> m (a, c)
150runWith renderer = liftM (second $ \x -> renderer $ wrapMarkup x) . runMarkupT
151{-# INLINE runWith #-}
152
153execMarkupT :: Monad m => MarkupT m a -> m Text.Blaze.Markup
125execMarkupT = liftM snd . runMarkupT 154execMarkupT = liftM snd . runMarkupT
126{-# INLINE execMarkupT #-} 155{-# INLINE execMarkupT #-}
127 156
128runMarkup :: MarkupM a -> (a,B.Markup) 157execWith :: Monad m => (Markup -> c) -> MarkupT m a -> m c
158execWith renderer = liftM snd . runWith renderer
159{-# INLINE execWith #-}
160
161runMarkup :: MarkupI a -> (a, Text.Blaze.Markup)
129runMarkup = runIdentity . runMarkupT 162runMarkup = runIdentity . runMarkupT
130{-# INLINE runMarkup #-} 163{-# INLINE runMarkup #-}
131 164
132execMarkup :: MarkupM a -> B.Markup 165execMarkup :: MarkupI a -> Text.Blaze.Markup
133execMarkup = snd . runMarkup 166execMarkup = snd . runMarkup
134{-# INLINE execMarkup #-} 167{-# INLINE execMarkup #-}
135 168
136-- instance MonadTrans MarkupT where
137
138 169
139instance (Monad m,Monoid a) => Monoid (MarkupT m a) where 170instance (Monad m,Monoid a) => Monoid (MarkupT m a) where
140 mempty = return mempty 171 mempty = return mempty
@@ -143,37 +174,42 @@ instance (Monad m,Monoid a) => Monoid (MarkupT m a) where
143 {-# INLINE mappend #-} 174 {-# INLINE mappend #-}
144 175
145 176
146instance Monad m => B.Attributable (MarkupT m a) where 177instance Monad m => Text.Blaze.Attributable (MarkupT m a) where
147 h ! a = wrapMarkupT2 (B.! a) h 178 h ! a = wrapMarkupT2 (Text.Blaze.! a) h
148 {-# INLINE (!) #-} 179 {-# INLINE (!) #-}
149 180
150instance Monad m => B.Attributable (a -> MarkupT m b) where 181instance Monad m => Text.Blaze.Attributable (a -> MarkupT m b) where
151 h ! a = \x -> wrapMarkupT2 (B.! a) $ h x 182 h ! a = \x -> wrapMarkupT2 (Text.Blaze.! a) $ h x
152 {-# INLINE (!) #-} 183 {-# INLINE (!) #-}
153 184
154instance Monad m => IsString (MarkupT m ()) where 185instance Monad m => IsString (MarkupT m ()) where
155 fromString = wrapMarkup . fromString 186 fromString = wrapMarkup . fromString
156 {-# INLINE fromString #-} 187 {-# INLINE fromString #-}
157 188
158wrapMarkupT :: Monad m => B.Markup -> MarkupT m () 189-- | Wrapper for 'Text.Blaze.Markup' is simply
190-- 'tell'
191wrapMarkupT :: Monad m => Text.Blaze.Markup -> MarkupT m ()
159wrapMarkupT = tell 192wrapMarkupT = tell
160{-# INLINE wrapMarkupT #-} 193{-# INLINE wrapMarkupT #-}
161 194
162wrapMarkup :: B.Markup -> Markup 195wrapMarkup :: Text.Blaze.Markup -> Markup
163wrapMarkup = wrapMarkupT 196wrapMarkup = wrapMarkupT
164{-# INLINE wrapMarkup #-} 197{-# INLINE wrapMarkup #-}
165 198
166wrapMarkupT2 :: Monad m => (B.Markup -> B.Markup) 199
200-- | Wrapper for functions that modify 'Text.Blaze.Markup' is simply
201-- 'censor'
202wrapMarkupT2 :: Monad m => (Text.Blaze.Markup -> Text.Blaze.Markup)
167 -> MarkupT m a -> MarkupT m a 203 -> MarkupT m a -> MarkupT m a
168wrapMarkupT2 = censor 204wrapMarkupT2 = censor
169{-# INLINE wrapMarkupT2 #-} 205{-# INLINE wrapMarkupT2 #-}
170 206
171wrapMarkup2 :: (B.Markup -> B.Markup) -> Markup2 207wrapMarkup2 :: (Text.Blaze.Markup -> Text.Blaze.Markup) -> Markup2
172wrapMarkup2 = wrapMarkupT2 208wrapMarkup2 = wrapMarkupT2
173{-# INLINE wrapMarkup2 #-} 209{-# INLINE wrapMarkup2 #-}
174 210
175unsafeByteString :: BS.ByteString -> Markup 211unsafeByteString :: BS.ByteString -> Markup
176unsafeByteString = wrapMarkup . B.unsafeByteString 212unsafeByteString = wrapMarkup . Text.Blaze.unsafeByteString
177{-# INLINE unsafeByteString #-} 213{-# INLINE unsafeByteString #-}
178 214
179-- | Insert a lazy 'BL.ByteString'. See 'unsafeByteString' for reasons why this 215-- | Insert a lazy 'BL.ByteString'. See 'unsafeByteString' for reasons why this
@@ -181,39 +217,39 @@ unsafeByteString = wrapMarkup . B.unsafeByteString
181-- 217--
182unsafeLazyByteString :: BL.ByteString -- ^ Value to insert 218unsafeLazyByteString :: BL.ByteString -- ^ Value to insert
183 -> Markup -- ^ Resulting HTML fragment 219 -> Markup -- ^ Resulting HTML fragment
184unsafeLazyByteString = wrapMarkup . B.unsafeLazyByteString 220unsafeLazyByteString = wrapMarkup . Text.Blaze.unsafeLazyByteString
185{-# INLINE unsafeLazyByteString #-} 221{-# INLINE unsafeLazyByteString #-}
186 222
187external :: Monad m => MarkupT m a -> MarkupT m a 223external :: Monad m => MarkupT m a -> MarkupT m a
188external = wrapMarkupT2 B.external 224external = wrapMarkupT2 Text.Blaze.external
189{-# INLINE external #-} 225{-# INLINE external #-}
190 226
191contents :: Monad m => MarkupT m a -> MarkupT m a 227contents :: Monad m => MarkupT m a -> MarkupT m a
192contents = wrapMarkupT2 B.contents 228contents = wrapMarkupT2 Text.Blaze.contents
193{-# INLINE contents #-} 229{-# INLINE contents #-}
194 230
195customParent ::B.Tag -> Markup2 231customParent ::Text.Blaze.Tag -> Markup2
196customParent = wrapMarkup2 . B.customParent 232customParent = wrapMarkup2 . Text.Blaze.customParent
197{-# INLINE customParent #-} 233{-# INLINE customParent #-}
198 234
199customLeaf :: B.Tag -> Bool -> Markup 235customLeaf :: Text.Blaze.Tag -> Bool -> Markup
200customLeaf = fmap wrapMarkup . B.customLeaf 236customLeaf = fmap wrapMarkup . Text.Blaze.customLeaf
201{-# INLINE customLeaf #-} 237{-# INLINE customLeaf #-}
202 238
203preEscapedText :: T.Text -> Markup 239preEscapedText :: T.Text -> Markup
204preEscapedText = wrapMarkup . B.preEscapedText 240preEscapedText = wrapMarkup . Text.Blaze.preEscapedText
205{-# INLINE preEscapedText #-} 241{-# INLINE preEscapedText #-}
206 242
207preEscapedLazyText :: LT.Text -> Markup 243preEscapedLazyText :: LT.Text -> Markup
208preEscapedLazyText = wrapMarkup . B.preEscapedLazyText 244preEscapedLazyText = wrapMarkup . Text.Blaze.preEscapedLazyText
209{-# INLINE preEscapedLazyText #-} 245{-# INLINE preEscapedLazyText #-}
210 246
211preEscapedTextBuilder :: LTB.Builder -> Markup 247preEscapedTextBuilder :: LTB.Builder -> Markup
212textBuilder :: LTB.Builder -> Markup 248textBuilder :: LTB.Builder -> Markup
213 249
214#ifdef PRE_BUILDER 250#ifdef PRE_BUILDER
215preEscapedTextBuilder = wrapMarkup . B.preEscapedTextBuilder 251preEscapedTextBuilder = wrapMarkup . Text.Blaze.preEscapedTextBuilder
216textBuilder = wrapMarkup . B.textBuilder 252textBuilder = wrapMarkup . Text.Blaze.textBuilder
217{-# INLINE preEscapedTextBuilder #-} 253{-# INLINE preEscapedTextBuilder #-}
218{-# INLINE textBuilder #-} 254{-# INLINE textBuilder #-}
219#else 255#else
@@ -222,17 +258,27 @@ textBuilder = error "This function needs blaze-markup 0.7.1.0"
222#endif 258#endif
223 259
224preEscapedString :: String -> Markup 260preEscapedString :: String -> Markup
225preEscapedString = wrapMarkup . B.preEscapedString 261preEscapedString = wrapMarkup . Text.Blaze.preEscapedString
226{-# INLINE preEscapedString #-} 262{-# INLINE preEscapedString #-}
227 263
228string :: String -> Markup 264string :: String -> Markup
229string = wrapMarkup . B.string 265string = wrapMarkup . Text.Blaze.string
230{-# INLINE string #-} 266{-# INLINE string #-}
231 267
232text :: T.Text -> Markup 268text :: T.Text -> Markup
233text = wrapMarkup . B.text 269text = wrapMarkup . Text.Blaze.text
234{-# INLINE text #-} 270{-# INLINE text #-}
235 271
236lazyText :: LT.Text -> Markup 272lazyText :: LT.Text -> Markup
237lazyText = wrapMarkup . B.lazyText 273lazyText = wrapMarkup . Text.Blaze.lazyText
238{-# INLINE lazyText #-} 274{-# INLINE lazyText #-}
275
276-- $descr1
277-- The following is an adaptation of all "Text.Blaze.Internal" exports to
278-- @blazeT@ types.
279--
280-- Entities that are reexported from "Text.Blaze.Internal" have the original
281-- documentation attached to them.
282--
283-- Entities that had to be adapted are tagged with \"(Adapted)\". For
284-- their documentation consult the "Text.Blaze.Internal" documentation.
diff --git a/src/Text/BlazeT/Renderer/Pretty.hs b/src/Text/BlazeT/Renderer/Pretty.hs
index 8977c94..5e033ac 100644
--- a/src/Text/BlazeT/Renderer/Pretty.hs
+++ b/src/Text/BlazeT/Renderer/Pretty.hs
@@ -1,22 +1,15 @@
1{-# LANGUAGE RankNTypes #-}
1module Text.BlazeT.Renderer.Pretty 2module Text.BlazeT.Renderer.Pretty
2 ( renderMarkup 3 ( renderMarkup
3 , renderHtml 4 , renderHtml
4 , renderMarkupT
5 , renderHtmlT
6 ) where 5 ) where
7 6
8import Control.Monad
9import Control.Monad.Identity
10import qualified Text.Blaze.Renderer.Pretty as BU 7import qualified Text.Blaze.Renderer.Pretty as BU
11import Text.BlazeT 8import Text.BlazeT
12 9
13renderMarkup :: MarkupM a -> String 10renderMarkup :: MarkupM a -> String
14renderMarkup = runIdentity . renderMarkupT 11renderMarkup = BU.renderMarkup . execMarkup
15renderMarkupT :: Monad m => MarkupT m a -> m String
16renderMarkupT = liftM BU.renderMarkup . execMarkupT
17 12
18renderHtml :: MarkupM a -> String 13renderHtml :: MarkupM a -> String
19renderHtml = renderMarkup 14renderHtml = renderMarkup
20renderHtmlT :: Monad m => MarkupT m a -> m String
21renderHtmlT = renderMarkupT
22 15
diff --git a/src/Text/BlazeT/Renderer/String.hs b/src/Text/BlazeT/Renderer/String.hs
index 0a2de8a..45c4786 100644
--- a/src/Text/BlazeT/Renderer/String.hs
+++ b/src/Text/BlazeT/Renderer/String.hs
@@ -1,13 +1,10 @@
1{-# LANGUAGE RankNTypes #-}
1module Text.BlazeT.Renderer.String 2module Text.BlazeT.Renderer.String
2 ( fromChoiceString 3 ( fromChoiceString
3 , renderMarkup 4 , renderMarkup
4 , renderHtml 5 , renderHtml
5 , renderMarkupT
6 , renderHtmlT
7 ) where 6 ) where
8 7
9import Control.Monad
10import Control.Monad.Identity
11import Text.Blaze.Internal (ChoiceString) 8import Text.Blaze.Internal (ChoiceString)
12import qualified Text.Blaze.Renderer.String as BU 9import qualified Text.Blaze.Renderer.String as BU
13import Text.BlazeT 10import Text.BlazeT
@@ -16,12 +13,8 @@ fromChoiceString :: ChoiceString -> String -> String
16fromChoiceString = BU.fromChoiceString 13fromChoiceString = BU.fromChoiceString
17 14
18renderMarkup :: MarkupM a -> String 15renderMarkup :: MarkupM a -> String
19renderMarkup = runIdentity . renderMarkupT 16renderMarkup = BU.renderMarkup . execMarkup
20renderMarkupT :: Monad m => MarkupT m a -> m String
21renderMarkupT = liftM BU.renderMarkup . execMarkupT
22 17
23renderHtml :: MarkupM a -> String 18renderHtml :: MarkupM a -> String
24renderHtml = renderMarkup 19renderHtml = renderMarkup
25renderHtmlT :: Monad m => MarkupT m a -> m String
26renderHtmlT = renderMarkupT
27 20
diff --git a/src/Text/BlazeT/Renderer/Text.hs b/src/Text/BlazeT/Renderer/Text.hs
index 31181eb..a595bd1 100644
--- a/src/Text/BlazeT/Renderer/Text.hs
+++ b/src/Text/BlazeT/Renderer/Text.hs
@@ -1,13 +1,6 @@
1{-# LANGUAGE RankNTypes #-}
1module Text.BlazeT.Renderer.Text 2module Text.BlazeT.Renderer.Text
2 ( renderMarkupBuilderT 3 ( renderMarkupBuilder
3 , renderMarkupBuilder
4 , renderMarkupBuilderWithT
5 , renderMarkupT
6 , renderMarkupWithT
7 , renderHtmlBuilderT
8 , renderHtmlBuilderWithT
9 , renderHtmlT
10 , renderHtmlWithT
11 , renderMarkupBuilderWith 4 , renderMarkupBuilderWith
12 , renderMarkup 5 , renderMarkup
13 , renderMarkupWith 6 , renderMarkupWith
@@ -17,9 +10,7 @@ module Text.BlazeT.Renderer.Text
17 , renderHtmlWith 10 , renderHtmlWith
18 ) where 11 ) where
19 12
20import Control.Monad
21import Data.ByteString (ByteString) 13import Data.ByteString (ByteString)
22import Control.Monad.Identity
23import Data.Text (Text) 14import Data.Text (Text)
24import qualified Data.Text.Lazy as L 15import qualified Data.Text.Lazy as L
25import qualified Data.Text.Lazy.Builder as B 16import qualified Data.Text.Lazy.Builder as B
@@ -28,48 +19,26 @@ import qualified Text.Blaze.Renderer.Text as BU
28import Text.BlazeT 19import Text.BlazeT
29 20
30renderMarkupBuilder :: MarkupM a -> B.Builder 21renderMarkupBuilder :: MarkupM a -> B.Builder
31renderMarkupBuilder = runIdentity . renderMarkupBuilderT 22renderMarkupBuilder = BU.renderMarkupBuilder . execMarkup
32
33renderMarkupBuilderT :: Monad m => MarkupT m a -> m B.Builder
34renderMarkupBuilderT = liftM BU.renderMarkupBuilder . execMarkupT
35 23
36renderHtmlBuilder :: MarkupM a -> B.Builder 24renderHtmlBuilder :: MarkupM a -> B.Builder
37renderHtmlBuilder = renderMarkupBuilder 25renderHtmlBuilder = renderMarkupBuilder
38 26
39renderHtmlBuilderT :: Monad m => MarkupT m a -> m B.Builder
40renderHtmlBuilderT = renderMarkupBuilderT
41
42renderMarkup :: MarkupM a -> L.Text 27renderMarkup :: MarkupM a -> L.Text
43renderMarkup = runIdentity . renderMarkupT 28renderMarkup = BU.renderMarkup . execMarkup
44renderMarkupT :: Monad m => MarkupT m a -> m L.Text
45renderMarkupT = liftM BU.renderMarkup . execMarkupT
46 29
47renderHtml :: MarkupM a -> L.Text 30renderHtml :: MarkupM a -> L.Text
48renderHtml = renderMarkup 31renderHtml = 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 32
55renderMarkupWith :: (ByteString -> Text) -> MarkupM a -> L.Text 33renderMarkupWith :: (ByteString -> Text) -> MarkupM a -> L.Text
56renderMarkupWith g = runIdentity . renderMarkupWithT g 34renderMarkupWith 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 35
61renderHtmlWith :: (ByteString -> Text) -> MarkupM a -> L.Text 36renderHtmlWith :: (ByteString -> Text) -> MarkupM a -> L.Text
62renderHtmlWith g = runIdentity . renderHtmlWithT g 37renderHtmlWith = 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 38
39renderMarkupBuilderWith :: (ByteString -> Text) -> MarkupM a -> B.Builder
40renderMarkupBuilderWith g = (BU.renderMarkupBuilderWith g) . execMarkup
70 41
71renderMarkupBuilderWithT :: Monad m => (ByteString -> Text) -> MarkupT m a -> m B.Builder 42renderHtmlBuilderWith :: (ByteString -> Text) -> MarkupM a -> B.Builder
72renderMarkupBuilderWithT g = liftM (BU.renderMarkupBuilderWith g) . execMarkupT 43renderHtmlBuilderWith = renderHtmlBuilderWith
73 44
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..2874b68 100644
--- a/src/Text/BlazeT/Renderer/Utf8.hs
+++ b/src/Text/BlazeT/Renderer/Utf8.hs
@@ -1,3 +1,4 @@
1{-# LANGUAGE RankNTypes #-}
1{-# OPTIONS_GHC -fsimpl-tick-factor=230 #-} 2{-# OPTIONS_GHC -fsimpl-tick-factor=230 #-}
2 3
3-- the above option was not needed with 4-- the above option was not needed with
@@ -13,54 +14,28 @@ module Text.BlazeT.Renderer.Utf8
13 , renderHtmlBuilder 14 , renderHtmlBuilder
14 , renderHtml 15 , renderHtml
15 , renderHtmlToByteStringIO 16 , renderHtmlToByteStringIO
16
17 -- * new BlazeT stuff
18 , renderMarkupBuilderT
19 , renderMarkupT
20 , renderMarkupToByteStringIOT
21 , renderHtmlToByteStringIOT
22 , renderHtmlBuilderT
23 , renderHtmlT
24 ) where 17 ) where
25 18
26import qualified Blaze.ByteString.Builder as B 19import qualified Blaze.ByteString.Builder as B
27import Control.Monad
28import Control.Monad.Identity
29import qualified Data.ByteString as BS 20import qualified Data.ByteString as BS
30import qualified Data.ByteString.Lazy as BL 21import qualified Data.ByteString.Lazy as BL
31import qualified Text.Blaze.Renderer.Utf8 as BU 22import qualified Text.Blaze.Renderer.Utf8 as BU
32import Text.BlazeT 23import Text.BlazeT
33 24
34renderMarkupBuilder :: MarkupM a -> B.Builder 25renderMarkupBuilder :: MarkupM a -> B.Builder
35renderMarkupBuilder = runIdentity . renderMarkupBuilderT 26renderMarkupBuilder = BU.renderMarkupBuilder . execMarkup
36
37renderMarkupBuilderT :: Monad m => MarkupT m a -> m B.Builder
38renderMarkupBuilderT = liftM BU.renderMarkupBuilder . execMarkupT
39 27
40renderHtmlBuilder :: MarkupM a -> B.Builder 28renderHtmlBuilder :: MarkupM a -> B.Builder
41renderHtmlBuilder = renderMarkupBuilder 29renderHtmlBuilder = renderMarkupBuilder
42 30
43renderHtmlBuilderT :: Monad m => MarkupT m a -> m B.Builder
44renderHtmlBuilderT = renderMarkupBuilderT
45
46renderMarkup :: MarkupM a -> BL.ByteString 31renderMarkup :: MarkupM a -> BL.ByteString
47renderMarkup = runIdentity . renderMarkupT 32renderMarkup = BU.renderMarkup . execMarkup
48renderMarkupT :: Monad m => MarkupT m a -> m BL.ByteString
49renderMarkupT = liftM BU.renderMarkup . execMarkupT
50 33
51renderHtml :: MarkupM a -> BL.ByteString 34renderHtml :: MarkupM a -> BL.ByteString
52renderHtml = renderMarkup 35renderHtml = renderMarkup
53renderHtmlT :: Monad m => MarkupT m a -> m BL.ByteString
54renderHtmlT = renderMarkupT
55 36
56renderMarkupToByteStringIO :: (BS.ByteString -> IO ()) -> MarkupM a -> IO () 37renderMarkupToByteStringIO :: (BS.ByteString -> IO ()) -> MarkupM a -> IO ()
57renderMarkupToByteStringIO g = runIdentity . renderMarkupToByteStringIOT g 38renderMarkupToByteStringIO 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 39
62renderHtmlToByteStringIO :: (BS.ByteString -> IO ()) -> MarkupM a -> IO () 40renderHtmlToByteStringIO :: (BS.ByteString -> IO ()) -> MarkupM a -> IO ()
63renderHtmlToByteStringIO g = runIdentity . renderMarkupToByteStringIOT g 41renderHtmlToByteStringIO = renderMarkupToByteStringIO
64renderHtmlToByteStringIOT :: Monad m => (BS.ByteString -> IO ()) ->
65 MarkupT m a -> m (IO ())
66renderHtmlToByteStringIOT g = liftM (BU.renderMarkupToByteStringIO g) . execMarkupT