diff --git a/Web/Restful/Application.hs b/Web/Restful/Application.hs index ce55aa4e..28312cc1 100644 --- a/Web/Restful/Application.hs +++ b/Web/Restful/Application.hs @@ -24,7 +24,6 @@ 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) @@ -44,10 +43,6 @@ 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/I18N.hs b/Web/Restful/I18N.hs deleted file mode 100644 index 9743c8d1..00000000 --- a/Web/Restful/I18N.hs +++ /dev/null @@ -1,62 +0,0 @@ -{-# LANGUAGE TypeSynonymInstances #-} -{-# LANGUAGE FlexibleInstances #-} -{-# LANGUAGE UndecidableInstances #-} -{-# LANGUAGE OverlappingInstances #-} ---------------------------------------------------------- --- --- Module : Web.Restful.I18N --- Copyright : Michael Snoyman --- License : BSD3 --- --- Maintainer : Michael Snoyman --- Stability : Stable --- Portability : portable --- --- Simple method for internationalization. --- ---------------------------------------------------------- -module Web.Restful.I18N - ( Language - , Translator - , I18N (..) - , translateBS - , NoI18N (..) - ) where - -import qualified Data.ByteString.Lazy as B -import qualified Data.ByteString as BS -import Data.ByteString.Class - -type Language = String -type Translator = [Language] -> B.ByteString - -class I18N a where - translate :: a -> Translator - translate a langs = toLazyByteString $ helper langs where - helper [] = defTrans a - helper (l:ls) = - case tryTranslate a l of - Nothing -> helper ls - Just s -> s - - defTrans :: a -> String - tryTranslate :: a -> Language -> Maybe String - -instance I18N String where - defTrans = id - tryTranslate = const . Just - -translateBS :: I18N a => a -> Translator -translateBS a = toLazyByteString . translate a - -class NoI18N a where - noTranslate :: a -> Translator - -instance NoI18N B.ByteString where - noTranslate = const - -instance NoI18N BS.ByteString where - noTranslate = const . toLazyByteString - -instance NoI18N String where - noTranslate = const . toLazyByteString diff --git a/Web/Restful/Response.hs b/Web/Restful/Response.hs index 6ae34e32..44691429 100644 --- a/Web/Restful/Response.hs +++ b/Web/Restful/Response.hs @@ -34,23 +34,34 @@ module Web.Restful.Response , objectResponse -- * Tests , testSuite - -- * Re-export - , module Web.Restful.I18N + -- * Translation + , TranslatorBS + , noTranslate + , translateBS ) where import Data.Time.Clock import Data.Object import Data.Object.Raw +import Data.Object.Translate import Data.Object.Instances +import Data.ByteString.Lazy (ByteString) +import Data.ByteString.Class import Web.Encodings (formatW3) -import Web.Restful.I18N import Test.Framework (testGroup, Test) type ContentType = String -type Rep = (ContentType, Translator) +type TranslatorBS = [Language] -> ByteString +noTranslate :: LazyByteString lbs => lbs -> TranslatorBS +noTranslate lbs = const $ toLazyByteString lbs + +translateBS :: CanTranslate t => t -> TranslatorBS +translateBS t langs = toLazyByteString $ translate t langs + +type Rep = (ContentType, TranslatorBS) type Reps = [Rep] -- | Something which can be represented as multiple content types. @@ -106,14 +117,14 @@ response :: (Monad m, HasReps reps) => reps -> m Reps response = return . reps -- | Return a response with an arbitrary content type. -genResponse :: (Monad m, NoI18N lbs) +genResponse :: (Monad m, LazyByteString lbs) => ContentType -> lbs -> m Reps genResponse ct lbs = return [(ct, noTranslate lbs)] -- | Return a response with a text/html content type. -htmlResponse :: (Monad m, NoI18N lbs) => lbs -> m Reps +htmlResponse :: (Monad m, LazyByteString lbs) => lbs -> m Reps htmlResponse = genResponse "text/html" -- | Return a response from an Object. @@ -122,7 +133,7 @@ objectResponse o = return $ reps $ (toObject o :: RawObject) -- HasReps instances instance HasReps () where - reps _ = [("text/plain", translate "")] + reps _ = [("text/plain", noTranslate "")] instance HasReps RawObject where reps o = [ ("text/html", noTranslate $ unHtml $ safeFromObject o) diff --git a/Web/Restful/Response/AtomFeed.hs b/Web/Restful/Response/AtomFeed.hs index 2efed8bf..fa2ad788 100644 --- a/Web/Restful/Response/AtomFeed.hs +++ b/Web/Restful/Response/AtomFeed.hs @@ -31,7 +31,7 @@ data AtomFeed = AtomFeed } instance HasReps AtomFeed where reps e = - [ ("application/atom+xml", translate $ show e) + [ ("application/atom+xml", noTranslate $ show e) ] data AtomFeedEntry = AtomFeedEntry diff --git a/Web/Restful/Response/Sitemap.hs b/Web/Restful/Response/Sitemap.hs index 68e7f13e..f75a7601 100644 --- a/Web/Restful/Response/Sitemap.hs +++ b/Web/Restful/Response/Sitemap.hs @@ -79,7 +79,7 @@ instance Show SitemapResponse where instance HasReps SitemapResponse where reps res = - [ ("text/xml", translate $ show res) + [ ("text/xml", noTranslate $ show res) ] sitemap :: IO [SitemapUrl] -> Handler diff --git a/restful.cabal b/restful.cabal index e598a704..0d989903 100644 --- a/restful.cabal +++ b/restful.cabal @@ -1,5 +1,5 @@ name: restful -version: 0.1.7 +version: 0.1.8 license: BSD3 license-file: LICENSE author: Michael Snoyman @@ -47,7 +47,6 @@ library Web.Restful.Handler, Web.Restful.Application, Web.Restful.Resource, - Web.Restful.I18N, Data.Object.Instances, Hack.Middleware.MethodOverride, Web.Restful.Helpers.Auth,