diff --git a/yesod-core/Yesod/Content.hs b/yesod-core/Yesod/Content.hs index 3276b412..0ececbb8 100644 --- a/yesod-core/Yesod/Content.hs +++ b/yesod-core/Yesod/Content.hs @@ -67,6 +67,11 @@ import Data.String (IsString (fromString)) import Network.Wai (FilePart) import Data.Conduit (Source, ResourceT, Flush) +import qualified Data.Aeson as J +import Data.Aeson.Encode (fromValue) +import qualified Blaze.ByteString.Builder.Char.Utf8 as Blaze +import Data.Text.Lazy.Builder (toLazyText) + data Content = ContentBuilder !Builder !(Maybe Int) -- ^ The content and optional content length. | ContentSource !(Source (ResourceT IO) (Flush Builder)) | ContentFile !FilePath !(Maybe FilePart) @@ -250,3 +255,9 @@ instance HasReps a => HasReps (DontFullyEvaluate a) where instance ToContent a => ToContent (DontFullyEvaluate a) where toContent (DontFullyEvaluate a) = ContentDontEvaluate $ toContent a + +instance ToContent J.Value where + toContent = flip ContentBuilder Nothing + . Blaze.fromLazyText + . toLazyText + . fromValue diff --git a/yesod-core/yesod-core.cabal b/yesod-core/yesod-core.cabal index ab8dd812..07ef4858 100644 --- a/yesod-core/yesod-core.cabal +++ b/yesod-core/yesod-core.cabal @@ -1,5 +1,5 @@ name: yesod-core -version: 1.1.4.2 +version: 1.1.5 license: MIT license-file: LICENSE author: Michael Snoyman @@ -57,7 +57,7 @@ library , path-pieces >= 0.1.2 && < 0.2 , hamlet >= 1.1 && < 1.2 , shakespeare >= 1.0 && < 1.1 - , shakespeare-js >= 1.0 && < 1.1 + , shakespeare-js >= 1.0.2 && < 1.2 , shakespeare-css >= 1.0 && < 1.1 , shakespeare-i18n >= 1.0 && < 1.1 , blaze-builder >= 0.2.1.4 && < 0.4 diff --git a/yesod-form/Yesod/Form/Jquery.hs b/yesod-form/Yesod/Form/Jquery.hs index 71719721..afa3b2cd 100644 --- a/yesod-form/Yesod/Form/Jquery.hs +++ b/yesod-form/Yesod/Form/Jquery.hs @@ -20,10 +20,11 @@ import Yesod.Widget import Data.Time (Day) import Data.Default import Text.Hamlet (shamlet) -import Text.Julius (julius) +import Text.Julius (julius, rawJS) import Data.Text (Text, pack, unpack) import Data.Monoid (mconcat) import Yesod.Core (RenderMessage) +import Data.Aeson (toJSON) -- | Gets the Google hosted jQuery UI 1.8 CSS file with the given theme. googleHostedJqueryUiCss :: Text -> Text @@ -73,14 +74,14 @@ $newline never addStylesheet' urlJqueryUiCss toWidget [julius| $(function(){ - var i = document.getElementById("#{theId}"); + var i = document.getElementById("#{rawJS theId}"); if (i.type != "date") { $(i).datepicker({ dateFormat:'yy-mm-dd', changeMonth:#{jsBool $ jdsChangeMonth jds}, changeYear:#{jsBool $ jdsChangeYear jds}, - numberOfMonths:#{mos $ jdsNumberOfMonths jds}, - yearRange:"#{jdsYearRange jds}" + numberOfMonths:#{rawJS $ mos $ jdsNumberOfMonths jds}, + yearRange:#{toJSON $ jdsYearRange jds} }); } }); @@ -89,8 +90,8 @@ $(function(){ } where showVal = either id (pack . show) - jsBool True = "true" :: Text - jsBool False = "false" :: Text + jsBool True = toJSON True + jsBool False = toJSON False mos (Left i) = show i mos (Right (x, y)) = concat [ "[" @@ -113,7 +114,7 @@ $newline never addScript' urlJqueryUiJs addStylesheet' urlJqueryUiCss toWidget [julius| -$(function(){$("##{theId}").autocomplete({source:"@{src}",minLength:2})}); +$(function(){$("##{rawJS theId}").autocomplete({source:"@{src}",minLength:2})}); |] , fieldEnctype = UrlEncoded } diff --git a/yesod-form/Yesod/Form/Nic.hs b/yesod-form/Yesod/Form/Nic.hs index 4f89b8d0..3127bebb 100644 --- a/yesod-form/Yesod/Form/Nic.hs +++ b/yesod-form/Yesod/Form/Nic.hs @@ -16,7 +16,7 @@ import Yesod.Form import Yesod.Widget import Text.HTML.SanitizeXSS (sanitizeBalance) import Text.Hamlet (Html, shamlet) -import Text.Julius (julius) +import Text.Julius (julius, rawJS) #if MIN_VERSION_blaze_html(0, 5, 0) import Text.Blaze (preEscapedToMarkup) import Text.Blaze.Html.Renderer.String (renderHtml) @@ -46,10 +46,10 @@ $newline never toWidget $ case jsLoader master of BottomOfHeadBlocking -> [julius| -bkLib.onDomLoaded(function(){new nicEditor({fullPanel:true}).panelInstance("#{theId}")}); +bkLib.onDomLoaded(function(){new nicEditor({fullPanel:true}).panelInstance("#{rawJS theId}")}); |] _ -> [julius| -(function(){new nicEditor({fullPanel:true}).panelInstance("#{theId}")})(); +(function(){new nicEditor({fullPanel:true}).panelInstance("#{rawJS theId}")})(); |] , fieldEnctype = UrlEncoded } diff --git a/yesod-form/yesod-form.cabal b/yesod-form/yesod-form.cabal index 81bda2dc..ceb01525 100644 --- a/yesod-form/yesod-form.cabal +++ b/yesod-form/yesod-form.cabal @@ -19,7 +19,7 @@ library , time >= 1.1.4 , hamlet >= 1.1 && < 1.2 , shakespeare-css >= 1.0 && < 1.1 - , shakespeare-js >= 1.0 && < 1.1 + , shakespeare-js >= 1.0.2 && < 1.2 , persistent >= 1.0 && < 1.1 , template-haskell , transformers >= 0.2.2 && < 0.4 @@ -36,6 +36,7 @@ library , blaze-markup >= 0.5.1 && < 0.6 , attoparsec >= 0.10 && < 0.11 , crypto-api >= 0.8 && < 0.11 + , aeson exposed-modules: Yesod.Form Yesod.Form.Class diff --git a/yesod-json/Yesod/Json.hs b/yesod-json/Yesod/Json.hs index 28d16875..eb46612a 100644 --- a/yesod-json/Yesod/Json.hs +++ b/yesod-json/Yesod/Json.hs @@ -51,11 +51,13 @@ import Network.Wai.Parse (parseHttpAccept) import qualified Data.ByteString.Char8 as B8 import Safe (headMay) +#if !MIN_VERSION_yesod_core(1, 1, 5) instance ToContent J.Value where toContent = flip ContentBuilder Nothing . Blaze.fromLazyText . toLazyText . fromValue +#endif -- | Provide both an HTML and JSON representation for a piece of -- data, using the default layout for the HTML output @@ -97,8 +99,10 @@ parseJsonBody_ = do J.Error s -> invalidArgs [pack s] J.Success a -> return a +#if !MIN_VERSION_shakespeare_js(1, 0, 2) instance ToJavascript J.Value where toJavascript = fromLazyText . decodeUtf8 . JE.encode +#endif -- | Convert a list of pairs to an 'J.Object'. object :: J.ToJSON a => [(Text, a)] -> J.Value diff --git a/yesod-json/yesod-json.cabal b/yesod-json/yesod-json.cabal index b43e1ef6..c9115f04 100644 --- a/yesod-json/yesod-json.cabal +++ b/yesod-json/yesod-json.cabal @@ -1,5 +1,5 @@ name: yesod-json -version: 1.1.1 +version: 1.1.2 license: MIT license-file: LICENSE author: Michael Snoyman @@ -18,7 +18,7 @@ library , yesod-routes >= 1.1 && < 1.2 , aeson >= 0.5 , text >= 0.8 && < 1.0 - , shakespeare-js >= 1.0 && < 1.1 + , shakespeare-js >= 1.0 && < 1.2 , vector >= 0.9 , containers >= 0.2 , blaze-builder diff --git a/yesod/yesod.cabal b/yesod/yesod.cabal index 61f2b639..ca10b74e 100644 --- a/yesod/yesod.cabal +++ b/yesod/yesod.cabal @@ -1,5 +1,5 @@ name: yesod -version: 1.1.3.2 +version: 1.1.4 license: MIT license-file: LICENSE author: Michael Snoyman @@ -27,7 +27,7 @@ extra-source-files: library build-depends: base >= 4.3 && < 5 - , yesod-core >= 1.1 && < 1.2 + , yesod-core >= 1.1.5 && < 1.2 , yesod-auth >= 1.1 && < 1.2 , yesod-json >= 1.1 && < 1.2 , yesod-persistent >= 1.1 && < 1.2 @@ -38,7 +38,7 @@ library , wai >= 1.3 && < 1.4 , wai-extra >= 1.3 && < 1.4 , hamlet >= 1.1 && < 1.2 - , shakespeare-js >= 1.0 && < 1.1 + , shakespeare-js >= 1.0.2 && < 1.2 , shakespeare-css >= 1.0 && < 1.1 , warp >= 1.3 && < 1.4 , blaze-html >= 0.5 && < 0.6 @@ -76,7 +76,7 @@ executable yesod , text >= 0.11 , shakespeare-text >= 1.0 && < 1.1 , shakespeare >= 1.0.2 && < 1.1 - , shakespeare-js >= 1.0.1 && < 1.1 + , shakespeare-js >= 1.0.2 && < 1.2 , shakespeare-css >= 1.0.2 && < 1.1 , bytestring >= 0.9.1.4 , time >= 1.1.4