Permalink
Browse files

new examples

  • Loading branch information...
lymar committed Feb 11, 2012
1 parent 961ee5c commit 37cda41baa776e784c74a3f62c75b53a0d5d6321
Showing with 92 additions and 0 deletions.
  1. +39 −0 README.md
  2. +17 −0 README.md.ha
  3. +11 −0 example/conditionalBool.hs
  4. +11 −0 example/conditionalList.hs
  5. +14 −0 example/conditionalNumber.hs
View
@@ -108,6 +108,45 @@ context = mkGenericContext $ Heroes ["Nameless","Long Sky","Flying Snow",
"Broken Sword","Qin Shi Huang"]
```
+#### Conditional evaluation
+
+Boolean
+
+```haskell
+template = "{{#boolean}}true{{/boolean}}{{^boolean}}false{{/boolean}}"
+context "boolean" = MuBool False
+```
+```
+false
+```
+
+List
+
+```haskell
+template = "{{^messages}}No new messages{{/messages}}"
+context "messages" = MuList []
+```
+```
+No new messages
+```
+
+Number
+
+```haskell
+main = mapM_ (\ctx ->
+ hastacheStr defaultConfig (encodeStr template) (mkStrContext ctx)
+ >>= LZ.putStrLn) [context1,context2]
+
+template = "{{#msg}}{{msg}}{{/msg}}{{^msg}}No{{/msg}} new messages."
+
+context1 "msg" = MuVariable (100 :: Int)
+context2 "msg" = MuVariable (0 :: Int)
+```
+```
+100 new messages.
+No new messages.
+```
+
#### Functions
```haskell
View
@@ -37,6 +37,23 @@ Another Generics version
{{#example}}listsGeneric.2{{/example}}
+#### Conditional evaluation
+
+Boolean
+
+{{#example}}conditionalBool{{/example}}
+{{#runExample}}conditionalBool{{/runExample}}
+
+List
+
+{{#example}}conditionalList{{/example}}
+{{#runExample}}conditionalList{{/runExample}}
+
+Number
+
+{{#example}}conditionalNumber{{/example}}
+{{#runExample}}conditionalNumber{{/runExample}}
+
#### Functions
{{#example}}function{{/example}}
View
@@ -0,0 +1,11 @@
+#!/usr/local/bin/runhaskell
+import Text.Hastache
+import Text.Hastache.Context
+import qualified Data.ByteString.Lazy as LZ
+
+main = hastacheStr defaultConfig (encodeStr template) (mkStrContext context)
+ >>= LZ.putStrLn
+
+-- begin example
+template = "{{#boolean}}true{{/boolean}}{{^boolean}}false{{/boolean}}"
+context "boolean" = MuBool False
View
@@ -0,0 +1,11 @@
+#!/usr/local/bin/runhaskell
+import Text.Hastache
+import Text.Hastache.Context
+import qualified Data.ByteString.Lazy as LZ
+
+main = hastacheStr defaultConfig (encodeStr template) (mkStrContext context)
+ >>= LZ.putStrLn
+
+-- begin example
+template = "{{^messages}}No new messages{{/messages}}"
+context "messages" = MuList []
@@ -0,0 +1,14 @@
+#!/usr/local/bin/runhaskell
+import Text.Hastache
+import Text.Hastache.Context
+import qualified Data.ByteString.Lazy as LZ
+
+-- begin example
+main = mapM_ (\ctx ->
+ hastacheStr defaultConfig (encodeStr template) (mkStrContext ctx)
+ >>= LZ.putStrLn) [context1,context2]
+
+template = "{{#msg}}{{msg}}{{/msg}}{{^msg}}No{{/msg}} new messages."
+
+context1 "msg" = MuVariable (100 :: Int)
+context2 "msg" = MuVariable (0 :: Int)

0 comments on commit 37cda41

Please sign in to comment.