packages feed

mustache 2.2 → 2.2.1

raw patch · 4 files changed

+39/−44 lines, 4 files

Files

CHANGELOG.md view
@@ -1,5 +1,14 @@ # Mustache library changelog +## v2.2.1++- Quickfix for an issue with resolving in context++## v2.2++- changed substitution into a new monad+    + easier usage in lambdas and lambdas can now do nested substitution+ ## v2.1.4  - Treat Null as falsy in sections@@ -10,7 +19,7 @@  ## v2.1.2 -- Fixed template cahce again, as the spec requires access to the previous cache in partials as well+- Fixed template cache again, as the spec requires access to the previous cache in partials as well  ## v2.1.1 
mustache.cabal view
@@ -1,5 +1,5 @@ name:                mustache-version:             2.2+version:             2.2.1 synopsis:            A mustache template parser library. description:   Allows parsing and rendering template files with mustache markup. See the@@ -28,13 +28,6 @@ source-repository head   type:     git   location: git://github.com/JustusAdam/mustache.git--source-repository this-  type:     git-  branch:   master-  location: git://github.com/JustusAdam/mustache.git-  tag:      v2.1.4-   library
src/Text/Mustache/Internal/Types.hs view
@@ -58,20 +58,19 @@ -- searched until the key is found, then 'innerSearch' is called on the result. search :: [Key] -> SubM (Maybe Value) search [] = return Nothing-search keys@(_:nextKeys) = (>>= innerSearch nextKeys) <$> go keys+search (key:nextKeys) = (>>= innerSearch nextKeys) <$> go   where-    go [] = return Nothing-    go val@(x:_) = do-        (Context parents focus) <- asks fst-+    go = asks fst >>= \case+      Context parents focus -> do+        let searchParents = case parents of+                  (newFocus: newParents) -> shiftContext (Context newParents newFocus) $ go+                  _ -> return Nothing         case focus of-            Object o ->-              case HM.lookup x o of-                Just res -> return $ Just res-                _ -> case parents of-                        (newFocus: newParents) -> shiftContext (Context newParents newFocus) $ go val-                        _ -> return Nothing-            _ -> return Nothing+          Object o ->+            case HM.lookup key o of+              Just res -> return $ Just res+              _ -> searchParents+          _ -> searchParents   -- | Searches nested scopes navigating inward. Fails if it encunters something
src/Text/Mustache/Render.hs view
@@ -118,10 +118,8 @@     Context parents focus@(Array a)       | V.null a  -> return ()       | otherwise -> for_ a $ \focus' ->-        let-          newContext = Context (focus:parents) focus'-        in-          shiftContext newContext $ substituteAST secSTree+        let newContext = Context (focus:parents) focus'+        in shiftContext newContext $ substituteAST secSTree     Context _ (Object _) -> substituteAST secSTree     Context _ v -> tellError $ InvalidImplicitSectionContextType $ showValueType v @@ -218,27 +216,23 @@   return $ pack $ show e  -class ToText a where-  toText :: a -> Text--instance ToText Text where-  toText = id--instance ToText LT.Text where-  toText = LT.toStrict+instance ToMustache (Context Value -> STree -> STree) where+  toMustache f = Lambda $ (<$> askContext) . flip f -instance ToText String where-  toText = pack+instance ToMustache (Context Value -> STree -> Text) where+  toMustache = lambdaHelper id +instance ToMustache (Context Value -> STree -> LT.Text) where+  toMustache = lambdaHelper LT.toStrict -instance ToMustache (Context Value -> STree -> STree) where-  toMustache f = Lambda $ (<$> askContext) . flip f+instance ToMustache (Context Value -> STree -> String) where+  toMustache = lambdaHelper pack -instance ToText t => ToMustache (Context Value -> STree -> t) where-  toMustache f = Lambda $ (<$> askContext) . wrapper-    where-      wrapper ::  STree -> Context Value -> STree-      wrapper lSTree c = [TextBlock $ toText $ f c lSTree]+lambdaHelper :: (r -> Text) -> (Context Value -> STree -> r) -> Value+lambdaHelper conv f = Lambda $ (<$> askContext) . wrapper+  where+    wrapper ::  STree -> Context Value -> STree+    wrapper lSTree c = [TextBlock $ conv $ f c lSTree] -instance ToText t => ToMustache (STree -> SubM t) where-  toMustache f = Lambda (fmap (return . TextBlock . toText) . f)+instance ToMustache (STree -> SubM Text) where+  toMustache f = Lambda (fmap (return . TextBlock) . f)