packages feed

mustache 2.2.2 → 2.2.3

raw patch · 5 files changed

+40/−3 lines, 5 filesdep ~basedep ~either

Dependency ranges changed: base, either

Files

CHANGELOG.md view
@@ -1,5 +1,9 @@ # Mustache library changelog +## v2.2.3++- Quick fix to prevent catchSubstitute from reporting substitutions to the renderer.+ ## v2.2.2  - Added a function to catch a substitution result
mustache.cabal view
@@ -1,5 +1,5 @@ name:                mustache-version:             2.2.2+version:             2.2.3 synopsis:            A mustache template parser library. description:   Allows parsing and rendering template files with mustache markup. See the
src/Text/Mustache.hs view
@@ -171,8 +171,17 @@    , substituteValue, checkedSubstituteValue -  -- ** Data Conversion+  -- ** In Lambdas++  , substituteNode, substituteAST, catchSubstitute++  -- * Data Conversion   , ToMustache, toMustache, object, (~>), (~=)++  -- ** Utilities for lambdas++  , overText+   ) where  @@ -180,3 +189,9 @@ import           Text.Mustache.Compile import           Text.Mustache.Render import           Text.Mustache.Types+import qualified Data.Text as T+++-- | Creates a 'Lambda' which first renders the contained section and then applies the supplied function+overText :: (T.Text -> T.Text) -> Value+overText f = toMustache $ fmap (f . snd) . catchSubstitute . substituteAST
src/Text/Mustache/Render.hs view
@@ -103,7 +103,9 @@  -- | Catch the results of running the inner substitution. catchSubstitute :: SubM a -> SubM (a, Text)-catchSubstitute = fmap (second (T.concat . snd)) . SubM . listen . runSubM'+catchSubstitute = fmap (second (T.concat . snd)) . SubM . hideResults . listen . runSubM'+  where+    hideResults = censor (\(errs, _) -> (errs, []))  -- | Substitute an entire 'STree' rather than just a single 'Node' substituteAST :: STree -> SubM ()
test/unit/Spec.hs view
@@ -185,6 +185,22 @@         (object ["section" ~> ([] :: [T.Text])])       `shouldBe` "" +    it "substitutes a lambda by applying lambda to contained text" $+      substitute+        (toTemplate [Section (NamedData ["lambda"]) [TextBlock "t"]])+        (object ["lambda" ~> (overText T.toUpper)])+      `shouldBe` "T"+++    it "substitutes a lambda by applying lambda to the nested substitution results" $+      substitute+        (toTemplate [Section (NamedData ["lambda"]) [TextBlock "t", Variable escaped (NamedData ["inner"])]])+        (object [ "lambda" ~> (overText T.toUpper)+                , "inner" ~> ("var" :: T.Text)+                ])+      `shouldBe` "TVAR"++     it "substitutes a nested section" $       substitute         (toTemplate [Variable escaped (NamedData ["outer", "inner"])])