diff --git a/servant-blaze/LICENSE b/servant-blaze/LICENSE new file mode 100644 index 00000000..0b0a2174 --- /dev/null +++ b/servant-blaze/LICENSE @@ -0,0 +1,30 @@ +Copyright (c) 2015, Julian K. Arni + +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. + + * Neither the name of Julian K. Arni nor the names of other + contributors may be used to endorse or promote products derived + from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"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 +OWNER OR CONTRIBUTORS 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/servant-blaze/Setup.hs b/servant-blaze/Setup.hs new file mode 100644 index 00000000..9a994af6 --- /dev/null +++ b/servant-blaze/Setup.hs @@ -0,0 +1,2 @@ +import Distribution.Simple +main = defaultMain diff --git a/servant-blaze/servant-blaze.cabal b/servant-blaze/servant-blaze.cabal new file mode 100644 index 00000000..0f42502e --- /dev/null +++ b/servant-blaze/servant-blaze.cabal @@ -0,0 +1,28 @@ +-- Initial servant-blaze.cabal generated by cabal init. For further +-- documentation, see http://haskell.org/cabal/users-guide/ + +name: servant-blaze +version: 0.1.0.0 +synopsis: Blaze-html support for servant +-- description: +homepage: http://haskell-servant.github.io/ +license: BSD3 +license-file: LICENSE +author: Julian K. Arni +maintainer: jkarni@gmail.com +-- copyright: +category: Web +build-type: Simple +-- extra-source-files: +cabal-version: >=1.10 + +library + exposed-modules: Servant.HTML.Blaze + -- other-modules: + -- other-extensions: + build-depends: base >=4.7 && <5 + , servant + , http-media + , blaze-html + hs-source-dirs: src + default-language: Haskell2010 diff --git a/servant-blaze/src/Servant/HTML/Blaze.hs b/servant-blaze/src/Servant/HTML/Blaze.hs new file mode 100644 index 00000000..d13af84c --- /dev/null +++ b/servant-blaze/src/Servant/HTML/Blaze.hs @@ -0,0 +1,45 @@ +{-# LANGUAGE CPP #-} +{-# LANGUAGE DeriveDataTypeable #-} +{-# LANGUAGE FlexibleInstances #-} +{-# LANGUAGE MultiParamTypeClasses #-} +{-# LANGUAGE OverloadedStrings #-} +#if !MIN_VERSION_base(4,8,0) +{-# LANGUAGE OverlappingInstances #-} +#endif + +-- | An @HTML@ empty data type with `MimeRender` instances for @blaze-html@'s +-- `ToMarkup` class and `Html` datatype. +-- You should only need to import this module for it's instances and the +-- `HTML` datatype.: +-- +-- >>> type Eg = Get '[HTML] a +-- +-- Will then check that @a@ has a `ToMarkup` instance, or is `Html`. +module Servant.HTML.Blaze where + +import Data.Typeable (Typeable) +import qualified Network.HTTP.Media as M +import Servant.API (Accept (..), MimeRender (..)) +import Text.Blaze.Html (Html, ToMarkup, toHtml) +import Text.Blaze.Html.Renderer.Utf8 (renderHtml) + +data HTML deriving Typeable + +-- | @text/plain;charset=utf-8@ +instance Accept HTML where + contentType _ = "text" M.// "html" M./: ("charset", "utf-8") + +instance +#if MIN_VERSION_base(4,8,0) + {-# OVERLAPPABLE #-} +#endif + ToMarkup a => MimeRender HTML a where + mimeRender _ = renderHtml . toHtml + +instance +#if MIN_VERSION_base(4,8,0) + {-# OVERLAPPING #-} +#endif + MimeRender HTML Html where + mimeRender _ = renderHtml + diff --git a/servant-lucid/LICENSE b/servant-lucid/LICENSE new file mode 100644 index 00000000..0b0a2174 --- /dev/null +++ b/servant-lucid/LICENSE @@ -0,0 +1,30 @@ +Copyright (c) 2015, Julian K. Arni + +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. + + * Neither the name of Julian K. Arni nor the names of other + contributors may be used to endorse or promote products derived + from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"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 +OWNER OR CONTRIBUTORS 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/servant-lucid/Setup.hs b/servant-lucid/Setup.hs new file mode 100644 index 00000000..9a994af6 --- /dev/null +++ b/servant-lucid/Setup.hs @@ -0,0 +1,2 @@ +import Distribution.Simple +main = defaultMain diff --git a/servant-lucid/servant-lucid.cabal b/servant-lucid/servant-lucid.cabal new file mode 100644 index 00000000..b2d02316 --- /dev/null +++ b/servant-lucid/servant-lucid.cabal @@ -0,0 +1,28 @@ +-- Initial servant-lucid.cabal generated by cabal init. For further +-- documentation, see http://haskell.org/cabal/users-guide/ + +name: servant-lucid +version: 0.1.0.0 +synopsis: Servant support for lucid +-- description: +homepage: http://haskell-servant.github.io/ +license: BSD3 +license-file: LICENSE +author: Julian K. Arni +maintainer: jkarni@gmail.com +-- copyright: +category: Web +build-type: Simple +-- extra-source-files: +cabal-version: >=1.10 + +library + exposed-modules: Servant.HTML.Lucid + -- other-modules: + -- other-extensions: + build-depends: base >=4.7 && <4.8 + , http-media + , lucid + , servant + hs-source-dirs: src + default-language: Haskell2010 diff --git a/servant-lucid/src/Servant/HTML/Lucid.hs b/servant-lucid/src/Servant/HTML/Lucid.hs new file mode 100644 index 00000000..7fa39709 --- /dev/null +++ b/servant-lucid/src/Servant/HTML/Lucid.hs @@ -0,0 +1,43 @@ +{-# LANGUAGE CPP #-} +{-# LANGUAGE DeriveDataTypeable #-} +{-# LANGUAGE FlexibleInstances #-} +{-# LANGUAGE MultiParamTypeClasses #-} +{-# LANGUAGE OverloadedStrings #-} +#if !MIN_VERSION_base(4,8,0) +{-# LANGUAGE OverlappingInstances #-} +#endif + +-- | An @HTML@ empty data type with `MimeRender` instances for @lucid@'s +-- `ToHtml` class and `Html` datatype. +-- You should only need to import this module for it's instances and the +-- `HTML` datatype.: +-- +-- >>> type Eg = Get '[HTML] a +-- +-- Will then check that @a@ has a `ToHtml` instance, or is `Html`. +module Servant.HTML.Lucid where + +import Data.Typeable (Typeable) +import Lucid (Html, ToHtml (..), renderBS) +import qualified Network.HTTP.Media as M +import Servant.API (Accept (..), MimeRender (..)) + +data HTML deriving Typeable + +-- | @text/plain;charset=utf-8@ +instance Accept HTML where + contentType _ = "text" M.// "html" M./: ("charset", "utf-8") + +instance +#if MIN_VERSION_base(4,8,0) + {-# OVERLAPPABLE #-} +#endif + ToHtml a => MimeRender HTML a where + mimeRender _ = renderBS . toHtml + +instance +#if MIN_VERSION_base(4,8,0) + {-# OVERLAPPING #-} +#endif + MimeRender HTML (Html a) where + mimeRender _ = renderBS diff --git a/servant/src/Servant/API.hs b/servant/src/Servant/API.hs index 1c701689..11a0fd27 100644 --- a/servant/src/Servant/API.hs +++ b/servant/src/Servant/API.hs @@ -61,7 +61,7 @@ module Servant.API ( import Data.Proxy (Proxy (..)) import Servant.API.Alternative ((:<|>) (..)) import Servant.API.Capture (Capture) -import Servant.API.ContentTypes (FormUrlEncoded, +import Servant.API.ContentTypes (Accept(..), FormUrlEncoded, FromFormUrlEncoded (..), JSON, MimeRender (..), MimeUnrender (..), OctetStream,