packages feed

hastache 0.2.0 → 0.2.1

raw patch · 3 files changed

+113/−22 lines, 3 filesPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

API changes (from Hackage documentation)

- Text.Hastache: MuLambda :: (ByteString -> ByteString) -> MuType m
+ Text.Hastache: MuLambda :: (ByteString -> a) -> MuType m
- Text.Hastache: MuLambdaM :: (ByteString -> m ByteString) -> MuType m
+ Text.Hastache: MuLambdaM :: (ByteString -> m a) -> MuType m

Files

Text/Hastache.hs view
@@ -12,6 +12,30 @@ {- | Haskell implementation of Mustache templates  See homepage for examples of usage: <http://github.com/lymar/hastache>++Simplest example:++@+module Main where + +import Text.Hastache +import Text.Hastache.Context +import qualified Data.ByteString.Lazy as LZ + +main = do +    res <- hastacheStr defaultConfig (encodeStr template)  +        (mkStrContext context) +    LZ.putStrLn res +    where +    template = \"Hello, {{name}}!\" +    context \"name\" = MuVariable \"Haskell\"+@++Result:++@+Hello, Haskell!+@ -} module Text.Hastache (       hastacheStr@@ -107,11 +131,11 @@     toLByteString k = k ~> encodeStr ~> toLBS      data MuType m = -    forall a. MuVar a => MuVariable a           |-    MuList [MuContext m]                        |-    MuBool Bool                                 |-    MuLambda (ByteString -> ByteString)         |-    MuLambdaM (ByteString -> m ByteString)      |+    forall a. MuVar a => MuVariable a                   |+    MuList [MuContext m]                                |+    MuBool Bool                                         |+    forall a. MuVar a => MuLambda (ByteString -> a)     |+    forall a. MuVar a => MuLambdaM (ByteString -> m a)  |     MuNothing  instance Show (MuType m) where@@ -329,13 +353,13 @@                             next afterSection                     Just (MuLambda func) ->                          if normalSection then do-                            func sectionContent ~> addResBS+                            func sectionContent ~> toLByteString ~> addResLZ                             next afterSection                         else do next afterSection                     Just (MuLambdaM func) ->                          if normalSection then do                             res <- lift (func sectionContent)-                            addResBS res+                            toLByteString res ~> addResLZ                             next afterSection                         else do next afterSection                     _ -> next afterSection
Text/Hastache/Context.hs view
@@ -99,6 +99,61 @@ UPPER (MONADIC) )cidanom( esrever @++Supported field types:++ * String+ + * Char+ + * Double++ * Float++ * Int++ * Int8++ * Int16++ * Int32++ * Int64++ * Integer++ * Word++ * Word8++ * Word16++ * Word32++ * Word64++ * Data.ByteString.ByteString++ * Data.ByteString.Lazy.ByteString+ + * Data.Text.Text++ * Data.Text.Lazy.Text+ + * Bool+ + * Data.ByteString.ByteString -> Data.ByteString.ByteString+ + * String -> String+ + * Data.ByteString.ByteString -> Data.ByteString.Lazy.ByteString+ + * MonadIO m => Data.ByteString.ByteString -> m Data.ByteString.ByteString+ + * MonadIO m => String -> m String+ + * MonadIO m => Data.ByteString.ByteString -> m Data.ByteString.Lazy.ByteString+  -} mkGenericContext :: (Monad m, Data a, Typeable1 m) => a -> MuContext m mkGenericContext val = toGenTemp val ~> convertGenTempToContext@@ -139,31 +194,43 @@     `extQ` (\(i::Text.Text)         -> MuVariable i ~> TSimple)     `extQ` (\(i::LText.Text)        -> MuVariable i ~> TSimple)     `extQ` (\(i::Bool)              -> MuBool i ~> TSimple)-    `extQ` muLambdaBS-    `extQ` muLambdaS-    `extQ` muLambdaMBS-    `extQ` muLambdaMS+    +    `extQ` muLambdaBSBS+    `extQ` muLambdaSS+    `extQ` muLambdaBSLBS+    +    `extQ` muLambdaMBSBS+    `extQ` muLambdaMSS+    `extQ` muLambdaMBSLBS     where     obj a = case dataTypeRep (dataTypeOf a) of         AlgRep [c] -> toGenTemp a         _ -> TUnknown     list a = map procField a ~> TList -    muLambdaMBS :: (BS.ByteString -> m BS.ByteString) -> TD m-    muLambdaMBS f = MuLambdaM f ~> TSimple+    muLambdaBSBS :: (BS.ByteString -> BS.ByteString) -> TD m+    muLambdaBSBS f = MuLambda f ~> TSimple -    muLambdaMS :: forall m. Monad m => (String -> m String) -> TD m-    muLambdaMS f = MuLambdaM fd ~> TSimple+    muLambdaSS :: (String -> String) -> TD m+    muLambdaSS f = MuLambda fd ~> TSimple         where-        fd s = decodeStr s ~> f >>= return . encodeStr+        fd s = decodeStr s ~> f -    muLambdaBS :: (BS.ByteString -> BS.ByteString) -> TD m-    muLambdaBS f = MuLambda f ~> TSimple+    muLambdaBSLBS :: (BS.ByteString -> LBS.ByteString) -> TD m+    muLambdaBSLBS f = MuLambda f ~> TSimple -    muLambdaS :: (String -> String) -> TD m-    muLambdaS f = MuLambda fd ~> TSimple+    -- monadic++    muLambdaMBSBS :: (BS.ByteString -> m BS.ByteString) -> TD m+    muLambdaMBSBS f = MuLambdaM f ~> TSimple++    muLambdaMSS :: (String -> m String) -> TD m+    muLambdaMSS f = MuLambdaM fd ~> TSimple         where-        fd s = decodeStr s ~> f ~> encodeStr +        fd s = decodeStr s ~> f++    muLambdaMBSLBS :: (BS.ByteString -> m LBS.ByteString) -> TD m+    muLambdaMBSLBS f = MuLambdaM f ~> TSimple  convertGenTempToContext :: TD t -> MuContext t convertGenTempToContext v = mkMap "" Map.empty v ~> mkMapContext
hastache.cabal view
@@ -1,5 +1,5 @@ name:            hastache-version:         0.2.0+version:         0.2.1 license:         BSD3 license-file:    LICENSE category:        Text