Add ToContent etc instance for Css and Javascript
This commit is contained in:
parent
55309a01b3
commit
7512cc2bfc
@ -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
|
||||
|
||||
@ -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>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user