diff --git a/Data/Object/Instances.hs b/Data/Object/Instances.hs index 3c9ae8ae..60cc6666 100644 --- a/Data/Object/Instances.hs +++ b/Data/Object/Instances.hs @@ -20,6 +20,7 @@ module Data.Object.Instances ) where import Data.Object +import Data.Object.Raw import qualified Data.ByteString.Lazy as B import Data.ByteString.Class import Web.Encodings (encodeJson) @@ -32,7 +33,7 @@ newtype Json = Json { unJson :: B.ByteString } instance SafeFromObject Json where safeFromObject = Json . helper where helper :: RawObject -> B.ByteString - helper (Scalar s) = B.concat + helper (Scalar (Raw s)) = B.concat [ toLazyByteString "\"" , encodeJson $ fromLazyByteString s , toLazyByteString "\"" @@ -47,8 +48,8 @@ instance SafeFromObject Json where , B.intercalate (toLazyByteString ",") $ map helper2 m , toLazyByteString "}" ] - helper2 :: (B.ByteString, RawObject) -> B.ByteString - helper2 (k, v) = B.concat + helper2 :: (Raw, RawObject) -> B.ByteString + helper2 (Raw k, v) = B.concat [ toLazyByteString "\"" , encodeJson $ fromLazyByteString k , toLazyByteString "\":" @@ -73,7 +74,7 @@ instance SafeFromObject Html where , toLazyByteString "" ] where helper :: RawObject -> B.ByteString - helper (Scalar s) = B.concat + helper (Scalar (Raw s)) = B.concat [ toLazyByteString "

" , toLazyByteString s , toLazyByteString "

" @@ -88,8 +89,8 @@ instance SafeFromObject Html where toLazyByteString "
" : map helper2 m ++ [ toLazyByteString "
" ] - helper2 :: (B.ByteString, RawObject) -> B.ByteString - helper2 (k, v) = B.concat + helper2 :: (Raw, RawObject) -> B.ByteString + helper2 (Raw k, v) = B.concat [ toLazyByteString "
" , toLazyByteString k , toLazyByteString "
" diff --git a/Web/Restful/Application.hs b/Web/Restful/Application.hs index dc9f5296..ce55aa4e 100644 --- a/Web/Restful/Application.hs +++ b/Web/Restful/Application.hs @@ -2,6 +2,7 @@ {-# LANGUAGE TypeSynonymInstances #-} {-# LANGUAGE ExistentialQuantification #-} {-# LANGUAGE ScopedTypeVariables #-} +{-# LANGUAGE FlexibleContexts #-} --------------------------------------------------------- -- -- Module : Web.Restful.Application @@ -24,6 +25,7 @@ module Web.Restful.Application import Web.Encodings import qualified Data.ByteString.Lazy as B import Data.Object +import Data.Object.Raw import Data.Enumerable import Control.Monad (when) @@ -42,6 +44,10 @@ import Web.Restful.Definitions import Web.Restful.Constants import Web.Restful.Resource +-- FIXME move to Data.Object.Raw +toRawObject :: ToObject o Raw Raw => o -> RawObject +toRawObject = toObject + -- | A data type that can be turned into a Hack application. class ResourceName a => RestfulApp a where -- | The encryption key to be used for encrypting client sessions. diff --git a/Web/Restful/Response.hs b/Web/Restful/Response.hs index 07ad806d..6ae34e32 100644 --- a/Web/Restful/Response.hs +++ b/Web/Restful/Response.hs @@ -1,4 +1,5 @@ {-# LANGUAGE FlexibleInstances #-} +{-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE TypeSynonymInstances #-} --------------------------------------------------------- -- @@ -38,7 +39,8 @@ module Web.Restful.Response ) where import Data.Time.Clock -import Data.Object hiding (testSuite) +import Data.Object +import Data.Object.Raw import Data.Object.Instances import Web.Encodings (formatW3) @@ -115,8 +117,8 @@ htmlResponse :: (Monad m, NoI18N lbs) => lbs -> m Reps htmlResponse = genResponse "text/html" -- | Return a response from an Object. -objectResponse :: (Monad m, ToRawObject o) => o -> m Reps -objectResponse = return . reps . toRawObject +objectResponse :: (Monad m, ToObject o Raw Raw) => o -> m Reps +objectResponse o = return $ reps $ (toObject o :: RawObject) -- HasReps instances instance HasReps () where