yesod-core 1.4.20.2 → 1.4.21
raw patch · 6 files changed
+76/−16 lines, 6 files
Files
- ChangeLog.md +4/−0
- Yesod/Core/Class/Yesod.hs +1/−5
- Yesod/Core/Content.hs +15/−0
- Yesod/Core/Json.hs +53/−8
- Yesod/Routes/Parse.hs +1/−1
- yesod-core.cabal +2/−2
ChangeLog.md view
@@ -1,3 +1,7 @@+## 1.4.21++* Add support for `Encoding` from `aeson-0.11` [#1241](https://github.com/yesodweb/yesod/pull/1241)+ ## 1.4.20.2 * GHC 8 support
Yesod/Core/Class/Yesod.hs view
@@ -226,11 +226,7 @@ messageLoggerSource site = defaultMessageLoggerSource $ shouldLogIO site -- | Where to Load sripts from. We recommend the default value,- -- 'BottomOfBody'. Alternatively use the built in async yepnope loader:- --- -- > BottomOfHeadAsync $ loadJsYepnope $ Right $ StaticR js_modernizr_js- --- -- Or write your own async js loader.+ -- 'BottomOfBody'. jsLoader :: site -> ScriptLoadPosition site jsLoader _ = BottomOfBody
Yesod/Core/Content.hs view
@@ -251,9 +251,20 @@ #else . fromValue #endif++#if MIN_VERSION_aeson(0, 11, 0)+instance ToContent J.Encoding where+ toContent = flip ContentBuilder Nothing . J.fromEncoding+#endif+ instance HasContentType J.Value where getContentType _ = typeJson +#if MIN_VERSION_aeson(0, 11, 0)+instance HasContentType J.Encoding where+ getContentType _ = typeJson+#endif+ instance HasContentType Html where getContentType _ = typeHtml @@ -289,6 +300,10 @@ toTypedContent (RepXml c) = TypedContent typeXml c instance ToTypedContent J.Value where toTypedContent v = TypedContent typeJson (toContent v)+#if MIN_VERSION_aeson(0, 11, 0)+instance ToTypedContent J.Encoding where+ toTypedContent e = TypedContent typeJson (toContent e)+#endif instance ToTypedContent Html where toTypedContent h = TypedContent typeHtml (toContent h) instance ToTypedContent T.Text where
Yesod/Core/Json.hs view
@@ -6,6 +6,9 @@ defaultLayoutJson , jsonToRepJson , returnJson+#if MIN_VERSION_aeson(0, 11, 0)+ , returnJsonEncoding+#endif , provideJson -- * Convert to a JSON value@@ -24,6 +27,9 @@ -- * Convenience functions , jsonOrRedirect+#if MIN_VERSION_aeson(0, 11, 0)+ , jsonEncodingOrRedirect+#endif , acceptsJson ) where @@ -52,35 +58,51 @@ -- data, using the default layout for the HTML output -- ('defaultLayout'). ----- /Since: 0.3.0/+-- @since 0.3.0 defaultLayoutJson :: (Yesod site, J.ToJSON a) => WidgetT site IO () -- ^ HTML -> HandlerT site IO a -- ^ JSON -> HandlerT site IO TypedContent defaultLayoutJson w json = selectRep $ do provideRep $ defaultLayout w+#if MIN_VERSION_aeson(0, 11, 0)+ provideRep $ fmap J.toEncoding json+#else provideRep $ fmap J.toJSON json+#endif -- | Wraps a data type in a 'RepJson'. The data type must -- support conversion to JSON via 'J.ToJSON'. ----- /Since: 0.3.0/+-- @since 0.3.0 jsonToRepJson :: (Monad m, J.ToJSON a) => a -> m J.Value jsonToRepJson = return . J.toJSON {-# DEPRECATED jsonToRepJson "Use returnJson instead" #-} -- | Convert a value to a JSON representation via aeson\'s 'J.toJSON' function. ----- Since 1.2.1+-- @since 1.2.1 returnJson :: (Monad m, J.ToJSON a) => a -> m J.Value returnJson = return . J.toJSON +#if MIN_VERSION_aeson(0, 11, 0)+-- | Convert a value to a JSON representation via aeson\'s 'J.toEncoding' function.+--+-- @since 1.4.21+returnJsonEncoding :: (Monad m, J.ToJSON a) => a -> m J.Encoding+returnJsonEncoding = return . J.toEncoding+#endif+ -- | Provide a JSON representation for usage with 'selectReps', using aeson\'s--- 'J.toJSON' function to perform the conversion.+-- 'J.toJSON' (aeson >= 0.11: 'J.toEncoding') function to perform the conversion. ----- Since 1.2.1+-- @since 1.2.1 provideJson :: (Monad m, J.ToJSON a) => a -> Writer (Endo [ProvidedRep m]) ()+#if MIN_VERSION_aeson(0, 11, 0)+provideJson = provideRep . return . J.toEncoding+#else provideJson = provideRep . return . J.toJSON+#endif -- | Parse the request body to a data type as a JSON value. The -- data type must support conversion from JSON via 'J.FromJSON'.@@ -91,7 +113,7 @@ -- twice will result in a parse error on the second call, since the request -- body will no longer be available. ----- /Since: 0.3.0/+-- @since 0.3.0 parseJsonBody :: (MonadHandler m, J.FromJSON a) => m (J.Result a) parseJsonBody = do eValue <- rawRequestBody $$ runCatchC (sinkParser JP.value')@@ -129,9 +151,32 @@ => Route (HandlerSite m) -- ^ Redirect target -> a -- ^ Data to send via JSON -> m J.Value-jsonOrRedirect r j = do+jsonOrRedirect = jsonOrRedirect' J.toJSON++#if MIN_VERSION_aeson(0, 11, 0)+-- | jsonEncodingOrRedirect simplifies the scenario where a POST handler sends a different+-- response based on Accept headers:+--+-- 1. 200 with JSON data if the client prefers+-- @application\/json@ (e.g. AJAX, see 'acceptsJSON').+--+-- 2. 3xx otherwise, following the PRG pattern.+-- @since 1.4.21+jsonEncodingOrRedirect :: (MonadHandler m, J.ToJSON a)+ => Route (HandlerSite m) -- ^ Redirect target+ -> a -- ^ Data to send via JSON+ -> m J.Encoding+jsonEncodingOrRedirect = jsonOrRedirect' J.toEncoding+#endif++jsonOrRedirect' :: (MonadHandler m, J.ToJSON a)+ => (a -> b)+ -> Route (HandlerSite m) -- ^ Redirect target+ -> a -- ^ Data to send via JSON+ -> m b+jsonOrRedirect' f r j = do q <- acceptsJson- if q then return (J.toJSON j)+ if q then return (f j) else redirect r -- | Returns @True@ if the client prefers @application\/json@ as
Yesod/Routes/Parse.hs view
@@ -58,7 +58,7 @@ { quoteExp = lift . resourcesFromString } --- | Convert a multi-line string to a set of resources. See documentation for+-- | Converts a multi-line string to a set of resources. See documentation for -- the format of this string. This is a partial function which calls 'error' on -- invalid input. resourcesFromString :: String -> [ResourceTree String]
yesod-core.cabal view
@@ -1,5 +1,5 @@ name: yesod-core-version: 1.4.20.2+version: 1.4.21 license: MIT license-file: LICENSE author: Michael Snoyman <michael@snoyman.com>@@ -26,7 +26,7 @@ , time >= 1.1.4 , wai >= 3.0 , wai-extra >= 3.0.7- , bytestring >= 0.9.1.4+ , bytestring >= 0.10 , text >= 0.7 , template-haskell , path-pieces >= 0.1.2 && < 0.3