heist-emanote 1.2.0.0 → 1.2.1.0
raw patch · 4 files changed
+49/−23 lines, 4 filesdep +indexed-traversabledep ~aesonPVP ok
version bump matches the API change (PVP)
Dependencies added: indexed-traversable
Dependency ranges changed: aeson
API changes (from Hackage documentation)
Files
- heist-emanote.cabal +10/−5
- src/Heist/Common.hs +2/−2
- src/Heist/Splices/Json.hs +27/−6
- test/suite/Heist/Compiled/Tests.hs +10/−10
heist-emanote.cabal view
@@ -1,5 +1,5 @@ name: heist-emanote-version: 1.2.0.0+version: 1.2.1.0 synopsis: An Haskell template system supporting both HTML5 and XML. description: Heist is a powerful template system that supports both HTML5 and XML.@@ -163,7 +163,7 @@ Heist.Interpreted.Internal build-depends:- aeson >= 0.6 && < 1.6,+ aeson >= 0.6 && < 2.1, attoparsec >= 0.10 && < 0.14, base >= 4.5 && < 4.15, blaze-builder >= 0.2 && < 0.5,@@ -187,7 +187,8 @@ transformers-base >= 0.4 && < 0.5, unordered-containers >= 0.1.4 && < 0.3, vector >= 0.9 && < 0.13,- xmlhtml >= 0.2.3.5 && < 0.3+ xmlhtml >= 0.2.3.5 && < 0.3,+ indexed-traversable if !impl(ghc >= 8.0) build-depends: semigroups >= 0.16 && < 0.19@@ -253,8 +254,10 @@ transformers-base, unordered-containers, vector,- xmlhtml+ xmlhtml,+ indexed-traversable + if !impl(ghc >= 8.0) build-depends: semigroups >= 0.16 && < 0.19 @@ -304,7 +307,9 @@ transformers-base, unordered-containers, vector,- xmlhtml+ xmlhtml,+ indexed-traversable+ if !impl(ghc >= 8.0) build-depends: semigroups >= 0.16 && < 0.19
src/Heist/Common.hs view
@@ -17,7 +17,7 @@ import Data.Hashable (Hashable) import Data.HashMap.Strict (HashMap) import qualified Data.HashMap.Strict as Map-import Data.List (isSuffixOf)+import Data.List (isSuffixOf, sort) import Data.Map.Syntax import Data.Maybe (isJust) import Data.Monoid ((<>))@@ -95,7 +95,7 @@ let spliceError = SpliceError { spliceHistory = _splicePath hs , spliceTemplateFile = _curTemplateFile hs- , visibleSplices = Map.keys $ _compiledSpliceMap hs+ , visibleSplices = sort $ Map.keys $ _compiledSpliceMap hs , contextNode = node , spliceMsg = msg }
src/Heist/Splices/Json.hs view
@@ -1,6 +1,8 @@+{-# LANGUAGE CPP #-} {-# LANGUAGE BangPatterns #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE ScopedTypeVariables #-}+{-# LANGUAGE FlexibleContexts #-} module Heist.Splices.Json ( bindJson@@ -11,7 +13,13 @@ import Data.Aeson import qualified Data.ByteString.Char8 as S import qualified Data.ByteString.Lazy.Char8 as L+#if MIN_VERSION_aeson(2,0,0)+import qualified Data.Aeson.KeyMap as KM+import qualified Data.Aeson.Key as K+import qualified Data.Foldable.WithIndex as FI+#else import qualified Data.HashMap.Strict as Map+#endif import Data.Map.Syntax import Data.Maybe import Data.Text (Text)@@ -89,7 +97,6 @@ numToText :: ToJSON a => a -> Text numToText = T.decodeUtf8 . S.concat . L.toChunks . encode - ------------------------------------------------------------------------------ findExpr :: Text -> Value -> Maybe Value findExpr t = go (T.split (=='.') t)@@ -97,7 +104,11 @@ go [] !value = Just value go (x:xs) !value = findIn value >>= go xs where+#if MIN_VERSION_aeson(2,0,0)+ findIn (Object obj) = KM.lookup (K.fromText x) obj+#else findIn (Object obj) = Map.lookup x obj+#endif findIn (Array arr) = tryReadIndex >>= \i -> arr V.!? i findIn _ = Nothing @@ -217,13 +228,23 @@ -------------------------------------------------------------------------- goObject obj = do start <- genericBindings+#if MIN_VERSION_aeson(2,0,0)+ let bindings = FI.ifoldl' (flip bindKvp) start obj+#else let bindings = Map.foldlWithKey' bindKvp start obj+#endif lift $ runChildrenWith bindings --------------------------------------------------------------------------+ bindKvp bindings k v =- let newBindings = do- T.append "with:" k ## withValue v explodeTag- T.append "snippet:" k ## withValue v snippetTag- T.append "value:" k ## withValue v valueTag- in bindings >> newBindings+#if MIN_VERSION_aeson(2,0,0)+ let k' = K.toText k+#else+ let k' = k+#endif+ newBindings = do+ T.append "with:" k' ## withValue v explodeTag+ T.append "snippet:" k' ## withValue v snippetTag+ T.append "value:" k' ## withValue v valueTag+ in bindings >> newBindings
test/suite/Heist/Compiled/Tests.hs view
@@ -266,9 +266,9 @@ H.assertEqual "namespace bind error test" (Left [ err1, err2, err3 ]) res where- err1 = "templates-nsbind/nsbinderror.tpl: No splice bound for h:invalid3\n ... via templates-nsbind/nsbinderror.tpl: h:main2\nBound splices: h:sub h:recurse h:call h:main2 h:main\nNode: Element {elementTag = \"h:invalid3\", elementAttrs = [], elementChildren = []}"- err2 = "templates-nsbind/nsbinderror.tpl: No splice bound for h:invalid2\n ... via templates-nsbind/nsbinderror.tpl: h:recurse\n ... via templates-nsbind/nsbinderror.tpl: h:main\nBound splices: h:sub h:recurse h:call h:main2 h:main\nNode: Element {elementTag = \"h:invalid2\", elementAttrs = [], elementChildren = []}"- err3 = "templates-nsbind/nsbinderror.tpl: No splice bound for h:invalid1\nBound splices: h:call h:main2 h:main\nNode: Element {elementTag = \"h:invalid1\", elementAttrs = [], elementChildren = []}"+ err1 = "templates-nsbind/nsbinderror.tpl: No splice bound for h:invalid3\n ... via templates-nsbind/nsbinderror.tpl: h:main2\nBound splices: h:call h:main h:main2 h:recurse h:sub\nNode: Element {elementTag = \"h:invalid3\", elementAttrs = [], elementChildren = []}"+ err2 = "templates-nsbind/nsbinderror.tpl: No splice bound for h:invalid2\n ... via templates-nsbind/nsbinderror.tpl: h:recurse\n ... via templates-nsbind/nsbinderror.tpl: h:main\nBound splices: h:call h:main h:main2 h:recurse h:sub\nNode: Element {elementTag = \"h:invalid2\", elementAttrs = [], elementChildren = []}"+ err3 = "templates-nsbind/nsbinderror.tpl: No splice bound for h:invalid1\nBound splices: h:call h:main h:main2\nNode: Element {elementTag = \"h:invalid1\", elementAttrs = [], elementChildren = []}" ------------------------------------------------------------------------------@@ -284,7 +284,7 @@ , Just "templates-nsbind/nsbinderror.tpl" , "h:main2") ] (Just "templates-nsbind/nsbinderror.tpl")- ["h:sub","h:recurse","h:call","h:main2","h:main"]+ ["h:call","h:main","h:main2","h:recurse","h:sub"] (X.Element "h:invalid3" [] []) "No splice bound for h:invalid3" err2 = SpliceError [ ( ["nsbinderror"]@@ -294,12 +294,12 @@ , Just "templates-nsbind/nsbinderror.tpl" ,"h:main") ] (Just "templates-nsbind/nsbinderror.tpl")- ["h:sub","h:recurse","h:call","h:main2","h:main"]+ ["h:call","h:main","h:main2","h:recurse","h:sub"] (X.Element "h:invalid2" [] []) "No splice bound for h:invalid2" err3 = SpliceError [] (Just "templates-nsbind/nsbinderror.tpl")- ["h:call","h:main2","h:main"]+ ["h:call","h:main","h:main2"] (X.Element "h:invalid1" [] []) "No splice bound for h:invalid1" @@ -334,8 +334,8 @@ (Left $ Set.fromList [ err1, err2 ]) (first Set.fromList res) where- err1 = "templates-nscall/_call.tpl: No splice bound for h:sub\nBound splices: h:call h:main2 h:main\nNode: Element {elementTag = \"h:sub\", elementAttrs = [], elementChildren = []}"- err2 = "templates-nscall/_invalid.tpl: No splice bound for h:invalid\nBound splices: h:call h:main2 h:main\nNode: Element {elementTag = \"h:invalid\", elementAttrs = [], elementChildren = []}"+ err1 = "templates-nscall/_call.tpl: No splice bound for h:sub\nBound splices: h:call h:main h:main2\nNode: Element {elementTag = \"h:sub\", elementAttrs = [], elementChildren = []}"+ err2 = "templates-nscall/_invalid.tpl: No splice bound for h:invalid\nBound splices: h:call h:main h:main2\nNode: Element {elementTag = \"h:invalid\", elementAttrs = [], elementChildren = []}" ------------------------------------------------------------------------------@@ -357,7 +357,7 @@ H.assertEqual "exceptions" (Right (msg, err)) $ res where- msg = "templates-loaderror/_error.tpl: Exception in splice compile: Prelude.read: no parse\n ... via templates-loaderror/_error.tpl: h:adder\n ... via templates-loaderror/test.tpl: h:call2\nBound splices: h:adder h:call2 h:call1\nNode: Element {elementTag = \"h:adder\", elementAttrs = [(\"value\",\"noparse\")], elementChildren = []}"+ msg = "templates-loaderror/_error.tpl: Exception in splice compile: Prelude.read: no parse\n ... via templates-loaderror/_error.tpl: h:adder\n ... via templates-loaderror/test.tpl: h:call2\nBound splices: h:adder h:call1 h:call2\nNode: Element {elementTag = \"h:adder\", elementAttrs = [(\"value\",\"noparse\")], elementChildren = []}" err = SpliceError [ ( ["test"] , Just "templates-loaderror/_error.tpl" , "h:adder"),@@ -365,7 +365,7 @@ , Just "templates-loaderror/test.tpl" ,"h:call2") ] (Just "templates-loaderror/_error.tpl")- ["h:adder", "h:call2", "h:call1"]+ ["h:adder", "h:call1", "h:call2"] (X.Element "h:adder" [("value", "noparse")] []) "Exception in splice compile: Prelude.read: no parse" hc = HeistConfig sc "h" True