Skip to content
Browse files

Add ToContent etc instance for Css and Javascript

  • Loading branch information...
1 parent 55309a0 commit 7512cc2bfc6e10985abd066c3175b0890e4073d0 @snoyberg snoyberg committed
Showing with 19 additions and 1 deletion.
  1. +18 −0 yesod-core/Yesod/Core/Content.hs
  2. +1 −1 yesod-core/yesod-core.cabal
View
18 yesod-core/Yesod/Core/Content.hs
@@ -69,6 +69,8 @@ import Data.Aeson.Encode (fromValue)
import qualified Blaze.ByteString.Builder.Char.Utf8 as Blaze
import Data.Text.Lazy.Builder (toLazyText)
import Yesod.Core.Types
+import Text.Lucius (Css, renderCss)
+import Text.Julius (Javascript, unJavascript)
-- | Zero-length enumerator.
emptyContent :: Content
@@ -108,6 +110,11 @@ instance ToContent (ContentType, Content) where
instance ToContent TypedContent where
toContent (TypedContent _ c) = c
+instance ToContent Css where
+ toContent = toContent . renderCss
+instance ToContent Javascript where
+ toContent = toContent . toLazyText . unJavascript
+
instance ToFlushBuilder builder => ToContent (Source (ResourceT IO) builder) where
toContent src = ContentSource $ mapOutput toFlushBuilder src
instance ToFlushBuilder builder => ToContent (ResumableSource (ResourceT IO) builder) where
@@ -245,6 +252,12 @@ instance HasContentType Text where
instance HasContentType T.Text where
getContentType _ = typePlain
+instance HasContentType Css where
+ getContentType _ = typeCss
+
+instance HasContentType Javascript where
+ getContentType _ = typeJavascript
+
-- | Any type which can be converted to 'TypedContent'.
--
-- Since 1.2.0
@@ -277,3 +290,8 @@ instance ToTypedContent a => ToTypedContent (DontFullyEvaluate a) where
toTypedContent (DontFullyEvaluate a) =
let TypedContent ct c = toTypedContent a
in TypedContent ct (ContentDontEvaluate c)
+
+instance ToTypedContent Css where
+ toTypedContent = TypedContent typeCss . toContent
+instance ToTypedContent Javascript where
+ toTypedContent = TypedContent typeJavascript . toContent
View
2 yesod-core/yesod-core.cabal
@@ -1,5 +1,5 @@
name: yesod-core
-version: 1.2.10
+version: 1.2.11
license: MIT
license-file: LICENSE
author: Michael Snoyman <michael@snoyman.com>

0 comments on commit 7512cc2

Please sign in to comment.
Something went wrong with that request. Please try again.