packages feed

stache 0.1.3 → 0.1.4

raw patch · 8 files changed

+56/−16 lines, 8 filesdep ~stache

Dependency ranges changed: stache

Files

CHANGELOG.md view
@@ -1,3 +1,19 @@+## Stache 0.1.4++* Numbers are now treated as “true” values.++* Added `Semigroup` instance for `Key`.++* Now change of delimiters affects special unescaped variable syntax as+  well, for example: `{{=<< >>=}}<<{var}>>` will be parsed as unescaped+  variable `var`.++* `compileMustacheFile` now shows full path to malformed template when the+  template cannot be parsed.++* Defined `displayException` method of `Exception` type class for+  `MustacheException` using `parseErrorPretty` from Megaparsec.+ ## Stache 0.1.3  * Cosmetic improvements.
Text/Mustache/Compile.hs view
@@ -63,8 +63,11 @@ compileMustacheFile :: (MonadIO m, MonadThrow m)   => FilePath          -- ^ Location of the file   -> m Template-compileMustacheFile path = liftIO (TL.readFile path) >>=-  withException . compileMustacheText (pathToPName path)+compileMustacheFile path =+  liftIO (TL.readFile path) >>= withException . compile+  where+    pname = pathToPName path+    compile = fmap (Template pname . M.singleton pname) . parseMustache path  -- | Compile Mustache template from a lazy 'Text' value. The cache will -- contain only this template named according to given 'PName'.
Text/Mustache/Parser.hs view
@@ -74,8 +74,11 @@ {-# INLINE pUnescapedVariable #-}  pUnescapedSpecial :: Parser Node-pUnescapedSpecial =-  UnescapedVar <$> between (symbol "{{{") (string "}}}") pKey+pUnescapedSpecial = do+  start <- gets openingDel+  end   <- gets closingDel+  between (symbol $ start ++ "{") (string $ "}" ++ end) $+    UnescapedVar <$> pKey {-# INLINE pUnescapedSpecial #-}  pSection :: String -> (Key -> [Node] -> Node) -> Parser Node
Text/Mustache/Render.hs view
@@ -90,12 +90,8 @@         Array xs ->           forM_ (V.toList xs) $ \x ->             addToLocalContext x (renderMany renderNode ns)-        Bool True ->-          renderMany renderNode ns-        String _  ->-          renderMany renderNode ns         _ ->-          return ()+          renderMany renderNode ns renderNode (InvertedSection k ns) = do   val <- lookupKey k   when (isBlank val) $@@ -246,6 +242,7 @@ isBlank (Bool False) = True isBlank (Object   m) = H.null m isBlank (Array    a) = V.null a+isBlank (String   s) = T.null s isBlank _            = False {-# INLINE isBlank #-} 
Text/Mustache/Type.hs view
@@ -11,6 +11,7 @@ -- because "Text.Mustache" re-exports everything you may need, import that -- module instead. +{-# LANGUAGE CPP                        #-} {-# LANGUAGE DeriveDataTypeable         #-} {-# LANGUAGE DeriveGeneric              #-} {-# LANGUAGE GeneralizedNewtypeDeriving #-}@@ -24,7 +25,7 @@ where  import Control.DeepSeq-import Control.Monad.Catch (Exception)+import Control.Exception (Exception(..)) import Data.Data (Data) import Data.Map (Map) import Data.Semigroup@@ -77,7 +78,7 @@ --     * @[text1, text2]@ — multiple keys represent dotted names.  newtype Key = Key { unKey :: [Text] }-  deriving (Eq, Ord, Show, Monoid, Data, Typeable, Generic)+  deriving (Eq, Ord, Show, Semigroup, Monoid, Data, Typeable, Generic)  instance NFData Key @@ -97,4 +98,9 @@ data MustacheException = MustacheException (ParseError Char Dec)   deriving (Eq, Show, Typeable, Generic) +#if MIN_VERSION_base(4,8,0)+instance Exception MustacheException where+  displayException (MustacheException e) = parseErrorPretty e+#else instance Exception MustacheException+#endif
stache.cabal view
@@ -31,7 +31,7 @@ -- POSSIBILITY OF SUCH DAMAGE.  name:                 stache-version:              0.1.3+version:              0.1.4 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.3+                    , stache           >= 0.1.4                     , 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.3+                    , stache           >= 0.1.4                     , 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.3+                    , stache           >= 0.1.4                     , text             >= 1.2  && < 1.3   if flag(dev)     ghc-options:      -Wall -Werror
tests/Text/Mustache/ParserSpec.hs view
@@ -81,6 +81,9 @@     it "handles whitespace just as well" $       p "{{=<<   >>=}}<<  var >>{{ var  }}" `shouldParse`         [EscapedVar (key "var"), TextBlock "{{ var  }}"]+    it "affects {{{s" $+      p "{{=<< >>=}}<<{var}>>" `shouldParse`+        [UnescapedVar (key "var")]     it "parses two subsequent delimiter changes" $       p "{{=(( ))=}}(( var ))((=-- $-=))--#section$---/section$-" `shouldParse`         [EscapedVar (key "var"), Section (key "section") []]
tests/Text/Mustache/RenderSpec.hs view
@@ -52,6 +52,8 @@           r nodes (object ["foo" .= ([] :: [Text])]) `shouldBe` ""         it "skips empty object" $           r nodes (object ["foo" .= object []]) `shouldBe` ""+        it "skips empty string" $+          r nodes (object ["foo" .= ("" :: Text)]) `shouldBe` ""       context "when the key is a Boolean true" $         it "renders the section without interpolation" $           r [Section (key "foo") [TextBlock "brr"]]@@ -70,10 +72,20 @@           r [Section (key "foo") [TextBlock "brr"]]             (object ["foo" .= [True, True]])             `shouldBe` "brrbrr"-      context "wehn the key is a list of objects" $+      context "when the key is a list of objects" $         it "renders the section many times changing context" $           r nodes (object ["foo" .= [object ["bar" .= x] | x <- [1..4] :: [Int]]])             `shouldBe` "1*2*3*4*"+      context "when the key is a number" $+        it "renders the section" $+          r [Section (key "foo") [TextBlock "brr"]]+            (object ["foo" .= (5 :: Int)])+            `shouldBe` "brr"+      context "when the key is a non-empty string" $+        it "renders the section" $+          r [Section (key "foo") [TextBlock "brr"]]+            (object ["foo" .= ("x" :: Text)])+            `shouldBe` "brr"   context "when rendering an inverted section" $ do     let nodes = [InvertedSection (key "foo") [TextBlock "Here!"]]     context "when the key is not present" $