stache 0.2.1 → 0.2.2
raw patch · 4 files changed
+33/−12 lines, 4 filesdep ~aesondep ~criteriondep ~stache
Dependency ranges changed: aeson, criterion, stache
Files
- CHANGELOG.md +7/−0
- Text/Mustache/Compile.hs +16/−5
- Text/Mustache/Compile/TH.hs +6/−3
- stache.cabal +4/−4
CHANGELOG.md view
@@ -1,3 +1,10 @@+## Stache 0.2.2++* Add the `getMustacheFilesInDir` function.++* Make TH helpers `compileMustacheDir` and `compileMustacheFile` detect+ changes in the templates and force recompilation.+ ## Stache 0.2.1 * Made TH parse errors nicer.
Text/Mustache/Compile.hs view
@@ -15,6 +15,7 @@ module Text.Mustache.Compile ( compileMustacheDir+ , getMustacheFilesInDir , compileMustacheFile , compileMustacheText ) where@@ -47,8 +48,7 @@ -> FilePath -- ^ Directory with templates -> m Template -- ^ The resulting template compileMustacheDir pname path =- liftIO (getDirectoryContents path) >>=- filterM isMustacheFile . liftM (F.combine (F.takeDirectory path)) >>=+ getMustacheFilesInDir path >>= liftM selectKey . foldM f (Template undefined M.empty) where selectKey t = t { templateActual = pname }@@ -56,6 +56,19 @@ Template _ new <- compileMustacheFile fp return (Template undefined (M.union new old)) +-- | Return a list of templates found in given directory. The returned paths+-- are absolute.+--+-- @since 0.2.2++getMustacheFilesInDir :: MonadIO m+ => FilePath -- ^ Directory with templates+ -> m [FilePath]+getMustacheFilesInDir path =+ liftIO (getDirectoryContents path) >>=+ filterM isMustacheFile . fmap (F.combine path) >>=+ mapM (liftIO . makeAbsolute)+ -- | Compile single Mustache template and select it. -- -- The action can throw the same exceptions as 'T.readFile'.@@ -82,7 +95,7 @@ ---------------------------------------------------------------------------- -- Helpers --- | Check if given 'FilePath' point to a mustache file.+-- | Check if given 'FilePath' points to a mustache file. isMustacheFile :: MonadIO m => FilePath -> m Bool isMustacheFile path = do@@ -94,7 +107,6 @@ pathToPName :: FilePath -> PName pathToPName = PName . T.pack . F.takeBaseName-{-# INLINE pathToPName #-} -- | Throw 'MustacheException' if argument is 'Left' or return the result -- inside 'Right'.@@ -103,4 +115,3 @@ => Either (ParseError Char Dec) Template -- ^ Value to process -> m Template -- ^ The result withException = either (throwM . MustacheParserException) return-{-# INLINE withException #-}
Text/Mustache/Compile/TH.hs view
@@ -32,7 +32,8 @@ import Data.Typeable (cast) import Language.Haskell.TH hiding (Dec) import Language.Haskell.TH.Quote (QuasiQuoter (..))-import Language.Haskell.TH.Syntax (lift)+import Language.Haskell.TH.Syntax (lift, addDependentFile)+import System.Directory import Text.Mustache.Type import qualified Data.Text as T import qualified Data.Text.Lazy as TL@@ -60,7 +61,8 @@ :: PName -- ^ Which template to select after compiling -> FilePath -- ^ Directory with templates -> Q Exp -- ^ The resulting template-compileMustacheDir pname path =+compileMustacheDir pname path = do+ runIO (C.getMustacheFilesInDir path) >>= mapM_ addDependentFile (runIO . try) (C.compileMustacheDir pname path) >>= handleEither -- | Compile single Mustache template and select it.@@ -70,7 +72,8 @@ compileMustacheFile :: FilePath -- ^ Location of the file -> Q Exp-compileMustacheFile path =+compileMustacheFile path = do+ runIO (makeAbsolute path) >>= addDependentFile (runIO . try) (C.compileMustacheFile path) >>= handleEither -- | Compile Mustache template from 'Text' value. The cache will contain
stache.cabal view
@@ -31,7 +31,7 @@ -- POSSIBILITY OF SUCH DAMAGE. name: stache-version: 0.2.1+version: 0.2.2 cabal-version: >= 1.10 license: BSD3 license-file: LICENSE.md@@ -97,7 +97,7 @@ , hspec >= 2.0 && < 3.0 , hspec-megaparsec >= 0.2 && < 0.4 , megaparsec >= 5.0 && < 6.0- , stache >= 0.2.1+ , stache >= 0.2.2 , 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.2.1+ , stache >= 0.2.2 , 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.2.1+ , stache >= 0.2.2 , text >= 1.2 && < 1.3 if flag(dev) ghc-options: -O2 -Wall -Werror