packages feed

stache 0.1.5 → 0.1.6

raw patch · 4 files changed

+36/−13 lines, 4 filesdep ~stache

Dependency ranges changed: stache

Files

CHANGELOG.md view
@@ -1,3 +1,7 @@+## Stache 0.1.6++* Fixed a bug in the lookup algorithm for dot-separated keys.+ ## Stache 0.1.5  * When section's key is a number or non-empty string, it's accessible as `.`
Text/Mustache/Render.hs view
@@ -184,19 +184,27 @@ lookupKey k = do   v <- asks rcContext   p <- asks rcPrefix-  return . fromMaybe Null $-    if (null . drop 1 . unKey) k-      then let f x = asum (simpleLookup (x <> k) <$> v)-           in asum (fmap (f . Key) . reverse . tails $ unKey p)-      else asum (simpleLookup (p <> k) <$> v)+  let f x = asum (simpleLookup False (x <> k) <$> v)+  (return . fromMaybe Null . asum) (fmap (f . Key) . reverse . tails $ unKey p)  -- | Lookup a 'Value' by traversing another 'Value' using given 'Key' as -- “path”. -simpleLookup :: Key -> Value -> Maybe Value-simpleLookup (Key [])     obj        = return obj-simpleLookup (Key (k:ks)) (Object m) = H.lookup k m >>= simpleLookup (Key ks)-simpleLookup _            _          = Nothing+simpleLookup+  :: Bool+     -- ^ At least one part of the path matched, in this case we are+     -- “committed” to this lookup and cannot say “there is nothing, try+     -- other level”. This is necessary to pass the “Dotted Names — Context+     -- Precedence” test from the “interpolation.yml” spec.+  -> Key               -- ^ The key to lookup+  -> Value             -- ^ Source value+  -> Maybe Value       -- ^ Looked-up value+simpleLookup _ (Key [])     obj        = return obj+simpleLookup c (Key (k:ks)) (Object m) =+  case H.lookup k m of+    Nothing -> if c then Just Null else Nothing+    Just  v -> simpleLookup True (Key ks) v+simpleLookup _ _ _ = Nothing {-# INLINE simpleLookup #-}  -- | Enter the section by adding given 'Key' prefix to current prefix.
stache.cabal view
@@ -31,7 +31,7 @@ -- POSSIBILITY OF SUCH DAMAGE.  name:                 stache-version:              0.1.5+version:              0.1.6 cabal-version:        >= 1.10 license:              BSD3 license-file:         LICENSE.md@@ -97,7 +97,7 @@                     , hspec            >= 2.0  && < 3.0                     , hspec-megaparsec >= 0.2  && < 0.3                     , megaparsec       >= 5.0  && < 6.0-                    , stache           >= 0.1.5+                    , stache           >= 0.1.6                     , text             >= 1.2  && < 1.3   other-modules:      Text.Mustache.Compile.THSpec                     , Text.Mustache.ParserSpec@@ -122,7 +122,7 @@                     , file-embed                     , hspec            >= 2.0  && < 3.0                     , megaparsec       >= 5.0  && < 6.0-                    , stache           >= 0.1.5+                    , stache           >= 0.1.6                     , text             >= 1.2  && < 1.3                     , yaml             >= 0.8  && < 0.9   if flag(dev)@@ -140,7 +140,7 @@                     , criterion        >= 0.6.2.1 && < 1.2                     , deepseq          >= 1.4  && < 1.5                     , megaparsec       >= 5.0  && < 6.0-                    , stache           >= 0.1.5+                    , stache           >= 0.1.6                     , text             >= 1.2  && < 1.3   if flag(dev)     ghc-options:      -Wall -Werror
tests/Text/Mustache/RenderSpec.hs view
@@ -127,3 +127,14 @@                        , ("partial", [TextBlock "one\ntwo\nthree"]) ]       in renderMustache template Null `shouldBe`            "   one\n   two\n   three*"+  context "when using dotted keys inside a section" $+    it "it should be equivalent to access via one more section" $+      r [ Section (key "things")+          [ EscapedVar (Key ["atts", "color"])+          , TextBlock " == "+          , Section (key "atts") [EscapedVar (key "color")] ] ]+        (object ["things" .=+                 [object+                  ["atts" .=+                   object ["color" .= ("blue" :: Text)]]]])+        `shouldBe` "blue == blue"