From ee661fef093fcabbf6380972590871f4d1a427c1 Mon Sep 17 00:00:00 2001 From: Michael Snoyman Date: Sat, 25 Dec 2010 23:30:16 +0200 Subject: [PATCH 01/10] first commit --- README | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 README diff --git a/README b/README new file mode 100644 index 00000000..e69de29b From 31a1b314816a41ccde5f8d304fb2471e4a74aed2 Mon Sep 17 00:00:00 2001 From: Michael Snoyman Date: Sat, 25 Dec 2010 23:30:42 +0200 Subject: [PATCH 02/10] Code import --- LICENSE | 25 +++++++++++++++++++++++++ Setup.lhs | 7 +++++++ Yesod/Json.hs | 33 +++++++++++++++++++++++++++++++++ yesod-json.cabal | 24 ++++++++++++++++++++++++ 4 files changed, 89 insertions(+) create mode 100644 LICENSE create mode 100755 Setup.lhs create mode 100644 Yesod/Json.hs create mode 100644 yesod-json.cabal diff --git a/LICENSE b/LICENSE new file mode 100644 index 00000000..8643e5d8 --- /dev/null +++ b/LICENSE @@ -0,0 +1,25 @@ +The following license covers this documentation, and the source code, except +where otherwise indicated. + +Copyright 2010, Michael Snoyman. All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +* Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +* Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS "AS IS" AND ANY EXPRESS OR +IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO +EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY DIRECT, INDIRECT, +INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT +NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, +OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/Setup.lhs b/Setup.lhs new file mode 100755 index 00000000..06e2708f --- /dev/null +++ b/Setup.lhs @@ -0,0 +1,7 @@ +#!/usr/bin/env runhaskell + +> module Main where +> import Distribution.Simple + +> main :: IO () +> main = defaultMain diff --git a/Yesod/Json.hs b/Yesod/Json.hs new file mode 100644 index 00000000..d35a4710 --- /dev/null +++ b/Yesod/Json.hs @@ -0,0 +1,33 @@ +{-# LANGUAGE TypeSynonymInstances #-} +{-# OPTIONS_GHC -fno-warn-orphans #-} +module Yesod.Json + ( defaultLayoutJson + , jsonToRepJson + ) where + +import Yesod.Handler (GHandler) +import Yesod.Content + ( ToContent (toContent), RepHtmlJson (RepHtmlJson), RepHtml (RepHtml) + , RepJson (RepJson), Content (ContentBuilder) + ) +import Yesod.Core (defaultLayout, Yesod) +import Yesod.Widget (GWidget) +import qualified Data.JSON.Types as J +import qualified Text.JSON.Enumerator as J + +instance ToContent J.Value where + toContent = flip ContentBuilder Nothing . J.renderValue + +-- | Provide both an HTML and JSON representation for a piece of data, using +-- the default layout for the HTML output ('defaultLayout'). +defaultLayoutJson :: Yesod master + => GWidget sub master () + -> J.Value + -> GHandler sub master RepHtmlJson +defaultLayoutJson w json = do + RepHtml html' <- defaultLayout w + return $ RepHtmlJson html' $ toContent json + +-- | Wraps the 'Content' generated by 'jsonToContent' in a 'RepJson'. +jsonToRepJson :: J.Value -> GHandler sub master RepJson +jsonToRepJson = return . RepJson . toContent diff --git a/yesod-json.cabal b/yesod-json.cabal new file mode 100644 index 00000000..132a04c4 --- /dev/null +++ b/yesod-json.cabal @@ -0,0 +1,24 @@ +name: yesod-json +version: 0.7.0 +license: BSD3 +license-file: LICENSE +author: Michael Snoyman +maintainer: Michael Snoyman +synopsis: Generate content for Yesod using the json-types package. +category: Web, Yesod +stability: Stable +cabal-version: >= 1.6 +build-type: Simple +homepage: http://docs.yesodweb.com/ + +library + build-depends: base >= 4 && < 5 + , yesod-core >= 0.7 && < 0.8 + , json-enumerator >= 0.0 && < 0.1 + , json-types >= 0.1 && < 0.2 + exposed-modules: Yesod.Json + ghc-options: -Wall + +source-repository head + type: git + location: git://github.com/snoyberg/yesod-json.git From 5901f61d3a3846cb4e99e1974042e323bdeadd3d Mon Sep 17 00:00:00 2001 From: Michael Snoyman Date: Wed, 19 Jan 2011 23:50:43 +0200 Subject: [PATCH 03/10] Version change --- yesod-json.cabal | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/yesod-json.cabal b/yesod-json.cabal index 132a04c4..5c5d15d4 100644 --- a/yesod-json.cabal +++ b/yesod-json.cabal @@ -1,5 +1,5 @@ name: yesod-json -version: 0.7.0 +version: 0.0.0 license: BSD3 license-file: LICENSE author: Michael Snoyman From 75a450059bd58b63c483cd475d3256817c3d6c79 Mon Sep 17 00:00:00 2001 From: Michael Snoyman Date: Thu, 3 Feb 2011 21:58:05 +0200 Subject: [PATCH 04/10] Compatibility layer for previous Yesod --- Yesod/Json.hs | 22 +++++++++++++++++++++- yesod-json.cabal | 2 ++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/Yesod/Json.hs b/Yesod/Json.hs index d35a4710..4f83f4d5 100644 --- a/Yesod/Json.hs +++ b/Yesod/Json.hs @@ -1,8 +1,14 @@ {-# LANGUAGE TypeSynonymInstances #-} {-# OPTIONS_GHC -fno-warn-orphans #-} module Yesod.Json - ( defaultLayoutJson + ( -- ^ Convert from a JSON value + defaultLayoutJson , jsonToRepJson + -- ^ Compatibility wrapper for old API + , Json + , jsonScalar + , jsonList + , jsonMap ) where import Yesod.Handler (GHandler) @@ -14,6 +20,9 @@ import Yesod.Core (defaultLayout, Yesod) import Yesod.Widget (GWidget) import qualified Data.JSON.Types 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 toContent = flip ContentBuilder Nothing . J.renderValue @@ -31,3 +40,14 @@ defaultLayoutJson w json = do -- | Wraps the 'Content' generated by 'jsonToContent' in a 'RepJson'. jsonToRepJson :: J.Value -> GHandler sub master RepJson 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) diff --git a/yesod-json.cabal b/yesod-json.cabal index 5c5d15d4..95147a5d 100644 --- a/yesod-json.cabal +++ b/yesod-json.cabal @@ -16,6 +16,8 @@ library , yesod-core >= 0.7 && < 0.8 , json-enumerator >= 0.0 && < 0.1 , json-types >= 0.1 && < 0.2 + , containers >= 0.2 && < 0.5 + , text >= 0.8 && < 0.12 exposed-modules: Yesod.Json ghc-options: -Wall From 3bedd2bf753272b272fb8d5f94413af4cb284fe4 Mon Sep 17 00:00:00 2001 From: Michael Snoyman Date: Thu, 24 Feb 2011 21:16:19 +0200 Subject: [PATCH 05/10] Version bump --- Yesod/Json.hs | 4 ++-- yesod-json.cabal | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Yesod/Json.hs b/Yesod/Json.hs index 4f83f4d5..4619bdec 100644 --- a/Yesod/Json.hs +++ b/Yesod/Json.hs @@ -1,10 +1,10 @@ {-# LANGUAGE TypeSynonymInstances #-} {-# OPTIONS_GHC -fno-warn-orphans #-} module Yesod.Json - ( -- ^ Convert from a JSON value + ( -- * Convert from a JSON value defaultLayoutJson , jsonToRepJson - -- ^ Compatibility wrapper for old API + -- * Compatibility wrapper for old API , Json , jsonScalar , jsonList diff --git a/yesod-json.cabal b/yesod-json.cabal index 95147a5d..d4c46142 100644 --- a/yesod-json.cabal +++ b/yesod-json.cabal @@ -1,5 +1,5 @@ name: yesod-json -version: 0.0.0 +version: 0.0.0.1 license: BSD3 license-file: LICENSE author: Michael Snoyman From 56d22c4fe22cf773f5c13d4076b046aed82a394d Mon Sep 17 00:00:00 2001 From: Michael Snoyman Date: Tue, 15 Mar 2011 23:32:10 +0200 Subject: [PATCH 06/10] Switch to aeson --- Yesod/Json.hs | 15 ++++++++------- yesod-json.cabal | 8 ++++---- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/Yesod/Json.hs b/Yesod/Json.hs index 4619bdec..f4752c50 100644 --- a/Yesod/Json.hs +++ b/Yesod/Json.hs @@ -18,14 +18,15 @@ import Yesod.Content ) import Yesod.Core (defaultLayout, Yesod) import Yesod.Widget (GWidget) -import qualified Data.JSON.Types as J -import qualified Text.JSON.Enumerator as J -import Data.Text.Lazy (pack) +import qualified Data.Aeson as J +import Data.Aeson.Encode (fromValue) +import Data.Text (pack) import Control.Arrow (first) import Data.Map (fromList) +import qualified Data.Vector as V instance ToContent J.Value where - toContent = flip ContentBuilder Nothing . J.renderValue + toContent = flip ContentBuilder Nothing . fromValue -- | Provide both an HTML and JSON representation for a piece of data, using -- the default layout for the HTML output ('defaultLayout'). @@ -44,10 +45,10 @@ jsonToRepJson = return . RepJson . toContent type Json = J.Value jsonScalar :: String -> Json -jsonScalar = J.ValueAtom . J.AtomText . pack +jsonScalar = J.String . pack jsonList :: [Json] -> Json -jsonList = J.ValueArray +jsonList = J.Array . V.fromList jsonMap :: [(String, Json)] -> Json -jsonMap = J.ValueObject . fromList . map (first pack) +jsonMap = J.Object . fromList . map (first pack) diff --git a/yesod-json.cabal b/yesod-json.cabal index d4c46142..4056493a 100644 --- a/yesod-json.cabal +++ b/yesod-json.cabal @@ -1,5 +1,5 @@ name: yesod-json -version: 0.0.0.1 +version: 0.1.0 license: BSD3 license-file: LICENSE author: Michael Snoyman @@ -14,10 +14,10 @@ homepage: http://docs.yesodweb.com/ library build-depends: base >= 4 && < 5 , yesod-core >= 0.7 && < 0.8 - , json-enumerator >= 0.0 && < 0.1 - , json-types >= 0.1 && < 0.2 - , containers >= 0.2 && < 0.5 + , aeson >= 0.3.1.1 && < 0.4 , text >= 0.8 && < 0.12 + , vector + , containers exposed-modules: Yesod.Json ghc-options: -Wall From 42be5de2d11ecfe5cb69d9c89477292faeb6312e Mon Sep 17 00:00:00 2001 From: Michael Snoyman Date: Sat, 30 Apr 2011 21:28:28 +0300 Subject: [PATCH 07/10] Minor fixes not in Github --- Yesod/Json.hs | 5 +++++ yesod-json.cabal | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/Yesod/Json.hs b/Yesod/Json.hs index f4752c50..83c03538 100644 --- a/Yesod/Json.hs +++ b/Yesod/Json.hs @@ -52,3 +52,8 @@ jsonList = J.Array . V.fromList jsonMap :: [(String, Json)] -> Json jsonMap = J.Object . fromList . map (first pack) + +{- FIXME +instance ToJavascript J.Value where + toJavascript = fromLazyText . decodeUtf8 . toLazyByteString . JE.renderValue +-} diff --git a/yesod-json.cabal b/yesod-json.cabal index 4056493a..4fa1af67 100644 --- a/yesod-json.cabal +++ b/yesod-json.cabal @@ -13,7 +13,7 @@ homepage: http://docs.yesodweb.com/ library build-depends: base >= 4 && < 5 - , yesod-core >= 0.7 && < 0.8 + , yesod-core >= 0.8 && < 0.9 , aeson >= 0.3.1.1 && < 0.4 , text >= 0.8 && < 0.12 , vector From de76f34c8c0ff8530de8f6772a61be3af38f1a9d Mon Sep 17 00:00:00 2001 From: Michael Snoyman Date: Sat, 30 Apr 2011 21:32:55 +0300 Subject: [PATCH 08/10] ToJavascript instance for Value --- Yesod/Json.hs | 8 +++++--- yesod-json.cabal | 3 ++- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/Yesod/Json.hs b/Yesod/Json.hs index 83c03538..bdc8ccc1 100644 --- a/Yesod/Json.hs +++ b/Yesod/Json.hs @@ -19,11 +19,15 @@ import Yesod.Content import Yesod.Core (defaultLayout, Yesod) import Yesod.Widget (GWidget) import qualified Data.Aeson as J +import qualified Data.Aeson.Encode as JE import Data.Aeson.Encode (fromValue) import Data.Text (pack) import Control.Arrow (first) import Data.Map (fromList) import qualified Data.Vector as V +import Text.Julius (ToJavascript (..)) +import Data.Text.Lazy.Builder (fromLazyText) +import Data.Text.Lazy.Encoding (decodeUtf8) instance ToContent J.Value where toContent = flip ContentBuilder Nothing . fromValue @@ -53,7 +57,5 @@ jsonList = J.Array . V.fromList jsonMap :: [(String, Json)] -> Json jsonMap = J.Object . fromList . map (first pack) -{- FIXME instance ToJavascript J.Value where - toJavascript = fromLazyText . decodeUtf8 . toLazyByteString . JE.renderValue --} + toJavascript = fromLazyText . decodeUtf8 . JE.encode diff --git a/yesod-json.cabal b/yesod-json.cabal index 4fa1af67..4d792b9f 100644 --- a/yesod-json.cabal +++ b/yesod-json.cabal @@ -1,5 +1,5 @@ name: yesod-json -version: 0.1.0 +version: 0.1.1 license: BSD3 license-file: LICENSE author: Michael Snoyman @@ -16,6 +16,7 @@ library , yesod-core >= 0.8 && < 0.9 , aeson >= 0.3.1.1 && < 0.4 , text >= 0.8 && < 0.12 + , hamlet >= 0.8 && < 0.9 , vector , containers exposed-modules: Yesod.Json From 78d08e0a20d345c445b4e5722e4c9513606e18c5 Mon Sep 17 00:00:00 2001 From: Michael Snoyman Date: Thu, 30 Jun 2011 15:45:40 +0300 Subject: [PATCH 09/10] Force blaze-textual < 0.2 --- yesod-json.cabal | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/yesod-json.cabal b/yesod-json.cabal index 4d792b9f..db20b79a 100644 --- a/yesod-json.cabal +++ b/yesod-json.cabal @@ -1,15 +1,15 @@ name: yesod-json -version: 0.1.1 +version: 0.1.1.1 license: BSD3 license-file: LICENSE author: Michael Snoyman maintainer: Michael Snoyman -synopsis: Generate content for Yesod using the json-types package. +synopsis: Generate content for Yesod using the aeson package. category: Web, Yesod stability: Stable cabal-version: >= 1.6 build-type: Simple -homepage: http://docs.yesodweb.com/ +homepage: http://www.yesodweb.com/ library build-depends: base >= 4 && < 5 @@ -19,6 +19,7 @@ library , hamlet >= 0.8 && < 0.9 , vector , containers + , blaze-textual >= 0.1 && < 0.2 exposed-modules: Yesod.Json ghc-options: -Wall From 41a198225f137610cae208190aca443c56efd332 Mon Sep 17 00:00:00 2001 From: Michael Snoyman Date: Tue, 19 Jul 2011 09:40:49 +0300 Subject: [PATCH 10/10] yesod 0.9 --- yesod-json.cabal | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/yesod-json.cabal b/yesod-json.cabal index db20b79a..7fe6f4aa 100644 --- a/yesod-json.cabal +++ b/yesod-json.cabal @@ -1,5 +1,5 @@ name: yesod-json -version: 0.1.1.1 +version: 0.2.0 license: BSD3 license-file: LICENSE author: Michael Snoyman @@ -13,10 +13,10 @@ homepage: http://www.yesodweb.com/ library build-depends: base >= 4 && < 5 - , yesod-core >= 0.8 && < 0.9 + , yesod-core >= 0.9 && < 0.10 , aeson >= 0.3.1.1 && < 0.4 , text >= 0.8 && < 0.12 - , hamlet >= 0.8 && < 0.9 + , hamlet >= 0.9 && < 0.10 , vector , containers , blaze-textual >= 0.1 && < 0.2