diff options
Diffstat (limited to 'src/Text')
-rw-r--r-- | src/Text/BlazeT.hs | 57 | ||||
-rw-r--r-- | src/Text/BlazeT/Html.hs | 17 | ||||
-rw-r--r-- | src/Text/BlazeT/Internal.hs | 234 | ||||
-rw-r--r-- | src/Text/BlazeT/Renderer/Pretty.hs | 11 | ||||
-rw-r--r-- | src/Text/BlazeT/Renderer/String.hs | 11 | ||||
-rw-r--r-- | src/Text/BlazeT/Renderer/Text.hs | 51 | ||||
-rw-r--r-- | src/Text/BlazeT/Renderer/Utf8.hs | 35 |
7 files changed, 209 insertions, 207 deletions
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 | |||
4 | module Text.BlazeT | 5 | module 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 | ||
67 | import qualified Text.Blaze as B | 74 | import qualified Text.Blaze |
68 | import Text.BlazeT.Internal | 75 | import Text.BlazeT.Internal as Text.BlazeT.Internal |
69 | 76 | ||
70 | class ToMarkup a where | 77 | class 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 | ||
77 | instance B.ToMarkup a => ToMarkup a where | 84 | instance 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 #-} |
2 | module Text.BlazeT.Html | 2 | module 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 | ||
12 | import Text.BlazeT | 15 | import Text.BlazeT |
13 | 16 | ||
14 | type HtmlT = MarkupT | 17 | type HtmlT = MarkupT |
15 | type HtmlM = MarkupM | 18 | type HtmlM a = MarkupM a |
16 | type Html = Markup | 19 | type Html = Markup |
17 | 20 | ||
18 | toHtml ::(ToMarkup a) => a -> Html | 21 | toHtml ::(ToMarkup a) => a -> Html |
@@ -20,3 +23,7 @@ toHtml = toMarkup | |||
20 | 23 | ||
21 | preEscapedToHtml ::(ToMarkup a) => a -> Html | 24 | preEscapedToHtml ::(ToMarkup a) => a -> Html |
22 | preEscapedToHtml = preEscapedToMarkup | 25 | preEscapedToHtml = 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 |
9 | module Text.BlazeT.Internal | 9 | module 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 | ||
102 | import Control.Arrow | ||
88 | import Control.Monad.Identity | 103 | import Control.Monad.Identity |
89 | import Control.Monad.Trans.Class | 104 | import Control.Monad.Trans.Class |
90 | import Control.Monad.Writer.Strict | 105 | import Control.Monad.Writer.Strict |
@@ -94,47 +109,63 @@ import Data.String | |||
94 | import qualified Data.Text as T | 109 | import qualified Data.Text as T |
95 | import qualified Data.Text.Lazy as LT | 110 | import qualified Data.Text.Lazy as LT |
96 | import qualified Data.Text.Lazy.Builder as LTB | 111 | import qualified Data.Text.Lazy.Builder as LTB |
97 | import qualified Text.Blaze as B | 112 | import qualified Text.Blaze |
98 | import qualified Text.Blaze.Internal as B | 113 | import qualified Text.Blaze.Internal as Text.Blaze |
99 | 114 | ||
100 | newtype 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 | -} | ||
120 | newtype 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 | ||
130 | type 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 |
112 | mapMarkupT :: (m (a,B.Markup) -> n (b,B.Markup)) -> MarkupT m a -> MarkupT n b | 134 | mapMarkupT :: (m (a,Text.Blaze.Markup) -> n (b,Text.Blaze.Markup)) -> MarkupT m a -> MarkupT n b |
113 | mapMarkupT f = MarkupT . mapWriterT f . fromMarkupT | 135 | mapMarkupT f = MarkupT . mapWriterT f . fromMarkupT |
114 | {-# INLINE mapMarkupT #-} | 136 | {-# INLINE mapMarkupT #-} |
115 | 137 | ||
116 | type MarkupM = MarkupT Identity | 138 | type MarkupM a = forall m . Monad m => MarkupT m a |
117 | type Markup = forall m . Monad m => MarkupT m () | 139 | type Markup = MarkupM () |
118 | type Markup2 = forall m . Monad m => MarkupT m () -> MarkupT m () | 140 | type Markup2 = forall m . Monad m => MarkupT m () -> MarkupT m () |
119 | 141 | ||
120 | runMarkupT :: MarkupT m a -> m (a,B.Markup) | 142 | runMarkupT :: MarkupT m a -> m (a,Text.Blaze.Markup) |
121 | runMarkupT = runWriterT . fromMarkupT | 143 | runMarkupT = runWriterT . fromMarkupT |
122 | {-# INLINE runMarkupT #-} | 144 | {-# INLINE runMarkupT #-} |
123 | 145 | ||
124 | execMarkupT :: 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' | ||
149 | runWith :: Monad m => (Markup -> c) -> MarkupT m a -> m (a, c) | ||
150 | runWith renderer = liftM (second $ \x -> renderer $ wrapMarkup x) . runMarkupT | ||
151 | {-# INLINE runWith #-} | ||
152 | |||
153 | execMarkupT :: Monad m => MarkupT m a -> m Text.Blaze.Markup | ||
125 | execMarkupT = liftM snd . runMarkupT | 154 | execMarkupT = liftM snd . runMarkupT |
126 | {-# INLINE execMarkupT #-} | 155 | {-# INLINE execMarkupT #-} |
127 | 156 | ||
128 | runMarkup :: MarkupM a -> (a,B.Markup) | 157 | execWith :: Monad m => (Markup -> c) -> MarkupT m a -> m c |
158 | execWith renderer = liftM snd . runWith renderer | ||
159 | {-# INLINE execWith #-} | ||
160 | |||
161 | runMarkup :: MarkupI a -> (a, Text.Blaze.Markup) | ||
129 | runMarkup = runIdentity . runMarkupT | 162 | runMarkup = runIdentity . runMarkupT |
130 | {-# INLINE runMarkup #-} | 163 | {-# INLINE runMarkup #-} |
131 | 164 | ||
132 | execMarkup :: MarkupM a -> B.Markup | 165 | execMarkup :: MarkupI a -> Text.Blaze.Markup |
133 | execMarkup = snd . runMarkup | 166 | execMarkup = snd . runMarkup |
134 | {-# INLINE execMarkup #-} | 167 | {-# INLINE execMarkup #-} |
135 | 168 | ||
136 | -- instance MonadTrans MarkupT where | ||
137 | |||
138 | 169 | ||
139 | instance (Monad m,Monoid a) => Monoid (MarkupT m a) where | 170 | instance (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 | ||
146 | instance Monad m => B.Attributable (MarkupT m a) where | 177 | instance 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 | ||
150 | instance Monad m => B.Attributable (a -> MarkupT m b) where | 181 | instance 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 | ||
154 | instance Monad m => IsString (MarkupT m ()) where | 185 | instance Monad m => IsString (MarkupT m ()) where |
155 | fromString = wrapMarkup . fromString | 186 | fromString = wrapMarkup . fromString |
156 | {-# INLINE fromString #-} | 187 | {-# INLINE fromString #-} |
157 | 188 | ||
158 | wrapMarkupT :: Monad m => B.Markup -> MarkupT m () | 189 | -- | Wrapper for 'Text.Blaze.Markup' is simply |
190 | -- 'tell' | ||
191 | wrapMarkupT :: Monad m => Text.Blaze.Markup -> MarkupT m () | ||
159 | wrapMarkupT = tell | 192 | wrapMarkupT = tell |
160 | {-# INLINE wrapMarkupT #-} | 193 | {-# INLINE wrapMarkupT #-} |
161 | 194 | ||
162 | wrapMarkup :: B.Markup -> Markup | 195 | wrapMarkup :: Text.Blaze.Markup -> Markup |
163 | wrapMarkup = wrapMarkupT | 196 | wrapMarkup = wrapMarkupT |
164 | {-# INLINE wrapMarkup #-} | 197 | {-# INLINE wrapMarkup #-} |
165 | 198 | ||
166 | wrapMarkupT2 :: Monad m => (B.Markup -> B.Markup) | 199 | |
200 | -- | Wrapper for functions that modify 'Text.Blaze.Markup' is simply | ||
201 | -- 'censor' | ||
202 | wrapMarkupT2 :: Monad m => (Text.Blaze.Markup -> Text.Blaze.Markup) | ||
167 | -> MarkupT m a -> MarkupT m a | 203 | -> MarkupT m a -> MarkupT m a |
168 | wrapMarkupT2 = censor | 204 | wrapMarkupT2 = censor |
169 | {-# INLINE wrapMarkupT2 #-} | 205 | {-# INLINE wrapMarkupT2 #-} |
170 | 206 | ||
171 | wrapMarkup2 :: (B.Markup -> B.Markup) -> Markup2 | 207 | wrapMarkup2 :: (Text.Blaze.Markup -> Text.Blaze.Markup) -> Markup2 |
172 | wrapMarkup2 = wrapMarkupT2 | 208 | wrapMarkup2 = wrapMarkupT2 |
173 | {-# INLINE wrapMarkup2 #-} | 209 | {-# INLINE wrapMarkup2 #-} |
174 | 210 | ||
175 | unsafeByteString :: BS.ByteString -> Markup | 211 | unsafeByteString :: BS.ByteString -> Markup |
176 | unsafeByteString = wrapMarkup . B.unsafeByteString | 212 | unsafeByteString = 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 | -- |
182 | unsafeLazyByteString :: BL.ByteString -- ^ Value to insert | 218 | unsafeLazyByteString :: BL.ByteString -- ^ Value to insert |
183 | -> Markup -- ^ Resulting HTML fragment | 219 | -> Markup -- ^ Resulting HTML fragment |
184 | unsafeLazyByteString = wrapMarkup . B.unsafeLazyByteString | 220 | unsafeLazyByteString = wrapMarkup . Text.Blaze.unsafeLazyByteString |
185 | {-# INLINE unsafeLazyByteString #-} | 221 | {-# INLINE unsafeLazyByteString #-} |
186 | 222 | ||
187 | external :: Monad m => MarkupT m a -> MarkupT m a | 223 | external :: Monad m => MarkupT m a -> MarkupT m a |
188 | external = wrapMarkupT2 B.external | 224 | external = wrapMarkupT2 Text.Blaze.external |
189 | {-# INLINE external #-} | 225 | {-# INLINE external #-} |
190 | 226 | ||
191 | contents :: Monad m => MarkupT m a -> MarkupT m a | 227 | contents :: Monad m => MarkupT m a -> MarkupT m a |
192 | contents = wrapMarkupT2 B.contents | 228 | contents = wrapMarkupT2 Text.Blaze.contents |
193 | {-# INLINE contents #-} | 229 | {-# INLINE contents #-} |
194 | 230 | ||
195 | customParent ::B.Tag -> Markup2 | 231 | customParent ::Text.Blaze.Tag -> Markup2 |
196 | customParent = wrapMarkup2 . B.customParent | 232 | customParent = wrapMarkup2 . Text.Blaze.customParent |
197 | {-# INLINE customParent #-} | 233 | {-# INLINE customParent #-} |
198 | 234 | ||
199 | customLeaf :: B.Tag -> Bool -> Markup | 235 | customLeaf :: Text.Blaze.Tag -> Bool -> Markup |
200 | customLeaf = fmap wrapMarkup . B.customLeaf | 236 | customLeaf = fmap wrapMarkup . Text.Blaze.customLeaf |
201 | {-# INLINE customLeaf #-} | 237 | {-# INLINE customLeaf #-} |
202 | 238 | ||
203 | preEscapedText :: T.Text -> Markup | 239 | preEscapedText :: T.Text -> Markup |
204 | preEscapedText = wrapMarkup . B.preEscapedText | 240 | preEscapedText = wrapMarkup . Text.Blaze.preEscapedText |
205 | {-# INLINE preEscapedText #-} | 241 | {-# INLINE preEscapedText #-} |
206 | 242 | ||
207 | preEscapedLazyText :: LT.Text -> Markup | 243 | preEscapedLazyText :: LT.Text -> Markup |
208 | preEscapedLazyText = wrapMarkup . B.preEscapedLazyText | 244 | preEscapedLazyText = wrapMarkup . Text.Blaze.preEscapedLazyText |
209 | {-# INLINE preEscapedLazyText #-} | 245 | {-# INLINE preEscapedLazyText #-} |
210 | 246 | ||
211 | preEscapedTextBuilder :: LTB.Builder -> Markup | 247 | preEscapedTextBuilder :: LTB.Builder -> Markup |
212 | textBuilder :: LTB.Builder -> Markup | 248 | textBuilder :: LTB.Builder -> Markup |
213 | 249 | ||
214 | #ifdef PRE_BUILDER | 250 | #ifdef PRE_BUILDER |
215 | preEscapedTextBuilder = wrapMarkup . B.preEscapedTextBuilder | 251 | preEscapedTextBuilder = wrapMarkup . Text.Blaze.preEscapedTextBuilder |
216 | textBuilder = wrapMarkup . B.textBuilder | 252 | textBuilder = 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 | ||
224 | preEscapedString :: String -> Markup | 260 | preEscapedString :: String -> Markup |
225 | preEscapedString = wrapMarkup . B.preEscapedString | 261 | preEscapedString = wrapMarkup . Text.Blaze.preEscapedString |
226 | {-# INLINE preEscapedString #-} | 262 | {-# INLINE preEscapedString #-} |
227 | 263 | ||
228 | string :: String -> Markup | 264 | string :: String -> Markup |
229 | string = wrapMarkup . B.string | 265 | string = wrapMarkup . Text.Blaze.string |
230 | {-# INLINE string #-} | 266 | {-# INLINE string #-} |
231 | 267 | ||
232 | text :: T.Text -> Markup | 268 | text :: T.Text -> Markup |
233 | text = wrapMarkup . B.text | 269 | text = wrapMarkup . Text.Blaze.text |
234 | {-# INLINE text #-} | 270 | {-# INLINE text #-} |
235 | 271 | ||
236 | lazyText :: LT.Text -> Markup | 272 | lazyText :: LT.Text -> Markup |
237 | lazyText = wrapMarkup . B.lazyText | 273 | lazyText = 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 #-} | ||
1 | module Text.BlazeT.Renderer.Pretty | 2 | module Text.BlazeT.Renderer.Pretty |
2 | ( renderMarkup | 3 | ( renderMarkup |
3 | , renderHtml | 4 | , renderHtml |
4 | , renderMarkupT | ||
5 | , renderHtmlT | ||
6 | ) where | 5 | ) where |
7 | 6 | ||
8 | import Control.Monad | ||
9 | import Control.Monad.Identity | ||
10 | import qualified Text.Blaze.Renderer.Pretty as BU | 7 | import qualified Text.Blaze.Renderer.Pretty as BU |
11 | import Text.BlazeT | 8 | import Text.BlazeT |
12 | 9 | ||
13 | renderMarkup :: MarkupM a -> String | 10 | renderMarkup :: MarkupM a -> String |
14 | renderMarkup = runIdentity . renderMarkupT | 11 | renderMarkup = BU.renderMarkup . execMarkup |
15 | renderMarkupT :: Monad m => MarkupT m a -> m String | ||
16 | renderMarkupT = liftM BU.renderMarkup . execMarkupT | ||
17 | 12 | ||
18 | renderHtml :: MarkupM a -> String | 13 | renderHtml :: MarkupM a -> String |
19 | renderHtml = renderMarkup | 14 | renderHtml = renderMarkup |
20 | renderHtmlT :: Monad m => MarkupT m a -> m String | ||
21 | renderHtmlT = 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 #-} | ||
1 | module Text.BlazeT.Renderer.String | 2 | module 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 | ||
9 | import Control.Monad | ||
10 | import Control.Monad.Identity | ||
11 | import Text.Blaze.Internal (ChoiceString) | 8 | import Text.Blaze.Internal (ChoiceString) |
12 | import qualified Text.Blaze.Renderer.String as BU | 9 | import qualified Text.Blaze.Renderer.String as BU |
13 | import Text.BlazeT | 10 | import Text.BlazeT |
@@ -16,12 +13,8 @@ fromChoiceString :: ChoiceString -> String -> String | |||
16 | fromChoiceString = BU.fromChoiceString | 13 | fromChoiceString = BU.fromChoiceString |
17 | 14 | ||
18 | renderMarkup :: MarkupM a -> String | 15 | renderMarkup :: MarkupM a -> String |
19 | renderMarkup = runIdentity . renderMarkupT | 16 | renderMarkup = BU.renderMarkup . execMarkup |
20 | renderMarkupT :: Monad m => MarkupT m a -> m String | ||
21 | renderMarkupT = liftM BU.renderMarkup . execMarkupT | ||
22 | 17 | ||
23 | renderHtml :: MarkupM a -> String | 18 | renderHtml :: MarkupM a -> String |
24 | renderHtml = renderMarkup | 19 | renderHtml = renderMarkup |
25 | renderHtmlT :: Monad m => MarkupT m a -> m String | ||
26 | renderHtmlT = 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 #-} | ||
1 | module Text.BlazeT.Renderer.Text | 2 | module 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 | ||
20 | import Control.Monad | ||
21 | import Data.ByteString (ByteString) | 13 | import Data.ByteString (ByteString) |
22 | import Control.Monad.Identity | ||
23 | import Data.Text (Text) | 14 | import Data.Text (Text) |
24 | import qualified Data.Text.Lazy as L | 15 | import qualified Data.Text.Lazy as L |
25 | import qualified Data.Text.Lazy.Builder as B | 16 | import qualified Data.Text.Lazy.Builder as B |
@@ -28,48 +19,26 @@ import qualified Text.Blaze.Renderer.Text as BU | |||
28 | import Text.BlazeT | 19 | import Text.BlazeT |
29 | 20 | ||
30 | renderMarkupBuilder :: MarkupM a -> B.Builder | 21 | renderMarkupBuilder :: MarkupM a -> B.Builder |
31 | renderMarkupBuilder = runIdentity . renderMarkupBuilderT | 22 | renderMarkupBuilder = BU.renderMarkupBuilder . execMarkup |
32 | |||
33 | renderMarkupBuilderT :: Monad m => MarkupT m a -> m B.Builder | ||
34 | renderMarkupBuilderT = liftM BU.renderMarkupBuilder . execMarkupT | ||
35 | 23 | ||
36 | renderHtmlBuilder :: MarkupM a -> B.Builder | 24 | renderHtmlBuilder :: MarkupM a -> B.Builder |
37 | renderHtmlBuilder = renderMarkupBuilder | 25 | renderHtmlBuilder = renderMarkupBuilder |
38 | 26 | ||
39 | renderHtmlBuilderT :: Monad m => MarkupT m a -> m B.Builder | ||
40 | renderHtmlBuilderT = renderMarkupBuilderT | ||
41 | |||
42 | renderMarkup :: MarkupM a -> L.Text | 27 | renderMarkup :: MarkupM a -> L.Text |
43 | renderMarkup = runIdentity . renderMarkupT | 28 | renderMarkup = BU.renderMarkup . execMarkup |
44 | renderMarkupT :: Monad m => MarkupT m a -> m L.Text | ||
45 | renderMarkupT = liftM BU.renderMarkup . execMarkupT | ||
46 | 29 | ||
47 | renderHtml :: MarkupM a -> L.Text | 30 | renderHtml :: MarkupM a -> L.Text |
48 | renderHtml = renderMarkup | 31 | renderHtml = renderMarkup |
49 | renderHtmlT :: Monad m => MarkupT m a -> m L.Text | ||
50 | renderHtmlT = renderMarkupT | ||
51 | |||
52 | renderMarkupWithT :: Monad m => (ByteString -> Text) -> MarkupT m a -> m L.Text | ||
53 | renderMarkupWithT g = liftM (BU.renderMarkupWith g) . execMarkupT | ||
54 | 32 | ||
55 | renderMarkupWith :: (ByteString -> Text) -> MarkupM a -> L.Text | 33 | renderMarkupWith :: (ByteString -> Text) -> MarkupM a -> L.Text |
56 | renderMarkupWith g = runIdentity . renderMarkupWithT g | 34 | renderMarkupWith g = (BH.renderHtmlWith g) . execMarkup |
57 | |||
58 | renderHtmlWithT :: Monad m => (ByteString -> Text) -> MarkupT m a -> m L.Text | ||
59 | renderHtmlWithT g = liftM (BH.renderHtmlWith g) . execMarkupT | ||
60 | 35 | ||
61 | renderHtmlWith :: (ByteString -> Text) -> MarkupM a -> L.Text | 36 | renderHtmlWith :: (ByteString -> Text) -> MarkupM a -> L.Text |
62 | renderHtmlWith g = runIdentity . renderHtmlWithT g | 37 | renderHtmlWith = renderMarkupWith |
63 | |||
64 | renderHtmlBuilderWithT :: Monad m => (ByteString -> Text) -> MarkupT m a -> m B.Builder | ||
65 | renderHtmlBuilderWithT g = liftM (BH.renderHtmlBuilderWith g) . execMarkupT | ||
66 | |||
67 | renderHtmlBuilderWith :: (ByteString -> Text) -> MarkupM a -> B.Builder | ||
68 | renderHtmlBuilderWith g = runIdentity . renderHtmlBuilderWithT g | ||
69 | 38 | ||
39 | renderMarkupBuilderWith :: (ByteString -> Text) -> MarkupM a -> B.Builder | ||
40 | renderMarkupBuilderWith g = (BU.renderMarkupBuilderWith g) . execMarkup | ||
70 | 41 | ||
71 | renderMarkupBuilderWithT :: Monad m => (ByteString -> Text) -> MarkupT m a -> m B.Builder | 42 | renderHtmlBuilderWith :: (ByteString -> Text) -> MarkupM a -> B.Builder |
72 | renderMarkupBuilderWithT g = liftM (BU.renderMarkupBuilderWith g) . execMarkupT | 43 | renderHtmlBuilderWith = renderHtmlBuilderWith |
73 | 44 | ||
74 | renderMarkupBuilderWith :: (ByteString -> Text) -> MarkupM a -> B.Builder | ||
75 | renderMarkupBuilderWith 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 | ||
26 | import qualified Blaze.ByteString.Builder as B | 19 | import qualified Blaze.ByteString.Builder as B |
27 | import Control.Monad | ||
28 | import Control.Monad.Identity | ||
29 | import qualified Data.ByteString as BS | 20 | import qualified Data.ByteString as BS |
30 | import qualified Data.ByteString.Lazy as BL | 21 | import qualified Data.ByteString.Lazy as BL |
31 | import qualified Text.Blaze.Renderer.Utf8 as BU | 22 | import qualified Text.Blaze.Renderer.Utf8 as BU |
32 | import Text.BlazeT | 23 | import Text.BlazeT |
33 | 24 | ||
34 | renderMarkupBuilder :: MarkupM a -> B.Builder | 25 | renderMarkupBuilder :: MarkupM a -> B.Builder |
35 | renderMarkupBuilder = runIdentity . renderMarkupBuilderT | 26 | renderMarkupBuilder = BU.renderMarkupBuilder . execMarkup |
36 | |||
37 | renderMarkupBuilderT :: Monad m => MarkupT m a -> m B.Builder | ||
38 | renderMarkupBuilderT = liftM BU.renderMarkupBuilder . execMarkupT | ||
39 | 27 | ||
40 | renderHtmlBuilder :: MarkupM a -> B.Builder | 28 | renderHtmlBuilder :: MarkupM a -> B.Builder |
41 | renderHtmlBuilder = renderMarkupBuilder | 29 | renderHtmlBuilder = renderMarkupBuilder |
42 | 30 | ||
43 | renderHtmlBuilderT :: Monad m => MarkupT m a -> m B.Builder | ||
44 | renderHtmlBuilderT = renderMarkupBuilderT | ||
45 | |||
46 | renderMarkup :: MarkupM a -> BL.ByteString | 31 | renderMarkup :: MarkupM a -> BL.ByteString |
47 | renderMarkup = runIdentity . renderMarkupT | 32 | renderMarkup = BU.renderMarkup . execMarkup |
48 | renderMarkupT :: Monad m => MarkupT m a -> m BL.ByteString | ||
49 | renderMarkupT = liftM BU.renderMarkup . execMarkupT | ||
50 | 33 | ||
51 | renderHtml :: MarkupM a -> BL.ByteString | 34 | renderHtml :: MarkupM a -> BL.ByteString |
52 | renderHtml = renderMarkup | 35 | renderHtml = renderMarkup |
53 | renderHtmlT :: Monad m => MarkupT m a -> m BL.ByteString | ||
54 | renderHtmlT = renderMarkupT | ||
55 | 36 | ||
56 | renderMarkupToByteStringIO :: (BS.ByteString -> IO ()) -> MarkupM a -> IO () | 37 | renderMarkupToByteStringIO :: (BS.ByteString -> IO ()) -> MarkupM a -> IO () |
57 | renderMarkupToByteStringIO g = runIdentity . renderMarkupToByteStringIOT g | 38 | renderMarkupToByteStringIO g = BU.renderMarkupToByteStringIO g . execMarkup |
58 | renderMarkupToByteStringIOT :: Monad m => (BS.ByteString -> IO ()) -> | ||
59 | MarkupT m a -> m (IO ()) | ||
60 | renderMarkupToByteStringIOT g = liftM (BU.renderMarkupToByteStringIO g) . execMarkupT | ||
61 | 39 | ||
62 | renderHtmlToByteStringIO :: (BS.ByteString -> IO ()) -> MarkupM a -> IO () | 40 | renderHtmlToByteStringIO :: (BS.ByteString -> IO ()) -> MarkupM a -> IO () |
63 | renderHtmlToByteStringIO g = runIdentity . renderMarkupToByteStringIOT g | 41 | renderHtmlToByteStringIO = renderMarkupToByteStringIO |
64 | renderHtmlToByteStringIOT :: Monad m => (BS.ByteString -> IO ()) -> | ||
65 | MarkupT m a -> m (IO ()) | ||
66 | renderHtmlToByteStringIOT g = liftM (BU.renderMarkupToByteStringIO g) . execMarkupT | ||