packages feed

xml-hamlet 0.0.3 → 0.1.0

raw patch · 3 files changed

+144/−6 lines, 3 filesdep +xml-hamletdep ~xml-enumerator

Dependencies added: xml-hamlet

Dependency ranges changed: xml-enumerator

Files

Text/Hamlet/XML.hs view
@@ -13,7 +13,7 @@ import Text.Shakespeare.Base (readUtf8File, derefToExp, Scope, Deref (DerefIdent), Ident (Ident)) import Data.Text (pack, unpack) import qualified Data.Text as T-import qualified Text.XML.Enumerator.Resolved as X+import qualified Text.XML as X import Data.String (fromString) import qualified Data.Foldable as F import Data.Maybe (fromMaybe)
+ test/main.hs view
@@ -0,0 +1,135 @@+{-# LANGUAGE QuasiQuotes #-}+{-# LANGUAGE OverloadedStrings #-}+import Text.Hamlet.XML+import qualified Text.XML as X+import Test.HUnit+import Test.Hspec+import Test.Hspec.HUnit ()++main :: IO ()+main = hspecX $ describe "xml-hamlet"+    [ it "handles plain tags" $ [xml|+<foo>+        <baz+|] @?=+        [ X.NodeElement $ X.Element "foo" []+            [ X.NodeElement $ X.Element "baz" [] []+            ]+        ]+    , it "handles raw text" $ [xml|+<foo>+        <baz>bin+|] @?=+        [ X.NodeElement $ X.Element "foo" []+            [ X.NodeElement $ X.Element "baz" []+                [ X.NodeContent "bin"+                ]+            ]+        ]+    , it "handles variables" $ [xml|+<foo>+        <baz>#{bin}+|] @?=+        [ X.NodeElement $ X.Element "foo" []+            [ X.NodeElement $ X.Element "baz" []+                [ X.NodeContent "bin"+                ]+            ]+        ]+    , it "handles embed" $ [xml|+<foo>+        <baz>^{nodes}+|] @?=+        [ X.NodeElement $ X.Element "foo" []+            [ X.NodeElement $ X.Element "baz" [] nodes+            ]+        ]+    , it "handles attributes" $ [xml|+<foo>+    <bar here=there>+        <baz+|] @?=+        [ X.NodeElement $ X.Element "foo" []+            [ X.NodeElement $ X.Element "bar" [("here", "there")]+                [ X.NodeElement $ X.Element "baz" [] []+                ]+            ]+        ]+    , it "handles attributes" $ [xml|+<foo>+    <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")] []+                ]+            ]+        ]+    , it "handles forall" $ [xml|+$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"]+        ]+    , 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"]+        ]+    , it "handles maybe" $ [xml|+$maybe _x <- Just five+    <one>+$nothing+    <two>+$maybe _x <- Nothing+    <three>+$nothing+    <four>+    |] @?=+        [ X.NodeElement $ X.Element "one" [] []+        , X.NodeElement $ X.Element "four" [] []+        ]+    , it "handles conditionals" $ [xml|+$if True+    <one>+$else+    <two>++$if False+    <three>+$elseif True+    <four>++$if False+    <five>+$elseif False+    <six>+$else+    <seven>+|] @?=+        [ X.NodeElement $ X.Element "one" [] []+        , X.NodeElement $ X.Element "four" [] []+        , X.NodeElement $ X.Element "seven" [] []+        ]+    , it "recognizes clark notation" $ [xml|+<{foo}bar {baz}bin="x"+|] @?= [X.NodeElement $ X.Element "{foo}bar" [("{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" [] []]+    ]+  where+    bin = "bin"+    nodes = [X.NodeInstruction $ X.Instruction "ifoo" "ibar"]+    true = "true"+    xs = ["foo", "bar", "baz"]++five :: Int+five = 5
xml-hamlet.cabal view
@@ -1,5 +1,5 @@ Name:                xml-hamlet-Version:             0.0.3+Version:             0.1.0 Synopsis:            Hamlet-style quasiquoter for XML content Homepage:            http://www.yesodweb.com/ License:             BSD3@@ -9,6 +9,7 @@ Category:            Text Build-type:          Simple Description:         Hamlet-style quasiquoter for XML content+Extra-source-files:  test/main.hs  Cabal-version:       >=1.8 @@ -18,22 +19,24 @@      Build-depends:       base                       >= 4        && < 5                      , shakespeare                >= 0.10     && < 0.11-                     , xml-enumerator             >= 0.3.4    && < 0.4+                     , xml-enumerator             >= 0.4      && < 0.5                      , text                       >= 0.10     && < 1.0                      , template-haskell                      , parsec                     >= 2.0      && < 3.2    Ghc-options:         -Wall -test-suite runtests-  main-is:             runtests.hs+test-suite test+  main-is:             main.hs+  hs-source-dirs:      test   type:                exitcode-stdio-1.0   ghc-options:         -Wall   build-depends:       hspec >= 0.6.1 && < 0.7                      , HUnit                      >= 1.2      && < 1.3                      , base >= 4 && < 5                      , shakespeare                >= 0.10     && < 0.11-                     , xml-enumerator             >= 0.3.4    && < 0.4+                     , xml-enumerator             >= 0.4      && < 0.5                      , text                       >= 0.10     && < 1.0                      , template-haskell                      , parsec                     >= 2.0      && < 3.2+                     , xml-hamlet                 >= 0.1      && < 0.2