stache 0.1.6 → 0.1.7
raw patch · 6 files changed
+52/−11 lines, 6 filesdep ~stache
Dependency ranges changed: stache
Files
- CHANGELOG.md +4/−0
- README.md +1/−0
- Text/Mustache.hs +1/−0
- Text/Mustache/Compile/TH.hs +29/−4
- stache.cabal +7/−7
- tests/Text/Mustache/Compile/THSpec.hs +10/−0
CHANGELOG.md view
@@ -1,3 +1,7 @@+## Stache 0.1.7++* Added `mustache` quasi-quoter.+ ## Stache 0.1.6 * Fixed a bug in the lookup algorithm for dot-separated keys.
README.md view
@@ -73,6 +73,7 @@ * The official Mustache site: https://mustache.github.io/ * The manual: https://mustache.github.io/mustache.5.html * The specification: https://github.com/mustache/spec+* Stack Builders Stache tutorial: https://www.stackbuilders.com/tutorials/haskell/mustache-templates/ ## License
Text/Mustache.hs view
@@ -69,6 +69,7 @@ -- * The official Mustache site: <https://mustache.github.io/> -- * The manual: <https://mustache.github.io/mustache.5.html> -- * The specification: <https://github.com/mustache/spec>+-- * Stack Builders Stache tutorial: <https://www.stackbuilders.com/tutorials/haskell/mustache-templates/> module Text.Mustache ( -- * Types
Text/Mustache/Compile/TH.hs view
@@ -14,24 +14,28 @@ -- At the moment, functions in this module only work with GHC 8 (they -- require at least @template-haskell-2.11@). -{-# LANGUAGE CPP #-}-{-# LANGUAGE RankNTypes #-}-{-# LANGUAGE TemplateHaskell #-}+{-# LANGUAGE CPP #-}+{-# LANGUAGE OverloadedStrings #-}+{-# LANGUAGE RankNTypes #-}+{-# LANGUAGE TemplateHaskell #-} module Text.Mustache.Compile.TH ( compileMustacheDir , compileMustacheFile- , compileMustacheText )+ , compileMustacheText+ , mustache ) where import Control.Monad.Catch (try) import Data.Text.Lazy (Text) import Data.Typeable (cast) import Language.Haskell.TH hiding (Dec)+import Language.Haskell.TH.Quote (QuasiQuoter (..)) import Language.Haskell.TH.Syntax (lift) import Text.Megaparsec hiding (try) import Text.Mustache.Type import qualified Data.Text as T+import qualified Data.Text.Lazy as TL import qualified Text.Mustache.Compile as C #if !MIN_VERSION_base(4,8,0)@@ -80,6 +84,27 @@ -> Q Exp compileMustacheText pname text = handleEither (C.compileMustacheText pname text)++-- | Compile Mustache using QuasiQuoter. Usage:+--+-- > {-# LANGUAGE QuasiQuotes #-}+-- > import Text.Mustache.Compile.TH (mustache)+-- >+-- > foo :: Template+-- > foo = [mustache|This is my inline {{ template }}.|]+--+-- Name of created partial is set to @"quasi-quoted"@. You can extend cache+-- of 'Template' created this way using 'mappend' and so work with partials+-- as usual.+--+-- @since 0.1.7++mustache :: QuasiQuoter+mustache = QuasiQuoter+ { quoteExp = compileMustacheText "quasi-quoted" . TL.pack+ , quotePat = undefined+ , quoteType = undefined+ , quoteDec = undefined } -- | Given an 'Either' result return 'Right' and signal pretty-printed error -- if we have a 'Left'.
stache.cabal view
@@ -31,7 +31,7 @@ -- POSSIBILITY OF SUCH DAMAGE. name: stache-version: 0.1.6+version: 0.1.7 cabal-version: >= 1.10 license: BSD3 license-file: LICENSE.md@@ -95,9 +95,9 @@ , base >= 4.7 && < 5.0 , containers >= 0.5 && < 0.6 , hspec >= 2.0 && < 3.0- , hspec-megaparsec >= 0.2 && < 0.3+ , hspec-megaparsec >= 0.2 && < 0.4 , megaparsec >= 5.0 && < 6.0- , stache >= 0.1.6+ , stache >= 0.1.7 , 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.6+ , stache >= 0.1.7 , text >= 1.2 && < 1.3 , yaml >= 0.8 && < 0.9 if flag(dev)@@ -135,12 +135,12 @@ main-is: Main.hs hs-source-dirs: bench type: exitcode-stdio-1.0- build-depends: aeson >= 0.11 && < 0.12- , base >= 4.7 && < 5.0+ build-depends: aeson >= 0.11 && < 1.1+ , base >= 4.7 && < 5.0 , criterion >= 0.6.2.1 && < 1.2 , deepseq >= 1.4 && < 1.5 , megaparsec >= 5.0 && < 6.0- , stache >= 0.1.6+ , stache >= 0.1.7 , text >= 1.2 && < 1.3 if flag(dev) ghc-options: -Wall -Werror
tests/Text/Mustache/Compile/THSpec.hs view
@@ -1,5 +1,6 @@ {-# LANGUAGE CPP #-} {-# LANGUAGE OverloadedStrings #-}+{-# LANGUAGE QuasiQuotes #-} {-# LANGUAGE TemplateHaskell #-} module Text.Mustache.Compile.THSpec@@ -22,6 +23,11 @@ spec :: Spec #if MIN_VERSION_template_haskell(2,11,0) spec = do+ describe "mustache" $+ it "compiles template using QuasiQuotes at compile time" $+ [TH.mustache|From Quasi-Quote!+|]+ `shouldBe` qqTemplate describe "compileMustacheText" $ it "compiles template from text at compile time" $ $(TH.compileMustacheText "foo" "This is the ‘foo’.\n")@@ -34,6 +40,10 @@ it "compiles templates from directory at compile time" $ $(TH.compileMustacheDir "foo" "templates/") `shouldBe` (fooTemplate <> barTemplate)++qqTemplate :: Template+qqTemplate = Template "quasi-quoted" $+ M.singleton "quasi-quoted" [TextBlock "From Quasi-Quote!\n"] fooTemplate :: Template fooTemplate = Template "foo" $