packages feed

mustache 2.1 → 2.1.1

raw patch · 4 files changed

+19/−10 lines, 4 files

Files

CHANGELOG.md view
@@ -1,6 +1,10 @@ # Mustache library changelog -# v2.1+## v2.1.1++- Fixed an error where the substitution of partials would not use the template cache of the new partial++## v2.1  - Added API preserving checked substitution with 'checkedSubstitute' and 'checkedSubstituteValue' - Better and more ToMustache instances. No longer are all sequences of characters serialised as strings
mustache.cabal view
@@ -1,5 +1,5 @@ name:                mustache-version:             2.1+version:             2.1.1 synopsis:            A mustache template parser library. description:   Allows parsing and rendering template files with mustache markup. See the
src/Text/Mustache.hs view
@@ -165,11 +165,11 @@    -- ** Generic -  , substitute+  , substitute, checkedSubstitute    -- ** Specialized -  , substituteValue+  , substituteValue, checkedSubstituteValue    -- ** Data Conversion   , ToMustache, toMustache, object, (~>), (~=)
src/Text/Mustache/Render.hs view
@@ -114,8 +114,12 @@   you must check that the error list in the first tuple value is empty. -} checkedSubstituteValue :: Template -> Value -> ([SubstitutionError], Text)-checkedSubstituteValue (Template { ast = cAst, partials = cPartials }) dataStruct =-  second T.concat $ execWriter $ mapM (substitute' (Context mempty dataStruct)) cAst+checkedSubstituteValue template dataStruct =+  second T.concat $ execWriter $ substituteASTWithValAndCache (ast template) (partials template) (Context mempty dataStruct)++substituteASTWithValAndCache :: STree -> TemplateCache -> Context Value -> Substitution ()+substituteASTWithValAndCache cAst cPartials ctx =+  mapM_ (substitute' ctx) cAst   where     -- Main substitution function     substitute' :: Context Value -> Node Text -> Substitution ()@@ -175,10 +179,11 @@      -- substituting a partial     substitute' context (Partial indent pName) =-      maybe-        (tellError $ PartialNotFound pName)-        (mapM_ (substitute' context) . handleIndent indent . ast)-        $ HM.lookup pName cPartials+      case HM.lookup pName cPartials of+        Nothing -> tellError $ PartialNotFound pName+        Just t ->+          let ast' = handleIndent indent $ ast t+          in substituteASTWithValAndCache ast' (partials t) context   showValueType :: Value -> String