HStringTemplate 0.6.12 → 0.7.0
raw patch · 4 files changed
+45/−42 lines, 4 filesdep +voiddep ~basePVP ok
version bump matches the API change (PVP)
Dependencies added: void
Dependency ranges changed: base
API changes (from Hackage documentation)
- Text.StringTemplate: smappend :: Stringable a => a -> a -> a
- Text.StringTemplate: smconcat :: Stringable a => [a] -> a
- Text.StringTemplate: smempty :: Stringable a => a
- Text.StringTemplate.Base: smappend :: Stringable a => a -> a -> a
- Text.StringTemplate.Base: smconcat :: Stringable a => [a] -> a
- Text.StringTemplate.Base: smempty :: Stringable a => a
- Text.StringTemplate.Classes: smappend :: Stringable a => a -> a -> a
- Text.StringTemplate.Classes: smconcat :: Stringable a => [a] -> a
- Text.StringTemplate.Classes: smempty :: Stringable a => a
- Text.StringTemplate.GenericWithClass: instance [overlap ok] (ToSElem a, Data ToSElemD a) => Sat (ToSElemD a)
- Text.StringTemplate.GenericWithClass: instance [overlap ok] Data ToSElemD t => ToSElem t
+ Text.StringTemplate: stFromText :: Stringable a => Text -> a
+ Text.StringTemplate.Base: stFromText :: Stringable a => Text -> a
+ Text.StringTemplate.Classes: TXT :: Text -> SElem a
+ Text.StringTemplate.Classes: stFromText :: Stringable a => Text -> a
- Text.StringTemplate: class Stringable a where stFromByteString = stFromString . unpack mconcatMap m k = foldr (smappend . k) smempty m mintercalate = (smconcat .) . intersperse mlabel x y = smconcat [x, stFromString "[", y, stFromString "]"] smconcat xs = foldr (smappend . id) smempty xs
+ Text.StringTemplate: class Monoid a => Stringable a where stFromByteString = stFromText . decodeUtf8 stFromText = stFromString . unpack mconcatMap m k = foldr (mappend . k) mempty m mintercalate = (mconcat .) . intersperse mlabel x y = mconcat [x, stFromString "[", y, stFromString "]"]
- Text.StringTemplate.Base: class Stringable a where stFromByteString = stFromString . unpack mconcatMap m k = foldr (smappend . k) smempty m mintercalate = (smconcat .) . intersperse mlabel x y = smconcat [x, stFromString "[", y, stFromString "]"] smconcat xs = foldr (smappend . id) smempty xs
+ Text.StringTemplate.Base: class Monoid a => Stringable a where stFromByteString = stFromText . decodeUtf8 stFromText = stFromString . unpack mconcatMap m k = foldr (mappend . k) mempty m mintercalate = (mconcat .) . intersperse mlabel x y = mconcat [x, stFromString "[", y, stFromString "]"]
- Text.StringTemplate.Classes: class Stringable a where stFromByteString = stFromString . unpack mconcatMap m k = foldr (smappend . k) smempty m mintercalate = (smconcat .) . intersperse mlabel x y = smconcat [x, stFromString "[", y, stFromString "]"] smconcat xs = foldr (smappend . id) smempty xs
+ Text.StringTemplate.Classes: class Monoid a => Stringable a where stFromByteString = stFromText . decodeUtf8 stFromText = stFromString . unpack mconcatMap m k = foldr (mappend . k) mempty m mintercalate = (mconcat .) . intersperse mlabel x y = mconcat [x, stFromString "[", y, stFromString "]"]
Files
- HStringTemplate.cabal +3/−6
- Text/StringTemplate/Base.hs +5/−3
- Text/StringTemplate/Classes.hs +28/−31
- Text/StringTemplate/Instances.hs +9/−2
HStringTemplate.cabal view
@@ -1,5 +1,5 @@ name: HStringTemplate-version: 0.6.12+version: 0.7.0 synopsis: StringTemplate implementation in Haskell. description: A port of the Java library by Terrence Parr. category: Text@@ -12,8 +12,8 @@ build-Depends: base Cabal-Version: >= 1.6 -flag smaller-base flag syb-with-class+ default: False flag quasi-quotation library@@ -25,10 +25,7 @@ build-depends: template-haskell >= 2.3, mtl exposed-modules: Text.StringTemplate.QQ - if flag(smaller-base)- build-depends: syb, base >= 4, base < 5, filepath, parsec < 4, containers, pretty, time, old-time, old-locale, bytestring, directory, array, text, deepseq, utf8-string, blaze-builder- else- build-depends: base > 3, base < 4, filepath, parsec < 4, containers, pretty, time, old-time, old-locale, bytestring, directory, array, text, utf8-string, blaze-builder+ build-depends: syb, base >= 4, base < 5, filepath, parsec < 4, containers, pretty, time, old-time, old-locale, bytestring, directory, array, text, deepseq, utf8-string, blaze-builder, void exposed-modules: Text.StringTemplate Text.StringTemplate.Base
Text/StringTemplate/Base.hs view
@@ -292,6 +292,7 @@ showVal snv se = case se of STR x -> stEncode x BS x -> stEncodeBS x+ TXT x -> stEncodeText x LI xs -> joinUpWith showVal xs SM sm -> joinUpWith showAssoc $ M.assocs sm STSH x -> stEncode (format x)@@ -301,8 +302,9 @@ where format = maybe stshow . stfshow <*> optLookup "format" $ snv joinUpWith f xs = mconcatMap' snv xs (f snv) showAssoc e (k,v) = stEncode (k ++ ": ") `mlabel` showVal e v- stEncode = senc snv . stFromString- stEncodeBS = senc snv . stFromByteString+ stEncode = senc snv . stFromString+ stEncodeBS = senc snv . stFromByteString+ stEncodeText = senc snv . stFromText showStr :: Stringable a => String -> SEnv a -> a showStr = const . stFromString@@ -349,7 +351,7 @@ The Grammar --------------------------------------------------------------------} myConcat :: Stringable a => [SEnv a -> a] -> (SEnv a -> a)-myConcat xs a = smconcat $ map ($ a) xs+myConcat xs a = mconcatMap xs ($ a) -- | if p is true, stmpl can fail gracefully, false it dies hard.
Text/StringTemplate/Classes.hs view
@@ -11,9 +11,11 @@ import qualified Blaze.ByteString.Builder.Char.Utf8 as BB import qualified Data.ByteString.Char8 as B import qualified Data.ByteString.Lazy.Char8 as LB+--import qualified Data.ByteString.Lazy.Builder as DBB 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.Builder as TB import qualified Data.Text.Lazy.Encoding as LT import qualified Text.PrettyPrint.HughesPJ as PP @@ -29,8 +31,9 @@ type SMap a = M.Map String (SElem a) -data SElem a = STR String- | BS LB.ByteString+data SElem a = STR String+ | BS LB.ByteString+ | TXT LT.Text | STSH STShow | SM (SMap a) | LI [SElem a]@@ -64,33 +67,26 @@ -- | The Stringable class should be instantiated with care. -- Generally, the provided instances should be enough for anything.-class Stringable a where+class Monoid a => Stringable a where stFromString :: String -> a stFromByteString :: LB.ByteString -> a- stFromByteString = stFromString . LB.unpack+ stFromByteString = stFromText . LT.decodeUtf8+ stFromText :: LT.Text -> a+ stFromText = stFromString . LT.unpack stToString :: a -> String -- | Defaults to @ mconcatMap m k = foldr (mappend . k) mempty m @ mconcatMap :: [b] -> (b -> a) -> a- mconcatMap m k = foldr (smappend . k) smempty m+ mconcatMap m k = foldr (mappend . k) mempty m -- | Defaults to @ (mconcat .) . intersperse @ mintercalate :: a -> [a] -> a- mintercalate = (smconcat .) . intersperse- -- | Defaults to @ mlabel x y = smconcat [x, stFromString "[", y, stFromString "]"] @+ mintercalate = (mconcat .) . intersperse+ -- | Defaults to @ mlabel x y = mconcat [x, stFromString "[", y, stFromString "]"] @ mlabel :: a -> a -> a- mlabel x y = smconcat [x, stFromString "[", y, stFromString "]"]- -- | Just mempty. Here to avoid orphan instances- smempty :: a- -- | Just mappend. Here to avoid orphan instances- smappend :: a -> a -> a- -- | Just mconcat. Here to avoid orphan instances- smconcat :: [a] -> a- smconcat xs = foldr (smappend . id) smempty xs+ mlabel x y = mconcat [x, stFromString "[", y, stFromString "]"] instance Stringable String where stFromString = id stToString = id- smempty = ""- smappend = (++) instance Stringable PP.Doc where stFromString = PP.text@@ -98,47 +94,48 @@ mconcatMap m k = PP.fcat . map k $ m mintercalate = (PP.fcat .) . PP.punctuate mlabel x y = x PP.$$ PP.nest 1 y- smempty = PP.empty- smappend = (PP.<>) instance Stringable B.ByteString where stFromString = B.pack stFromByteString = B.concat . LB.toChunks stToString = B.unpack- smempty = B.empty- smappend = B.append instance Stringable LB.ByteString where stFromString = LB.pack stFromByteString = id stToString = LB.unpack- smempty = LB.empty- smappend = LB.append instance Stringable T.Text where stFromString = T.pack stFromByteString = T.decodeUtf8 . B.concat . LB.toChunks+ stFromText = LT.toStrict stToString = T.unpack- smempty = T.empty- smappend = T.append instance Stringable LT.Text where stFromString = LT.pack stFromByteString = LT.decodeUtf8+ stFromText = id stToString = LT.unpack- smempty = LT.empty- smappend = LT.append instance Stringable BB.Builder where stFromString = BB.fromString stFromByteString = BB.fromLazyByteString stToString = LB.unpack . BB.toLazyByteString- smappend = mappend- smempty = mempty +{-+instance Stringable LBB.Builder where+ stFromString = stringUtf8+ stFromByteString = LBB.lazyByteString+ stToString = LB.unpack . LBB.toLazyByteString+-}++instance Stringable TB.Builder where+ stFromString = TB.fromString+ stFromText = TB.fromLazyText+ stToString = LT.unpack . TB.toLazyText++ --add dlist instance instance Stringable (Endo String) where stFromString = Endo . (++) stToString = ($ []) . appEndo- smempty = mempty- smappend = mappend
Text/StringTemplate/Instances.hs view
@@ -16,6 +16,7 @@ import qualified System.Time as OldTime import System.Locale 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@@ -28,6 +29,12 @@ --------------------------------------------------------------------} --Basics+instance ToSElem () where+ toSElem _ = STR ""++instance ToSElem Void where+ toSElem = absurd+ instance ToSElem Char where toSElem = STR . (:[]) toSElemList = STR@@ -39,10 +46,10 @@ toSElem = BS . LB.fromChunks . (:[]) instance ToSElem LT.Text where- toSElem = BS . LT.encodeUtf8+ toSElem = TXT instance ToSElem T.Text where- toSElem = BS . LB.fromChunks . (:[]) . T.encodeUtf8+ toSElem = TXT . LT.fromStrict instance ToSElem Bool where toSElem True = STR ""