xml-hamlet 0.3.0.1 → 0.4.0
raw patch · 3 files changed
+37/−33 lines, 3 filesdep +containersdep ~xml-conduit
Dependencies added: containers
Dependency ranges changed: xml-conduit
Files
- Text/Hamlet/XML.hs +4/−3
- test/main.hs +29/−28
- xml-hamlet.cabal +4/−2
Text/Hamlet/XML.hs view
@@ -17,6 +17,7 @@ import Data.String (fromString) import qualified Data.Foldable as F import Data.Maybe (fromMaybe)+import qualified Data.Map as Map xml :: QuasiQuoter xml = QuasiQuoter { quoteExp = strToExp }@@ -76,11 +77,11 @@ return (NormalG $ derefToExp scope deref, inside') mkAttrs :: Scope -> [(Maybe Deref, String, [Content])] -> Q Exp-mkAttrs _ [] = [| [] |]+mkAttrs _ [] = [| Map.empty |] mkAttrs scope ((mderef, name, value):rest) = do rest' <- mkAttrs scope rest- this <- [| ($(liftName name), T.concat $(fmap ListE $ mapM go value)) |]- let with = [| $(return this) : $(return rest') |]+ this <- [| Map.insert $(liftName name) (T.concat $(fmap ListE $ mapM go value)) |]+ let with = [| $(return this) $(return rest') |] case mderef of Nothing -> with Just deref -> [| if $(return $ derefToExp scope deref) then $(with) else $(return rest') |]
test/main.hs view
@@ -3,8 +3,9 @@ import Text.Hamlet.XML import qualified Text.XML as X import Test.HUnit-import Test.Hspec+import Test.Hspec.Core import Test.Hspec.HUnit ()+import qualified Data.Map as Map main :: IO () main = hspecX [describe "xml-hamlet"@@ -12,16 +13,16 @@ <foo> <baz> |] @?=- [ X.NodeElement $ X.Element "foo" []- [ X.NodeElement $ X.Element "baz" [] []+ [ X.NodeElement $ X.Element "foo" Map.empty+ [ X.NodeElement $ X.Element "baz" Map.empty [] ] ] , it "handles raw text" $ [xml| <foo> <baz>bin |] @?=- [ X.NodeElement $ X.Element "foo" []- [ X.NodeElement $ X.Element "baz" []+ [ X.NodeElement $ X.Element "foo" Map.empty+ [ X.NodeElement $ X.Element "baz" Map.empty [ X.NodeContent "bin" ] ]@@ -30,8 +31,8 @@ <foo> <baz>#{bin} |] @?=- [ X.NodeElement $ X.Element "foo" []- [ X.NodeElement $ X.Element "baz" []+ [ X.NodeElement $ X.Element "foo" Map.empty+ [ X.NodeElement $ X.Element "baz" Map.empty [ X.NodeContent "bin" ] ]@@ -40,8 +41,8 @@ <foo> <baz>^{nodes} |] @?=- [ X.NodeElement $ X.Element "foo" []- [ X.NodeElement $ X.Element "baz" [] nodes+ [ X.NodeElement $ X.Element "foo" Map.empty+ [ X.NodeElement $ X.Element "baz" Map.empty nodes ] ] , it "handles attributes" $ [xml|@@ -49,9 +50,9 @@ <bar here=there> <baz> |] @?=- [ X.NodeElement $ X.Element "foo" []- [ X.NodeElement $ X.Element "bar" [("here", "there")]- [ X.NodeElement $ X.Element "baz" [] []+ [ X.NodeElement $ X.Element "foo" Map.empty+ [ X.NodeElement $ X.Element "bar" (Map.singleton "here" "there")+ [ X.NodeElement $ X.Element "baz" Map.empty [] ] ] ]@@ -60,9 +61,9 @@ <bar here=there> <baz :False:false=false :True:true=#{true}> |] @?=- [ X.NodeElement $ X.Element "foo" []- [ X.NodeElement $ X.Element "bar" [("here", "there")]- [ X.NodeElement $ X.Element "baz" [("true", "true")] []+ [ X.NodeElement $ X.Element "foo" Map.empty+ [ X.NodeElement $ X.Element "bar" (Map.singleton "here" "there")+ [ X.NodeElement $ X.Element "baz" (Map.singleton "true" "true") [] ] ] ]@@ -70,18 +71,18 @@ $forall x <- xs <word>#{x} |] @?=- [ X.NodeElement $ X.Element "word" [] [X.NodeContent "foo"]- , X.NodeElement $ X.Element "word" [] [X.NodeContent "bar"]- , X.NodeElement $ X.Element "word" [] [X.NodeContent "baz"]+ [ X.NodeElement $ X.Element "word" Map.empty [X.NodeContent "foo"]+ , X.NodeElement $ X.Element "word" Map.empty [X.NodeContent "bar"]+ , X.NodeElement $ X.Element "word" Map.empty [X.NodeContent "baz"] ] , it "handles with" $ [xml| $with ys <- xs $forall x <- ys <word>#{x} |] @?=- [ X.NodeElement $ X.Element "word" [] [X.NodeContent "foo"]- , X.NodeElement $ X.Element "word" [] [X.NodeContent "bar"]- , X.NodeElement $ X.Element "word" [] [X.NodeContent "baz"]+ [ X.NodeElement $ X.Element "word" Map.empty [X.NodeContent "foo"]+ , X.NodeElement $ X.Element "word" Map.empty [X.NodeContent "bar"]+ , X.NodeElement $ X.Element "word" Map.empty [X.NodeContent "baz"] ] , it "handles maybe" $ [xml| $maybe _x <- Just five@@ -93,8 +94,8 @@ $nothing <four> |] @?=- [ X.NodeElement $ X.Element "one" [] []- , X.NodeElement $ X.Element "four" [] []+ [ X.NodeElement $ X.Element "one" Map.empty []+ , X.NodeElement $ X.Element "four" Map.empty [] ] , it "handles conditionals" $ [xml| $if True@@ -114,16 +115,16 @@ $else <seven> |] @?=- [ X.NodeElement $ X.Element "one" [] []- , X.NodeElement $ X.Element "four" [] []- , X.NodeElement $ X.Element "seven" [] []+ [ X.NodeElement $ X.Element "one" Map.empty []+ , X.NodeElement $ X.Element "four" Map.empty []+ , X.NodeElement $ X.Element "seven" Map.empty [] ] , it "recognizes clark notation" $ [xml| <{foo}bar {baz}bin="x">-|] @?= [X.NodeElement $ X.Element "{foo}bar" [("{baz}bin", "x")] []]+|] @?= [X.NodeElement $ X.Element "{foo}bar" (Map.singleton "{baz}bin" "x") []] , it "recognizes clark with URLs" $ [xml| <{http://www.example.com/foo/bar}baz>-|] @?= [X.NodeElement $ X.Element "{http://www.example.com/foo/bar}baz" [] []]+|] @?= [X.NodeElement $ X.Element "{http://www.example.com/foo/bar}baz" Map.empty []] , it "allow embedding comments" $[xml|^{comment}|] @?= comment , it "multiline tags" $ [xml| <foo bar=baz
xml-hamlet.cabal view
@@ -1,5 +1,5 @@ Name: xml-hamlet-Version: 0.3.0.1+Version: 0.4.0 Synopsis: Hamlet-style quasiquoter for XML content Homepage: http://www.yesodweb.com/ License: BSD3@@ -19,10 +19,11 @@ Build-depends: base >= 4 && < 5 , shakespeare >= 1.0 && < 1.1- , xml-conduit >= 0.5 && < 0.8+ , xml-conduit >= 1.0 && < 1.1 , text >= 0.10 && < 1.0 , template-haskell , parsec >= 2.0 && < 3.2+ , containers Ghc-options: -Wall @@ -40,3 +41,4 @@ , template-haskell , parsec , xml-hamlet+ , containers