on master help sign in
Servant-blaze and servant-lucid
commit666e6700586310f5b766311cc224a5d324d49d7b authorJulian K. Arni <jkarni@gmail.com> dateSat 2 May 2015, 12:04 (11 years ago) parenta2b8d6a
9 files changed+209−1
servant-blaze/LICENSE+30 servant-blaze/Setup.hs+2 servant-blaze/servant-blaze.cabal+28 servant-blaze/src/Servant/HTML/Blaze.hs+45 servant-lucid/LICENSE+30 servant-lucid/Setup.hs+2 servant-lucid/servant-lucid.cabal+28 servant-lucid/src/Servant/HTML/Lucid.hs+43 servant/src/Servant/API.hs+1−1
servant-blaze/LICENSEnew file+30
@@ -0,0 +1,30 @@
1+Copyright (c) 2015, Julian K. Arni
2+
3+All rights reserved.
4+
5+Redistribution and use in source and binary forms, with or without
6+modification, are permitted provided that the following conditions are met:
7+
8+ * Redistributions of source code must retain the above copyright
9+ notice, this list of conditions and the following disclaimer.
10+
11+ * Redistributions in binary form must reproduce the above
12+ copyright notice, this list of conditions and the following
13+ disclaimer in the documentation and/or other materials provided
14+ with the distribution.
15+
16+ * Neither the name of Julian K. Arni nor the names of other
17+ contributors may be used to endorse or promote products derived
18+ from this software without specific prior written permission.
19+
20+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
servant-blaze/Setup.hsnew file+2
@@ -0,0 +1,2 @@
1+import Distribution.Simple
2+main = defaultMain
servant-blaze/servant-blaze.cabalnew file+28
@@ -0,0 +1,28 @@
1+-- Initial servant-blaze.cabal generated by cabal init. For further
2+-- documentation, see http://haskell.org/cabal/users-guide/
3+
4+name: servant-blaze
5+version: 0.1.0.0
6+synopsis: Blaze-html support for servant
7+-- description:
8+homepage: http://haskell-servant.github.io/
9+license: BSD3
10+license-file: LICENSE
11+author: Julian K. Arni
12+maintainer: jkarni@gmail.com
13+-- copyright:
14+category: Web
15+build-type: Simple
16+-- extra-source-files:
17+cabal-version: >=1.10
18+
19+library
20+ exposed-modules: Servant.HTML.Blaze
21+ -- other-modules:
22+ -- other-extensions:
23+ build-depends: base >=4.7 && <5
24+ , servant
25+ , http-media
26+ , blaze-html
27+ hs-source-dirs: src
28+ default-language: Haskell2010
servant-blaze/src/Servant/HTML/Blaze.hsnew file+45
@@ -0,0 +1,45 @@
1+{-# LANGUAGE CPP #-}
2+{-# LANGUAGE DeriveDataTypeable #-}
3+{-# LANGUAGE FlexibleInstances #-}
4+{-# LANGUAGE MultiParamTypeClasses #-}
5+{-# LANGUAGE OverloadedStrings #-}
6+#if !MIN_VERSION_base(4,8,0)
7+{-# LANGUAGE OverlappingInstances #-}
8+#endif
9+
10+-- | An @HTML@ empty data type with `MimeRender` instances for @blaze-html@'s
11+-- `ToMarkup` class and `Html` datatype.
12+-- You should only need to import this module for it's instances and the
13+-- `HTML` datatype.:
14+--
15+-- >>> type Eg = Get '[HTML] a
16+--
17+-- Will then check that @a@ has a `ToMarkup` instance, or is `Html`.
18+module Servant.HTML.Blaze where
19+
20+import Data.Typeable (Typeable)
21+import qualified Network.HTTP.Media as M
22+import Servant.API (Accept (..), MimeRender (..))
23+import Text.Blaze.Html (Html, ToMarkup, toHtml)
24+import Text.Blaze.Html.Renderer.Utf8 (renderHtml)
25+
26+data HTML deriving Typeable
27+
28+-- | @text/plain;charset=utf-8@
29+instance Accept HTML where
30+ contentType _ = "text" M.// "html" M./: ("charset", "utf-8")
31+
32+instance
33+#if MIN_VERSION_base(4,8,0)
34+ {-# OVERLAPPABLE #-}
35+#endif
36+ ToMarkup a => MimeRender HTML a where
37+ mimeRender _ = renderHtml . toHtml
38+
39+instance
40+#if MIN_VERSION_base(4,8,0)
41+ {-# OVERLAPPING #-}
42+#endif
43+ MimeRender HTML Html where
44+ mimeRender _ = renderHtml
45+
servant-lucid/LICENSEnew file+30
@@ -0,0 +1,30 @@
1+Copyright (c) 2015, Julian K. Arni
2+
3+All rights reserved.
4+
5+Redistribution and use in source and binary forms, with or without
6+modification, are permitted provided that the following conditions are met:
7+
8+ * Redistributions of source code must retain the above copyright
9+ notice, this list of conditions and the following disclaimer.
10+
11+ * Redistributions in binary form must reproduce the above
12+ copyright notice, this list of conditions and the following
13+ disclaimer in the documentation and/or other materials provided
14+ with the distribution.
15+
16+ * Neither the name of Julian K. Arni nor the names of other
17+ contributors may be used to endorse or promote products derived
18+ from this software without specific prior written permission.
19+
20+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
servant-lucid/Setup.hsnew file+2
@@ -0,0 +1,2 @@
1+import Distribution.Simple
2+main = defaultMain
servant-lucid/servant-lucid.cabalnew file+28
@@ -0,0 +1,28 @@
1+-- Initial servant-lucid.cabal generated by cabal init. For further
2+-- documentation, see http://haskell.org/cabal/users-guide/
3+
4+name: servant-lucid
5+version: 0.1.0.0
6+synopsis: Servant support for lucid
7+-- description:
8+homepage: http://haskell-servant.github.io/
9+license: BSD3
10+license-file: LICENSE
11+author: Julian K. Arni
12+maintainer: jkarni@gmail.com
13+-- copyright:
14+category: Web
15+build-type: Simple
16+-- extra-source-files:
17+cabal-version: >=1.10
18+
19+library
20+ exposed-modules: Servant.HTML.Lucid
21+ -- other-modules:
22+ -- other-extensions:
23+ build-depends: base >=4.7 && <4.8
24+ , http-media
25+ , lucid
26+ , servant
27+ hs-source-dirs: src
28+ default-language: Haskell2010
servant-lucid/src/Servant/HTML/Lucid.hsnew file+43
@@ -0,0 +1,43 @@
1+{-# LANGUAGE CPP #-}
2+{-# LANGUAGE DeriveDataTypeable #-}
3+{-# LANGUAGE FlexibleInstances #-}
4+{-# LANGUAGE MultiParamTypeClasses #-}
5+{-# LANGUAGE OverloadedStrings #-}
6+#if !MIN_VERSION_base(4,8,0)
7+{-# LANGUAGE OverlappingInstances #-}
8+#endif
9+
10+-- | An @HTML@ empty data type with `MimeRender` instances for @lucid@'s
11+-- `ToHtml` class and `Html` datatype.
12+-- You should only need to import this module for it's instances and the
13+-- `HTML` datatype.:
14+--
15+-- >>> type Eg = Get '[HTML] a
16+--
17+-- Will then check that @a@ has a `ToHtml` instance, or is `Html`.
18+module Servant.HTML.Lucid where
19+
20+import Data.Typeable (Typeable)
21+import Lucid (Html, ToHtml (..), renderBS)
22+import qualified Network.HTTP.Media as M
23+import Servant.API (Accept (..), MimeRender (..))
24+
25+data HTML deriving Typeable
26+
27+-- | @text/plain;charset=utf-8@
28+instance Accept HTML where
29+ contentType _ = "text" M.// "html" M./: ("charset", "utf-8")
30+
31+instance
32+#if MIN_VERSION_base(4,8,0)
33+ {-# OVERLAPPABLE #-}
34+#endif
35+ ToHtml a => MimeRender HTML a where
36+ mimeRender _ = renderBS . toHtml
37+
38+instance
39+#if MIN_VERSION_base(4,8,0)
40+ {-# OVERLAPPING #-}
41+#endif
42+ MimeRender HTML (Html a) where
43+ mimeRender _ = renderBS
servant/src/Servant/API.hs+1−1
@@ -61,7 +61,7 @@ module Servant.API (
6161import Data.Proxy (Proxy (..))
6262import Servant.API.Alternative ((:<|>) (..))
6363import Servant.API.Capture (Capture)
64−import Servant.API.ContentTypes (FormUrlEncoded,
64+import Servant.API.ContentTypes (Accept(..), FormUrlEncoded,
6565 FromFormUrlEncoded (..), JSON,
6666 MimeRender (..),
6767 MimeUnrender (..), OctetStream,