stache 2.0.1 → 2.1.0
raw patch · 11 files changed
+73/−57 lines, 11 filesdep −semigroupsdep −voiddep ~basedep ~megaparsecPVP ok
version bump matches the API change (PVP)
Dependencies removed: semigroups, void
Dependency ranges changed: base, megaparsec
API changes (from Hackage documentation)
- Text.Mustache.Type: instance GHC.Exception.Exception Text.Mustache.Type.MustacheException
+ Text.Mustache.Type: instance GHC.Exception.Type.Exception Text.Mustache.Type.MustacheException
+ Text.Mustache.Type: instance Language.Haskell.TH.Syntax.Lift Text.Mustache.Type.Key
+ Text.Mustache.Type: instance Language.Haskell.TH.Syntax.Lift Text.Mustache.Type.Node
+ Text.Mustache.Type: instance Language.Haskell.TH.Syntax.Lift Text.Mustache.Type.PName
+ Text.Mustache.Type: instance Language.Haskell.TH.Syntax.Lift Text.Mustache.Type.Template
- Text.Mustache: MustacheParserException :: (ParseErrorBundle Text Void) -> MustacheException
+ Text.Mustache: MustacheParserException :: ParseErrorBundle Text Void -> MustacheException
- Text.Mustache: Partial :: PName -> (Maybe Pos) -> Node
+ Text.Mustache: Partial :: PName -> Maybe Pos -> Node
- Text.Mustache.Type: MustacheParserException :: (ParseErrorBundle Text Void) -> MustacheException
+ Text.Mustache.Type: MustacheParserException :: ParseErrorBundle Text Void -> MustacheException
- Text.Mustache.Type: Partial :: PName -> (Maybe Pos) -> Node
+ Text.Mustache.Type: Partial :: PName -> Maybe Pos -> Node
Files
- CHANGELOG.md +9/−0
- LICENSE.md +1/−1
- README.md +1/−1
- Text/Mustache.hs +2/−2
- Text/Mustache/Compile.hs +10/−6
- Text/Mustache/Compile/TH.hs +2/−17
- Text/Mustache/Parser.hs +1/−1
- Text/Mustache/Render.hs +1/−2
- Text/Mustache/Type.hs +33/−2
- bench/Main.hs +0/−6
- stache.cabal +13/−19
CHANGELOG.md view
@@ -1,3 +1,12 @@+## Stache 2.1.0++* Dropped support for GHC 8.0 and older.++* Documentation improvements.++* Added Template Haskell `Lift` instance for the `Template` type and its+ sub-components.+ ## Stache 2.0.1 * Now interpolation with escaping also escapes single quotes as `'`.
LICENSE.md view
@@ -1,4 +1,4 @@-Copyright © 2016–2018 Stack Builders+Copyright © 2016–present Stack Builders All rights reserved.
README.md view
@@ -83,6 +83,6 @@ ## License -Copyright © 2016–2018 Stack Builders+Copyright © 2016–present Stack Builders Distributed under BSD 3 clause license.
Text/Mustache.hs view
@@ -1,6 +1,6 @@ -- | -- Module : Text.Mustache--- Copyright : © 2016–2018 Stack Builders+-- Copyright : © 2016–present Stack Builders -- License : BSD 3 clause -- -- Maintainer : Mark Karpov <markkarpov92@gmail.com>@@ -50,7 +50,7 @@ -- > let res = compileMustacheText "foo" -- > "Hi, {{name}}! You have:\n{{#things}}\n * {{.}}\n{{/things}}\n" -- > case res of--- > Left err -> putStrLn (parseErrorPretty err)+-- > Left bundle -> putStrLn (errorBundlePretty bundle) -- > Right template -> TIO.putStr $ renderMustache template $ object -- > [ "name" .= ("John" :: Text) -- > , "things" .= ["pen" :: Text, "candle", "egg"]
Text/Mustache/Compile.hs view
@@ -1,6 +1,6 @@ -- | -- Module : Text.Mustache.Compile--- Copyright : © 2016–2018 Stack Builders+-- Copyright : © 2016–present Stack Builders -- License : BSD 3 clause -- -- Maintainer : Mark Karpov <markkarpov92@gmail.com>@@ -11,8 +11,6 @@ -- usually need to import the module, because "Text.Mustache" re-exports -- everything you may need, import that module instead. -{-# LANGUAGE CPP #-}- module Text.Mustache.Compile ( compileMustacheDir , compileMustacheDir'@@ -40,9 +38,14 @@ -- files should have the extension @mustache@, (e.g. @foo.mustache@) to be -- recognized. This function /does not/ scan the directory recursively. ----- The action can throw the same exceptions as 'getDirectoryContents', and--- 'T.readFile'.+-- Note that each template\/partial will get an identifier which consists of+-- the name of corresponding template file with extension @.mustache@+-- dropped. This is important for e.g. selecting active template after+-- loading (the first argument). --+-- The action can throw 'MustacheParserException' and the same exceptions as+-- 'getDirectoryContents', and 'T.readFile'.+-- -- > compileMustacheDir = complieMustacheDir' isMustacheFile compileMustacheDir :: MonadIO m@@ -105,7 +108,8 @@ -- | Compile a single Mustache template and select it. ----- The action can throw the same exceptions as 'T.readFile'.+-- The action can throw 'MustacheParserException' and the same exceptions as+-- 'T.readFile'. compileMustacheFile :: MonadIO m => FilePath -- ^ Location of the file
Text/Mustache/Compile/TH.hs view
@@ -1,6 +1,6 @@ -- | -- Module : Text.Mustache.Compile.TH--- Copyright : © 2016–2018 Stack Builders+-- Copyright : © 2016–present Stack Builders -- License : BSD 3 clause -- -- Maintainer : Mark Karpov <markkarpov92@gmail.com>@@ -14,7 +14,6 @@ -- At the moment, functions in this module only work with GHC 8 (they -- require at least @template-haskell-2.11@). -{-# LANGUAGE CPP #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE RankNTypes #-} {-# LANGUAGE TemplateHaskell #-}@@ -29,7 +28,6 @@ import Control.Exception import Data.Text (Text)-import Data.Typeable (cast) import Language.Haskell.TH hiding (Dec) import Language.Haskell.TH.Quote (QuasiQuoter (..)) import Language.Haskell.TH.Syntax (lift, addDependentFile)@@ -38,14 +36,6 @@ import qualified Data.Text as T import qualified Text.Mustache.Compile as C -#if MIN_VERSION_template_haskell(2,11,0)-import Language.Haskell.TH.Syntax (dataToExpQ)-#else-import Data.Data (Data)-dataToExpQ :: Data a => (forall b. Data b => b -> Maybe (Q Exp)) -> a -> Q Exp-dataToExpQ _ _ = fail "The feature requires at least GHC 8 to work"-#endif- -- | Compile all templates in specified directory and select one. Template -- files should have the extension @mustache@, (e.g. @foo.mustache@) to be -- recognized. This function /does not/ scan the directory recursively.@@ -128,7 +118,7 @@ handleEither val = case val of Left err -> (fail . indentNicely . displayException) err- Right template -> dataToExpQ (fmap liftText . cast) template+ Right template -> lift template where -- NOTE Since the feature requires GHC 8 anyway, we follow the -- indentation style of that version of compiler. This makes it look@@ -138,8 +128,3 @@ case lines x' of [] -> "" (x:xs) -> unlines (x : fmap (replicate 8 ' ' ++) xs)---- | Lift strict 'T.Text' to 'Q' 'Exp'.--liftText :: T.Text -> Q Exp-liftText txt = AppE (VarE 'T.pack) <$> lift (T.unpack txt)
Text/Mustache/Parser.hs view
@@ -1,6 +1,6 @@ -- | -- Module : Text.Mustache.Parser--- Copyright : © 2016–2018 Stack Builders+-- Copyright : © 2016–present Stack Builders -- License : BSD 3 clause -- -- Maintainer : Mark Karpov <markkarpov92@gmail.com>
Text/Mustache/Render.hs view
@@ -1,6 +1,6 @@ -- | -- Module : Text.Mustache.Render--- Copyright : © 2016–2018 Stack Builders+-- Copyright : © 2016–present Stack Builders -- License : BSD 3 clause -- -- Maintainer : Mark Karpov <markkarpov92@gmail.com>@@ -11,7 +11,6 @@ -- import the module, because "Text.Mustache" re-exports everything you may -- need, import that module instead. -{-# LANGUAGE CPP #-} {-# LANGUAGE OverloadedStrings #-} module Text.Mustache.Render
Text/Mustache/Type.hs view
@@ -1,6 +1,6 @@ -- | -- Module : Text.Mustache.Type--- Copyright : © 2016–2018 Stack Buliders+-- Copyright : © 2016–present Stack Buliders -- License : BSD 3 clause -- -- Maintainer : Mark Karpov <markkarpov92@gmail.com>@@ -16,6 +16,7 @@ {-# LANGUAGE DeriveGeneric #-} {-# LANGUAGE GeneralizedNewtypeDeriving #-} {-# LANGUAGE OverloadedStrings #-}+{-# LANGUAGE TemplateHaskell #-} module Text.Mustache.Type ( Template (..)@@ -34,12 +35,13 @@ import Data.Map (Map) import Data.String (IsString (..)) import Data.Text (Text)-import Data.Typeable (Typeable)+import Data.Typeable (Typeable, cast) import Data.Void import GHC.Generics import Text.Megaparsec import qualified Data.Map as M import qualified Data.Text as T+import qualified Language.Haskell.TH.Syntax as TH #if !MIN_VERSION_base(4,11,0) import Data.Semigroup@@ -65,6 +67,11 @@ instance Semigroup Template where (Template pname x) <> (Template _ y) = Template pname (M.union x y) +-- | @since 2.1.0++instance TH.Lift Template where+ lift = liftData+ -- | Structural element of template. data Node@@ -77,6 +84,11 @@ -- ^ Partial with indentation level ('Nothing' means it was inlined) deriving (Eq, Ord, Show, Data, Typeable, Generic) +-- | @since 2.1.0++instance TH.Lift Node where+ lift = liftData+ -- | Identifier for values to interpolate. -- -- The representation is the following:@@ -90,6 +102,11 @@ instance NFData Key +-- | @since 2.1.0++instance TH.Lift Key where+ lift = liftData+ -- | Pretty-print a key, this is helpful, for example, if you want to -- display an error message. --@@ -110,6 +127,11 @@ instance NFData PName +-- | @since 2.1.0++instance TH.Lift PName where+ lift = liftData+ -- | Exception that is thrown when parsing of a template fails or referenced -- values are not provided. @@ -147,3 +169,12 @@ "Referenced value was not provided, key: " ++ T.unpack (showKey key) displayMustacheWarning (MustacheDirectlyRenderedValue key) = "Complex value rendered as such, key: " ++ T.unpack (showKey key)++----------------------------------------------------------------------------+-- TH lifting helpers++liftData :: Data a => a -> TH.Q TH.Exp+liftData = TH.dataToExpQ (fmap liftText . cast)++liftText :: Text -> TH.Q TH.Exp+liftText t = TH.AppE (TH.VarE 'T.pack) <$> TH.lift (T.unpack t)
bench/Main.hs view
@@ -1,4 +1,3 @@-{-# LANGUAGE CPP #-} {-# LANGUAGE OverloadedStrings #-} {-# OPTIONS_GHC -fno-warn-orphans #-} @@ -93,11 +92,6 @@ ---------------------------------------------------------------------------- -- Orphan instances--#if !MIN_VERSION_megaparsec(5,0,1)-instance NFData Pos where- rnf = rnf . unPos-#endif instance NFData Node
stache.cabal view
@@ -1,7 +1,7 @@ name: stache-version: 2.0.1+version: 2.1.0 cabal-version: 1.18-tested-with: GHC==7.10.3, GHC==8.0.2, GHC==8.2.2, GHC==8.4.3+tested-with: GHC==8.2.2, GHC==8.4.4, GHC==8.6.5 license: BSD3 license-file: LICENSE.md author: Mark Karpov <markkarpov92@gmail.com>@@ -29,22 +29,18 @@ library build-depends: aeson >= 0.11 && < 1.5- , base >= 4.8 && < 5.0+ , base >= 4.10 && < 5.0 , bytestring >= 0.10 && < 0.11- , containers >= 0.5 && < 0.6+ , containers >= 0.5 && < 0.7 , deepseq >= 1.4 && < 1.5 , directory >= 1.2 && < 1.4 , filepath >= 1.2 && < 1.5 , megaparsec >= 7.0 && < 8.0 , mtl >= 2.1 && < 3.0- , template-haskell >= 2.10 && < 2.14+ , template-haskell >= 2.10 && < 2.15 , text >= 1.2 && < 1.3 , unordered-containers >= 0.2.5 && < 0.3 , vector >= 0.11 && < 0.13- if !impl(ghc >= 7.10)- build-depends: void == 0.7.*- if !impl(ghc >= 8.0)- build-depends: semigroups == 0.18.* exposed-modules: Text.Mustache , Text.Mustache.Compile , Text.Mustache.Compile.TH@@ -55,7 +51,7 @@ ghc-options: -O0 -Wall -Werror -fsimpl-tick-factor=150 else ghc-options: -O2 -Wall -fsimpl-tick-factor=150- if flag(dev) && impl(ghc >= 8.0)+ if flag(dev) ghc-options: -Wcompat -Wincomplete-record-updates -Wincomplete-uni-patterns@@ -68,21 +64,19 @@ hs-source-dirs: tests type: exitcode-stdio-1.0 build-depends: aeson >= 0.11 && < 1.5- , base >= 4.8 && < 5.0- , containers >= 0.5 && < 0.6+ , base >= 4.10 && < 5.0+ , containers >= 0.5 && < 0.7 , hspec >= 2.0 && < 3.0 , hspec-megaparsec >= 2.0 && < 3.0 , megaparsec >= 7.0 && < 8.0 , stache- , template-haskell >= 2.10 && < 2.14+ , template-haskell >= 2.10 && < 2.15 , text >= 1.2 && < 1.3 other-modules: Text.Mustache.Compile.THSpec , Text.Mustache.ParserSpec , Text.Mustache.RenderSpec , Text.Mustache.TypeSpec build-tools: hspec-discover >= 2.0 && < 3.0- if !impl(ghc >= 8.0)- build-depends: semigroups == 0.18.* if flag(dev) ghc-options: -O0 -Wall -Werror else@@ -94,15 +88,15 @@ hs-source-dirs: mustache-spec type: exitcode-stdio-1.0 build-depends: aeson >= 0.11 && < 1.5- , base >= 4.8 && < 5.0+ , base >= 4.10 && < 5.0 , bytestring >= 0.10 && < 0.11- , containers >= 0.5 && < 0.6+ , containers >= 0.5 && < 0.7 , file-embed , hspec >= 2.0 && < 3.0 , megaparsec >= 7.0 && < 8.0 , stache , text >= 1.2 && < 1.3- , yaml >= 0.8 && < 0.11+ , yaml >= 0.8 && < 0.12 if flag(dev) ghc-options: -Wall -Werror else@@ -114,7 +108,7 @@ hs-source-dirs: bench type: exitcode-stdio-1.0 build-depends: aeson >= 0.11 && < 1.5- , base >= 4.8 && < 5.0+ , base >= 4.10 && < 5.0 , criterion >= 0.6.2.1 && < 1.6 , deepseq >= 1.4 && < 1.5 , megaparsec >= 7.0 && < 8.0