blaze-markup 0.6.2.0 → 0.6.3.0
raw patch · 9 files changed
+99/−9 lines, 9 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ Text.Blaze: lazyText :: Text -> Markup
+ Text.Blaze: lazyTextComment :: Text -> Markup
+ Text.Blaze: lazyTextValue :: Text -> AttributeValue
+ Text.Blaze: preEscapedLazyText :: Text -> Markup
+ Text.Blaze: preEscapedLazyTextValue :: Text -> AttributeValue
+ Text.Blaze: preEscapedString :: String -> Markup
+ Text.Blaze: preEscapedStringValue :: String -> AttributeValue
+ Text.Blaze: preEscapedText :: Text -> Markup
+ Text.Blaze: preEscapedTextValue :: Text -> AttributeValue
+ Text.Blaze: string :: String -> Markup
+ Text.Blaze: stringComment :: String -> Markup
+ Text.Blaze: stringValue :: String -> AttributeValue
+ Text.Blaze: text :: Text -> Markup
+ Text.Blaze: textComment :: Text -> Markup
+ Text.Blaze: textValue :: Text -> AttributeValue
+ Text.Blaze: unsafeByteStringComment :: ByteString -> Markup
+ Text.Blaze: unsafeLazyByteStringComment :: ByteString -> Markup
+ Text.Blaze.Internal: Comment :: ChoiceString -> MarkupM a
+ Text.Blaze.Internal: lazyTextComment :: Text -> Markup
+ Text.Blaze.Internal: stringComment :: String -> Markup
+ Text.Blaze.Internal: textComment :: Text -> Markup
+ Text.Blaze.Internal: unsafeByteStringComment :: ByteString -> Markup
+ Text.Blaze.Internal: unsafeLazyByteStringComment :: ByteString -> Markup
Files
- CHANGELOG +3/−0
- blaze-markup.cabal +1/−1
- src/Text/Blaze.hs +28/−7
- src/Text/Blaze/Internal.hs +42/−0
- src/Text/Blaze/Renderer/Pretty.hs +2/−0
- src/Text/Blaze/Renderer/String.hs +3/−1
- src/Text/Blaze/Renderer/Text.hs +4/−0
- src/Text/Blaze/Renderer/Utf8.hs +4/−0
- tests/Text/Blaze/Tests.hs +12/−0
CHANGELOG view
@@ -1,3 +1,6 @@+- 0.6.3.0+ * Add combinators to insert HTML comments+ - 0.6.2.0 * Add `Applicative` instance for `MarkupM`
blaze-markup.cabal view
@@ -1,5 +1,5 @@ Name: blaze-markup-Version: 0.6.2.0+Version: 0.6.3.0 Homepage: http://jaspervdj.be/blaze Bug-Reports: http://github.com/jaspervdj/blaze-markup/issues License: BSD3
src/Text/Blaze.hs view
@@ -1,4 +1,6 @@-{-# LANGUAGE FlexibleInstances, TypeSynonymInstances #-}+{-# LANGUAGE FlexibleInstances #-}+{-# LANGUAGE OverloadedStrings #-}+{-# LANGUAGE TypeSynonymInstances #-} -- | BlazeMarkup is a markup combinator library. It provides a way to embed -- markup languages like HTML and SVG in Haskell in an efficient and convenient -- way, with a light-weight syntax.@@ -46,15 +48,34 @@ -- * Converting values to Markup. , ToMarkup (..)+ , text+ , preEscapedText+ , lazyText+ , preEscapedLazyText+ , string+ , preEscapedString , unsafeByteString , unsafeLazyByteString + -- * Comments+ , textComment+ , lazyTextComment+ , stringComment+ , unsafeByteStringComment+ , unsafeLazyByteStringComment+ -- * Creating tags. , textTag , stringTag -- * Converting values to attribute values. , ToValue (..)+ , textValue+ , preEscapedTextValue+ , lazyTextValue+ , preEscapedLazyTextValue+ , stringValue+ , preEscapedStringValue , unsafeByteStringValue , unsafeLazyByteStringValue @@ -66,14 +87,14 @@ , contents ) where -import Data.Monoid (mconcat)-import Data.Int (Int32, Int64)-import Data.Word (Word, Word32, Word64)+import Data.Int (Int32, Int64)+import Data.Monoid (mconcat)+import Data.Word (Word, Word32, Word64) -import Data.Text (Text)-import qualified Data.Text.Lazy as LT+import Data.Text (Text)+import qualified Data.Text.Lazy as LT -import Text.Blaze.Internal+import Text.Blaze.Internal -- | Class allowing us to use a single function for Markup values --
src/Text/Blaze/Internal.hs view
@@ -36,6 +36,13 @@ , unsafeByteString , unsafeLazyByteString + -- * Comments+ , textComment+ , lazyTextComment+ , stringComment+ , unsafeByteStringComment+ , unsafeLazyByteStringComment+ -- * Converting values to tags. , textTag , stringTag@@ -137,6 +144,9 @@ | CustomLeaf ChoiceString Bool -- | HTML content | Content ChoiceString+ -- | HTML comment. Note: you should wrap the 'ChoiceString' in a+ -- 'PreEscaped'.+ | Comment ChoiceString -- | Concatenation of two HTML pieces | forall b c. Append (MarkupM b) (MarkupM c) -- | Add an attribute to the inner HTML. Raw key, key, value, HTML to@@ -328,6 +338,37 @@ unsafeLazyByteString = mconcat . map unsafeByteString . BL.toChunks {-# INLINE unsafeLazyByteString #-} +-- | Create a comment from a 'Text' value.+-- The text should not contain @"--"@.+-- This is not checked by the library.+textComment :: Text -> Markup+textComment = Comment . PreEscaped . Text++-- | Create a comment from a 'LT.Text' value.+-- The text should not contain @"--"@.+-- This is not checked by the library.+lazyTextComment :: LT.Text -> Markup+lazyTextComment = Comment . mconcat . map (PreEscaped . Text) . LT.toChunks++-- | Create a comment from a 'String' value.+-- The text should not contain @"--"@.+-- This is not checked by the library.+stringComment :: String -> Markup+stringComment = Comment . PreEscaped . String++-- | Create a comment from a 'ByteString' value.+-- The text should not contain @"--"@.+-- This is not checked by the library.+unsafeByteStringComment :: ByteString -> Markup+unsafeByteStringComment = Comment . PreEscaped . ByteString++-- | Create a comment from a 'BL.ByteString' value.+-- The text should not contain @"--"@.+-- This is not checked by the library.+unsafeLazyByteStringComment :: BL.ByteString -> Markup+unsafeLazyByteStringComment =+ Comment . mconcat . map (PreEscaped . ByteString) . BL.toChunks+ -- | Create a 'Tag' from some 'Text'. -- textTag :: Text -- ^ Text to create a tag from@@ -489,6 +530,7 @@ Leaf _ _ _ -> False CustomLeaf _ _ -> False Content c -> emptyChoiceString c+ Comment c -> emptyChoiceString c Append c1 c2 -> null c1 && null c2 AddAttribute _ _ _ c -> null c AddCustomAttribute _ _ c -> null c
src/Text/Blaze/Renderer/Pretty.hs view
@@ -34,6 +34,8 @@ (' ' : ) . fromChoiceString key . ("=\"" ++) . fromChoiceString value . ('"' :) . attrs go i _ (Content content) = ind i . fromChoiceString content . ('\n' :)+ go i _ (Comment comment) = ind i .+ ("<!-- " ++) . fromChoiceString comment . (" -->\n" ++) go i attrs (Append h1 h2) = go i attrs h1 . go i attrs h2 go _ _ Empty = id {-# NOINLINE go #-}
src/Text/Blaze/Renderer/String.hs view
@@ -59,7 +59,7 @@ renderString :: Markup -- ^ Markup to render -> String -- ^ String to append -> String -- ^ Resulting String-renderString = go id +renderString = go id where go :: (String -> String) -> MarkupM b -> String -> String go attrs (Parent _ open close content) =@@ -77,6 +77,8 @@ (' ' :) . fromChoiceString key . ("=\"" ++) . fromChoiceString value . ('"' :) . attrs go _ (Content content) = fromChoiceString content+ go _ (Comment comment) =+ ("<!-- " ++) . fromChoiceString comment . (" -->" ++) go attrs (Append h1 h2) = go attrs h1 . go attrs h2 go _ Empty = id {-# NOINLINE go #-}
src/Text/Blaze/Renderer/Text.hs view
@@ -121,6 +121,10 @@ `mappend` B.singleton '"' `mappend` attrs) h go _ (Content content) = fromChoiceString d content+ go _ (Comment comment) =+ B.fromText "<!-- "+ `mappend` fromChoiceString d comment+ `mappend` " -->" go attrs (Append h1 h2) = go attrs h1 `mappend` go attrs h2 go _ Empty = mempty {-# NOINLINE go #-}
src/Text/Blaze/Renderer/Utf8.hs view
@@ -87,6 +87,10 @@ `mappend` B.fromChar '"' `mappend` attrs) h go _ (Content content) = fromChoiceString content+ go _ (Comment comment) =+ B.fromByteString "<!-- "+ `mappend` fromChoiceString comment+ `mappend` B.fromByteString " -->" go attrs (Append h1 h2) = go attrs h1 `mappend` go attrs h2 go _ Empty = mempty {-# NOINLINE go #-}
tests/Text/Blaze/Tests.hs view
@@ -23,6 +23,7 @@ import qualified Data.ByteString.Lazy as LB import qualified Data.ByteString.Lazy.Char8 as LBC +import Text.Blaze import Text.Blaze.Internal import Text.Blaze.Tests.Util @@ -42,6 +43,7 @@ , testCase "contents 1" contents1 , testCase "empty 1" empty1 , testCase "empty 2" empty2+ , testCase "comment 1" comment1 ] -- | The left identity Monoid law.@@ -139,6 +141,7 @@ html :: Markup html = div $ do p ! id "para" $ "Hello "+ stringComment "Test test" img ! name "An image" p "World!" @@ -156,6 +159,15 @@ where html :: Markup html = "" `mappend` "" `mappend` p "a"++comment1 :: Assertion+comment1 = preEscapedString "<div>Hello <!-- Test --> World!</div>" @=? html+ where+ html :: Markup+ html = div $ do+ "Hello "+ stringComment "Test"+ " World!" -- Show instance for the HTML type, so we can debug. --