blaze-markup 0.5.2.1 → 0.6.0.0
raw patch · 5 files changed
+28/−1 lines, 5 files
Files
- CHANGELOG +3/−0
- blaze-markup.cabal +1/−1
- src/Text/Blaze.hs +1/−0
- src/Text/Blaze/Internal.hs +14/−0
- tests/Text/Blaze/Tests.hs +9/−0
CHANGELOG view
@@ -1,3 +1,6 @@+- 0.6.0.0+ * Add the operator (!?) for nicely setting conditional attributes+ - 0.5.2.0 * Provide ToHtml and ToValue instances for Int32, Int64, Word, Word32, and Word64
blaze-markup.cabal view
@@ -1,5 +1,5 @@ Name: blaze-markup-Version: 0.5.2.1+Version: 0.6.0.0 Homepage: http://jaspervdj.be/blaze Bug-Reports: http://github.com/jaspervdj/blaze-markup/issues License: BSD3
src/Text/Blaze.hs view
@@ -60,6 +60,7 @@ -- * Setting attributes , (!)+ , (!?) -- * Modifiying Markup trees , contents
src/Text/Blaze/Internal.hs view
@@ -53,6 +53,7 @@ -- * Setting attributes , Attributable , (!)+ , (!?) -- * Modifying Markup elements , contents@@ -411,6 +412,19 @@ instance Attributable (MarkupM a -> MarkupM b) where h ! f = (! f) . h {-# INLINE (!) #-}++-- | Shorthand for setting an attribute depending on a conditional.+--+-- Example:+--+-- > p !? (isBig, A.class "big") $ "Hello"+--+-- Gives the same result as:+--+-- > (if isBig then p ! A.class "big" else p) "Hello"+--+(!?) :: Attributable h => h -> (Bool, Attribute) -> h+(!?) h (c, a) = if c then h ! a else h -- | Mark HTML as external data. External data can be: --
tests/Text/Blaze/Tests.hs view
@@ -35,6 +35,7 @@ , testProperty "well nested <>" wellNestedBrackets , testProperty "unsafeByteString id" unsafeByteStringId + , testCase "conditional attributes" conditionalAttributes , testCase "contents 1" contents1 ] @@ -113,6 +114,14 @@ '<' -> if isOpen then False else wellNested True xs '>' -> if isOpen then wellNested False xs else False _ -> wellNested isOpen xs++conditionalAttributes :: Assertion+conditionalAttributes =+ "<p class=\"foo\">Hello</p><p id=\"2nd\">World</p>" @=? renderUsingUtf8 html+ where+ html = do+ p !? (4 > length [()], class_ "foo") $ "Hello"+ p !? (null [()], class_ "bar") !? (True, id "2nd") $ "World" contents1 :: Assertion contents1 = "Hello World!" @=? renderUsingUtf8 (contents html)