packages feed

HStringTemplate 0.8 → 0.8.1

raw patch · 4 files changed

+20/−14 lines, 4 filesdep −utf8-stringPVP ok

version bump matches the API change (PVP)

Dependencies removed: utf8-string

API changes (from Hackage documentation)

Files

HStringTemplate.cabal view
@@ -1,5 +1,5 @@ name:                HStringTemplate-version:             0.8+version:             0.8.1 synopsis:            StringTemplate implementation in Haskell. description:         A port of the Java library by Terrence Parr. category:            Text@@ -16,7 +16,7 @@ library    build-depends:   syb, base >= 4, base < 5, filepath, parsec < 4, containers, pretty >= 1.1.0.0,-                   time >= 1.5 && < 1.6, bytestring, directory, array, text, deepseq, utf8-string, blaze-builder, void, template-haskell >= 2.3, mtl+                   time >= 1.5 && < 1.6, bytestring, directory, array, text, deepseq, blaze-builder,void, template-haskell >= 2.3, mtl    exposed-modules:   Text.StringTemplate                      Text.StringTemplate.Base
Text/StringTemplate/Base.hs view
@@ -267,7 +267,7 @@                               Just _ -> C.throw $ ParseError n err                               Nothing -> showStr err (senv t) --- | Returns a tuple of three lists. The first is of templates with parse errors, and their erros. The next is of missing attributes, and the last is of missing templates. If there are no errors, then all lists will be empty.+-- | Returns a tuple of three lists. The first is of templates with parse errors, and their errors. The next is of missing attributes, and the last is of missing templates. If there are no errors, then all lists will be empty. This check is performed recursively. checkTemplateDeep :: (Stringable a, NFData a) => StringTemplate a -> ([(String,String)], [String], [String]) checkTemplateDeep t = case runSTMP t of                         Left err -> ([("Top Level Template", err)], [],[])
Text/StringTemplate/Group.hs view
@@ -18,9 +18,9 @@ import System.FilePath import System.Directory import Data.IORef+import System.IO import System.IO.Unsafe import System.IO.Error-import System.IO.UTF8 as U import qualified Data.Map as M import Data.Time @@ -34,10 +34,16 @@ (<$$>) :: (Functor f1, Functor f) => (a -> b) -> f (f1 a) -> f (f1 b) (<$$>) = (<$>) . (<$>) +readFileUTF :: FilePath -> IO String+readFileUTF f = do+   h <- openFile f ReadMode+   hSetEncoding h utf8+   hGetContents h+ readFile' :: FilePath -> IO String readFile' f = do-  x <- U.readFile f-  length x `seq` return x+   x <- readFileUTF f+   length x `seq` return x  groupFromFiles :: Stringable a => (FilePath -> IO String) -> [(FilePath,String)] -> IO (STGroup a) groupFromFiles rf fs = groupStringTemplates <$> forM fs  (\(f,fname) -> do@@ -91,12 +97,12 @@ -- | Given a path, returns a group which generates all files in said directory which have the supplied extension. directoryGroupLazyExt :: (Stringable a) => FilePath -> FilePath -> IO (STGroup a) directoryGroupLazyExt ext path =-    groupFromFiles U.readFile .+    groupFromFiles readFileUTF .     map ((</>) path &&& takeBaseName) . filter ((ext ==) . takeExtension) =<<     getDirectoryContents path  -- | As with 'directoryGroup', but traverses subdirectories as well. A template named--- \"foo/bar.st\" may be referenced by \"foo/bar\" in the returned group.+-- \"foo\/bar.st\" may be referenced by \"foo\/bar\" in the returned group. directoryGroupRecursive :: (Stringable a) => FilePath -> IO (STGroup a) directoryGroupRecursive = directoryGroupRecursiveExt ".st" @@ -110,7 +116,7 @@  -- | As with 'directoryGroupRecursiveLazy', but a template extension is supplied. directoryGroupRecursiveLazyExt :: (Stringable a) => FilePath -> FilePath -> IO (STGroup a)-directoryGroupRecursiveLazyExt ext path = groupFromFiles U.readFile =<< getTmplsRecursive ext "" path+directoryGroupRecursiveLazyExt ext path = groupFromFiles readFileUTF =<< getTmplsRecursive ext "" path  -- | Adds a supergroup to any StringTemplate group such that templates from -- the original group are now able to call ones from the supergroup as well.@@ -154,8 +160,10 @@ unsafeVolatileDirectoryGroup path m = return . flip addSubGroup extraTmpls $ cacheSTGroup stfg     where stfg = StFirst . Just . newSTMP . unsafePerformIO . flip CE.catch                        (return . (\e -> "IO Error: " ++ show (ioeGetFileName e) ++ " -- " ++ ioeGetErrorString e))-                 . U.readFile . (path </>) . (++".st")+                 . readFileUTF . (path </>) . (++".st")           extraTmpls = addSubGroup (groupStringTemplates [("dumpAttribs", dumpAttribs)]) nullGroup+          delayTime :: Double+          delayTime = fromIntegral m           cacheSTGroup :: STGroup a -> STGroup a           cacheSTGroup g = unsafePerformIO $ do                              !ior <- newIORef M.empty@@ -170,7 +178,7 @@                                case M.lookup s mp of                                  Nothing -> udReturn curtime                                  Just (t, st) ->-                                     if (round . realToFrac $-                                               diffUTCTime curtime t) > m+                                     if (realToFrac $+                                               diffUTCTime curtime t) > delayTime                                        then udReturn curtime                                        else return st
Text/StringTemplate/Instances.hs view
@@ -16,9 +16,7 @@ import Data.Time import Data.Void import qualified Data.Text as T-import qualified Data.Text.Encoding as T import qualified Data.Text.Lazy as LT-import qualified Data.Text.Lazy.Encoding as LT   {--------------------------------------------------------------------