packages feed

servant-rawm-docs (empty) → 1.0.0.0

raw patch · 5 files changed

+198/−0 lines, 5 filesdep +basedep +http-mediadep +http-types

Dependencies added: base, http-media, http-types, lens, servant-docs, servant-rawm

Files

+ CHANGELOG.md view
@@ -0,0 +1,12 @@+## 1.0.0.0++*   The implementations of the `RawM` endpoint are divided into+    `servant-rawm-client`, `servant-rawm-docs`, and `servant-rawm-server` to+    avoid introducing unnecessary dependencies and reduce the compilation+    overhead. You will need to add either of the implementations to your+    dependencies, and import the corresponding implementation+    (`Servant.RawM.Server`, `Servant.RawM.Client`, or `Servant.RawM.Docs`) for+    the `RawM` endpoint to function correctly.+    [#16](https://github.com/cdepillabout/servant-rawm/pull/16)+    Thanks [@Krasjet](https://github.com/Krasjet)!+
+ LICENSE view
@@ -0,0 +1,30 @@+Copyright Dennis Gosnell (c) 2017-2020++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 Author name here 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.
+ README.md view
@@ -0,0 +1,20 @@+# Servant.RawM.Docs++[![Build Status](https://secure.travis-ci.org/cdepillabout/servant-rawm.svg)](http://travis-ci.org/cdepillabout/servant-rawm)+[![Hackage](https://img.shields.io/hackage/v/servant-rawm-docs.svg)](https://hackage.haskell.org/package/servant-rawm-docs)+[![Stackage LTS](http://stackage.org/package/servant-rawm-docs/badge/lts)](http://stackage.org/lts/package/servant-rawm-docs)+[![Stackage Nightly](http://stackage.org/package/servant-rawm-docs/badge/nightly)](http://stackage.org/nightly/package/servant-rawm-docs)+![BSD3 license](https://img.shields.io/badge/license-BSD3-blue.svg)++This is the documentation-generation library for+[`servant-rawm`](https://github.com/cdepillabout/servant-rawm).++See the `servant-rawm`+[`README.md`](https://github.com/cdepillabout/servant-rawm) and+[Haddocks](side://hackage.haskell.org/package/servant-rawm)+for a short explanation of how to use this package.++After `servant-rawm` 1.0.0.0, the implementations of the `RawM` endpoint are+divided into `servant-rawm-client`, `servant-rawm-docs`, and+`servant-rawm-server` to avoid introducing unnecessary dependencies and reduce+the compilation overhead.
+ servant-rawm-docs.cabal view
@@ -0,0 +1,33 @@+name:                servant-rawm-docs+version:             1.0.0.0+synopsis:            Documentation generator for 'RawM' endpoints.+description:         Please see <https://github.com/cdepillabout/servant-rawm#readme README.md>.+homepage:            https://github.com/cdepillabout/servant-rawm+license:             BSD3+license-file:        LICENSE+author:              Dennis Gosnell+maintainer:          cdep.illabout@gmail.com+                   , nil.krjst@gmail.com+copyright:           2017 Dennis Gosnell+category:            Servant+                   , Web+build-type:          Simple+extra-source-files:  CHANGELOG.md+                   , README.md+cabal-version:       >=1.10++library+  hs-source-dirs:      src+  exposed-modules:     Servant.RawM.Docs+  build-depends:       base >= 4.9 && < 5+                     , servant-rawm+                     , servant-docs >= 0.11.3+                     , lens >= 4.0+                     , http-media >= 0.6+                     , http-types >= 0.9+  default-language:    Haskell2010+  ghc-options:         -Wall -fwarn-incomplete-uni-patterns -fwarn-incomplete-record-updates -fwarn-monomorphism-restriction++source-repository head+  type:     git+  location: git@github.com:cdepillabout/servant-rawm.git
+ src/Servant/RawM/Docs.hs view
@@ -0,0 +1,103 @@+{-# LANGUAGE CPP                       #-}+{-# LANGUAGE InstanceSigs              #-}+{-# LANGUAGE NoMonomorphismRestriction #-}+{-# LANGUAGE OverloadedStrings         #-}+{-# LANGUAGE ScopedTypeVariables       #-}+{-# OPTIONS_GHC -fno-warn-orphans #-}++{- |+Module      :  Servant.RawM.Docs++Copyright   :  Dennis Gosnell 2017+License     :  BSD3++Maintainer  :  Dennis Gosnell (cdep.illabout@gmail.com)+               Krasjet (nil.krjst@gmail.com)+Stability   :  experimental+Portability :  unknown++This module exports a 'HasDocs' instance for 'RawM', which provides+documentations for the 'RawM' endpoint.+-}++module Servant.RawM.Docs (+  -- * Reexport RawM API+  module Servant.RawM+) where++-- Semigroup is in Prelude since 4.11.0+#if !MIN_VERSION_base(4,11,0)+import Data.Semigroup ((<>))+#endif++import Control.Lens       ((.~), (<>~))+import Data.Function      ((&))+import Data.Proxy         (Proxy (Proxy))+import Network.HTTP.Media ((//))+import Network.HTTP.Types (methodGet)+import Servant.Docs       (API, Action, DocCapture (DocCapture),+                           DocNote (DocNote), DocOptions, Endpoint,+                           HasDocs (docsFor), captures, defResponse, method,+                           notes, path, respBody, respStatus, respTypes,+                           response, single)+import Servant.RawM++-- | This just defers to the 'HasDocs' instance for the @serverType@ phantom+-- type.+instance (HasDocs serverType) => HasDocs (RawM' serverType) where+  docsFor :: Proxy (RawM' serverType) -> (Endpoint, Action) -> DocOptions -> API+  docsFor Proxy (endpoint, action) docOpts =+    docsFor (Proxy :: Proxy serverType) (endpoint, action) docOpts++-- | This is a 'HasDocs' instance compatible with the file servers defined in+-- "Servant.RawM.Server".+instance HasDocs FileServer where+  docsFor :: Proxy FileServer -> (Endpoint, Action) -> DocOptions -> API+  docsFor Proxy (endpoint, action) _ =+    let captureSymbol = ":filename"+        captureDesc = "the name of the file to GET"+        capture = DocCapture captureSymbol captureDesc+        htmlMediaType = "text" // "html"+        jsMediaType = "application" // "javascript"+        possibleRespMediaTypes =+          [ jsMediaType+          , "application" // "xml"+          , "application" // "zip"+          , "application" // "pdf"+          , "audio" // "mpeg"+          , "text" // "css"+          , htmlMediaType+          , "text" // "csv"+          , "text" // "plain"+          , "image" // "png"+          , "image" // "jpeg"+          , "image" // "gif"+          ]+        sampleHtml = "<html><body><p>Hello World</p></body></html>"+        sampleHtmlResp = ("example HTML response", htmlMediaType, sampleHtml)+        sampleJs = "alert(\"Hello World\");"+        sampleJsResp = ("example JS response", jsMediaType, sampleJs)+        noteBody1 =+          "This route is a file server.  If you specify the filename, it " <>+          "will serve up the file with the appropriate content type.  If " <>+          "the file doesn't exist, it will return a 404."+        noteBody2 =+          "The supported content types below are just examples.  A full " <>+          "list of recognized MIME types can be found " <>+          "[here](https://hackage.haskell.org/package/mime-types-0.1.0.7/docs/src/Network.Mime.html#defaultMimeMap)."+        note = DocNote "File Server" [noteBody1, noteBody2]+        resp =+          defResponse+            & respStatus .~ 200+            & respTypes .~ possibleRespMediaTypes+            & respBody .~ [sampleHtmlResp, sampleJsResp]+        newEndpoint =+          endpoint+            & method .~ methodGet+            & path <>~ [captureSymbol]+        newAction =+          action+            & captures <>~ [capture]+            & notes <>~ [note]+            & response .~ resp+    in single newEndpoint newAction