Compatibility layer for previous Yesod
This commit is contained in:
parent
5901f61d3a
commit
75a450059b
@ -1,8 +1,14 @@
|
|||||||
{-# LANGUAGE TypeSynonymInstances #-}
|
{-# LANGUAGE TypeSynonymInstances #-}
|
||||||
{-# OPTIONS_GHC -fno-warn-orphans #-}
|
{-# OPTIONS_GHC -fno-warn-orphans #-}
|
||||||
module Yesod.Json
|
module Yesod.Json
|
||||||
( defaultLayoutJson
|
( -- ^ Convert from a JSON value
|
||||||
|
defaultLayoutJson
|
||||||
, jsonToRepJson
|
, jsonToRepJson
|
||||||
|
-- ^ Compatibility wrapper for old API
|
||||||
|
, Json
|
||||||
|
, jsonScalar
|
||||||
|
, jsonList
|
||||||
|
, jsonMap
|
||||||
) where
|
) where
|
||||||
|
|
||||||
import Yesod.Handler (GHandler)
|
import Yesod.Handler (GHandler)
|
||||||
@ -14,6 +20,9 @@ import Yesod.Core (defaultLayout, Yesod)
|
|||||||
import Yesod.Widget (GWidget)
|
import Yesod.Widget (GWidget)
|
||||||
import qualified Data.JSON.Types as J
|
import qualified Data.JSON.Types as J
|
||||||
import qualified Text.JSON.Enumerator as J
|
import qualified Text.JSON.Enumerator as J
|
||||||
|
import Data.Text.Lazy (pack)
|
||||||
|
import Control.Arrow (first)
|
||||||
|
import Data.Map (fromList)
|
||||||
|
|
||||||
instance ToContent J.Value where
|
instance ToContent J.Value where
|
||||||
toContent = flip ContentBuilder Nothing . J.renderValue
|
toContent = flip ContentBuilder Nothing . J.renderValue
|
||||||
@ -31,3 +40,14 @@ defaultLayoutJson w json = do
|
|||||||
-- | Wraps the 'Content' generated by 'jsonToContent' in a 'RepJson'.
|
-- | Wraps the 'Content' generated by 'jsonToContent' in a 'RepJson'.
|
||||||
jsonToRepJson :: J.Value -> GHandler sub master RepJson
|
jsonToRepJson :: J.Value -> GHandler sub master RepJson
|
||||||
jsonToRepJson = return . RepJson . toContent
|
jsonToRepJson = return . RepJson . toContent
|
||||||
|
|
||||||
|
type Json = J.Value
|
||||||
|
|
||||||
|
jsonScalar :: String -> Json
|
||||||
|
jsonScalar = J.ValueAtom . J.AtomText . pack
|
||||||
|
|
||||||
|
jsonList :: [Json] -> Json
|
||||||
|
jsonList = J.ValueArray
|
||||||
|
|
||||||
|
jsonMap :: [(String, Json)] -> Json
|
||||||
|
jsonMap = J.ValueObject . fromList . map (first pack)
|
||||||
|
|||||||
@ -16,6 +16,8 @@ library
|
|||||||
, yesod-core >= 0.7 && < 0.8
|
, yesod-core >= 0.7 && < 0.8
|
||||||
, json-enumerator >= 0.0 && < 0.1
|
, json-enumerator >= 0.0 && < 0.1
|
||||||
, json-types >= 0.1 && < 0.2
|
, json-types >= 0.1 && < 0.2
|
||||||
|
, containers >= 0.2 && < 0.5
|
||||||
|
, text >= 0.8 && < 0.12
|
||||||
exposed-modules: Yesod.Json
|
exposed-modules: Yesod.Json
|
||||||
ghc-options: -Wall
|
ghc-options: -Wall
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user