packages feed

ginger 0.1.4.0 → 0.1.5.0

raw patch · 2 files changed

+19/−2 lines, 2 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

+ Text.Ginger.GVal: orderedDict :: [Pair m] -> GVal m

Files

ginger.cabal view
@@ -2,7 +2,7 @@ -- documentation, see http://haskell.org/cabal/users-guide/  name:                ginger-version:             0.1.4.0+version:             0.1.5.0 synopsis:            An implementation of the Jinja2 template language in Haskell description:         Ginger is Jinja, minus the most blatant pythonisms. Wants                      to be feature complete, but isn't quite there yet.
src/Text/Ginger/GVal.hs view
@@ -246,10 +246,27 @@ -- compact syntax. type Pair m = (Text, GVal m) --- | Construct a dictionary GVal from a list of pairs.+-- | Construct a dictionary GVal from a list of pairs. Internally, this uses+-- a hashmap, so element order will not be preserved. dict :: [Pair m] -> GVal m dict = toGVal . HashMap.fromList +-- | Construct an ordered dictionary GVal from a list of pairs. Internally,+-- this conversion uses both a hashmap (for O(1) lookup) and the original list,+-- so element order is preserved, but there is a bit of a memory overhead.+orderedDict :: [Pair m] -> GVal m+orderedDict xs =+    def+        { asHtml = mconcat . Prelude.map asHtml . Prelude.map snd $ xs+        , asText = mconcat . Prelude.map asText . Prelude.map snd $ xs+        , asBoolean = not . Prelude.null $ xs+        , isNull = False+        , asLookup = Just (\v -> HashMap.lookup v hm)+        , asDictItems = Just xs+        }+    where+        hm = HashMap.fromList xs+-- -- | Construct a pair from a key and a value. (~>) :: ToGVal m a => Text -> a -> Pair m k ~> v = (k, toGVal v)