packages feed

heist-aeson 0.4 → 0.5

raw patch · 5 files changed

+35/−10 lines, 5 filesdep ~heistPVP ok

version bump matches the API change (PVP)

Dependency ranges changed: heist

API changes (from Hackage documentation)

Files

heist-aeson.cabal view
@@ -7,7 +7,7 @@ -- The package version. See the Haskell package versioning policy -- (http://www.haskell.org/haskellwiki/Package_versioning_policy) for -- standards guiding when and how versions should be incremented.-Version:             0.4+Version:             0.5  -- A short (one-line) description of the package. Synopsis:            Use JSON directly from Heist templates.@@ -57,7 +57,7 @@    -- Packages needed in order to build this package.   Build-depends:       base >= 4 && < 5, aeson, monads-fd, text, xmlhtml,-                       bytestring, vector, containers, blaze-builder, heist+                       bytestring, vector, containers, blaze-builder, heist >= 0.5.1.1      ghc-options:         -fwarn-unused-binds -fwarn-unused-imports 
src/Text/Templating/Heist/Aeson.hs view
@@ -11,17 +11,14 @@     ) where  import Data.Aeson                            ( Value(..), Array )-import Text.Templating.Heist                 ( TemplateState, TemplateMonad-                                             , Splice, getParamNode, MIMEType-                                             , renderTemplate, bindSplices-                                             , runChildren )+import Text.Templating.Heist import Blaze.ByteString.Builder              ( Builder ) import qualified Data.Map as Map             ( lookup ) import qualified Data.Vector as V            ( forM, toList )  import qualified Data.ByteString as Strict   ( ByteString ) -import qualified Text.XmlHtml as X           ( Node(..), elementAttrs )+import qualified Text.XmlHtml as X import qualified Data.Text as T              ( Text, append, pack, splitOn )  import Control.Monad.Reader                  ( ReaderT, ask, local, runReaderT )@@ -44,7 +41,7 @@  withValue :: Monad m => Value -> JsonSpliceT m -> JsonSpliceT m withValue value-    = local $ \input -> input{jsonCurrent = value, jsonHistory = value : jsonHistory input}+    = local $ \input -> input{jsonCurrent = value, jsonHistory = jsonCurrent input : jsonHistory input}  jsonSplice :: Monad m => JsonSpliceT m jsonSplice@@ -134,9 +131,22 @@                   Object object | Just value <- Map.lookup key object                     -> worker value (current:history) xs                   _ -> Nothing-                              ++bindStrict :: Monad m => Splice m+bindStrict = do+    node <- getParamNode+    cs <- runChildren+    maybe (return ()) (add cs)+          (X.getAttribute "tag" node)+    return []++  where+    add cs nm = modifyTS $ bindSplice nm $ do+        return cs+ addHeistAeson :: Monad m => JsonState m -> JsonState m-addHeistAeson = bindSplices [ ("json", jsonSplice)]+addHeistAeson = bindSplices [ ("json", jsonSplice)+                            , ("bind", bindStrict) ]  renderJsonTemplate :: Monad m => JsonState m -> Strict.ByteString -> Value -> m (Maybe (Builder, MIMEType)) renderJsonTemplate state tplName json
+ tests/bind.expected view
@@ -0,0 +1,6 @@+&#10;++  +value++
+ tests/bind.json view
@@ -0,0 +1,2 @@+{"key": "value"+,"level1": {"level2": {"level3": "Third level"}}}
+ tests/bind.tpl view
@@ -0,0 +1,7 @@+<bind tag="val">+<json value="key"/>+</bind>++<json section="level1/level2">+  <val/>+</json>