Skip to content

Commit

Permalink
mkGenericContext refactoring. Added supported field types comment
Browse files Browse the repository at this point in the history
  • Loading branch information
lymar committed Nov 8, 2011
1 parent 9defebf commit 3f749e9
Showing 1 changed file with 81 additions and 14 deletions.
95 changes: 81 additions & 14 deletions Text/Hastache/Context.hs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,61 @@ esrever
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
Expand Down Expand Up @@ -139,31 +194,43 @@ procField =
`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

muLambdaBSLBS :: (BS.ByteString -> LBS.ByteString) -> TD m
muLambdaBSLBS f = MuLambda f ~> TSimple

muLambdaBS :: (BS.ByteString -> BS.ByteString) -> TD m
muLambdaBS f = MuLambda f ~> TSimple
-- monadic

muLambdaS :: (String -> String) -> TD m
muLambdaS f = MuLambda fd ~> TSimple
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
Expand Down

0 comments on commit 3f749e9

Please sign in to comment.