getting-started -> tutorial

This commit is contained in:
Alp Mestanogullari 2015-05-10 13:39:18 +02:00
parent 4653744706
commit 39d114ab12
16 changed files with 77 additions and 77 deletions

View file

@ -1,39 +0,0 @@
import Network.Wai
import Network.Wai.Handler.Warp
import System.Environment
import qualified GS1
import qualified GS2
import qualified GS3
import qualified GS4
import qualified GS5
import qualified GS6
import qualified GS7
import qualified GS9
import qualified GS10
app :: String -> (Application -> IO ()) -> IO ()
app n f = case n of
"1" -> f GS1.app
"2" -> f GS2.app
"3" -> f GS3.app
"4" -> f GS4.app
"5" -> f GS5.app
"6" -> f GS6.app
"7" -> f GS7.app
"8" -> f GS3.app
"9" -> GS9.writeJSFiles >> f GS9.app
"10" -> f GS10.app
_ -> usage
main :: IO ()
main = do
args <- getArgs
case args of
[n] -> app n (run 8081)
_ -> usage
usage :: IO ()
usage = do
putStrLn "Usage:\t getting-started N"
putStrLn "\t\twhere N is the number of the example you want to run."

View file

@ -13,9 +13,9 @@ category: Web
build-type: Simple build-type: Simple
cabal-version: >=1.10 cabal-version: >=1.10
executable getting-started executable tutorial
main-is: getting-started.hs main-is: tutorial.hs
other-modules: GS1, GS2, GS3, GS4, GS5, GS6, GS7, GS8, GS9, GS10 other-modules: T1, T2, T3, T4, T5, T6, T7, T8, T9, T10
build-depends: build-depends:
aeson >= 0.8 aeson >= 0.8
, base >= 4.7 , base >= 4.7
@ -36,12 +36,12 @@ executable getting-started
, transformers , transformers
, wai , wai
, warp , warp
hs-source-dirs: getting-started hs-source-dirs: tutorial
default-language: Haskell2010 default-language: Haskell2010
executable gs8-main executable t8-main
main-is: gs8-main.hs main-is: t8-main.hs
hs-source-dirs: getting-started hs-source-dirs: tutorial
default-language: Haskell2010 default-language: Haskell2010
build-depends: build-depends:
aeson aeson

View file

@ -2,7 +2,7 @@
{-# LANGUAGE TypeFamilies #-} {-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE DeriveGeneric #-} {-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE TypeOperators #-} {-# LANGUAGE TypeOperators #-}
module GS1 where module T1 where
import Data.Aeson import Data.Aeson
import Data.Time.Calendar import Data.Time.Calendar

View file

@ -4,7 +4,7 @@
{-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE MultiParamTypeClasses #-} {-# LANGUAGE MultiParamTypeClasses #-}
module GS10 where module T10 where
import Data.ByteString.Lazy (ByteString) import Data.ByteString.Lazy (ByteString)
import Data.Text.Lazy (pack) import Data.Text.Lazy (pack)
@ -13,9 +13,9 @@ import Network.HTTP.Types
import Network.Wai import Network.Wai
import Servant import Servant
import Servant.Docs import Servant.Docs
import qualified GS3 import qualified T3
type DocsAPI = GS3.API :<|> Raw type DocsAPI = T3.API :<|> Raw
instance ToCapture (Capture "x" Int) where instance ToCapture (Capture "x" Int) where
toCapture _ = DocCapture "x" "(integer) position on the x axis" toCapture _ = DocCapture "x" "(integer) position on the x axis"
@ -23,8 +23,8 @@ instance ToCapture (Capture "x" Int) where
instance ToCapture (Capture "y" Int) where instance ToCapture (Capture "y" Int) where
toCapture _ = DocCapture "y" "(integer) position on the y axis" toCapture _ = DocCapture "y" "(integer) position on the y axis"
instance ToSample GS3.Position GS3.Position where instance ToSample T3.Position T3.Position where
toSample _ = Just (GS3.Position 3 14) toSample _ = Just (T3.Position 3 14)
instance ToParam (QueryParam "name" String) where instance ToParam (QueryParam "name" String) where
toParam _ = toParam _ =
@ -33,20 +33,20 @@ instance ToParam (QueryParam "name" String) where
"Name of the person to say hello to." "Name of the person to say hello to."
Normal Normal
instance ToSample GS3.HelloMessage GS3.HelloMessage where instance ToSample T3.HelloMessage T3.HelloMessage where
toSamples _ = toSamples _ =
[ ("When a value is provided for 'name'", GS3.HelloMessage "Hello, Alp") [ ("When a value is provided for 'name'", T3.HelloMessage "Hello, Alp")
, ("When 'name' is not specified", GS3.HelloMessage "Hello, anonymous coward") , ("When 'name' is not specified", T3.HelloMessage "Hello, anonymous coward")
] ]
ci :: GS3.ClientInfo ci :: T3.ClientInfo
ci = GS3.ClientInfo "Alp" "alp@foo.com" 26 ["haskell", "mathematics"] ci = T3.ClientInfo "Alp" "alp@foo.com" 26 ["haskell", "mathematics"]
instance ToSample GS3.ClientInfo GS3.ClientInfo where instance ToSample T3.ClientInfo T3.ClientInfo where
toSample _ = Just ci toSample _ = Just ci
instance ToSample GS3.Email GS3.Email where instance ToSample T3.Email T3.Email where
toSample _ = Just (GS3.emailForClient ci) toSample _ = Just (T3.emailForClient ci)
api :: Proxy DocsAPI api :: Proxy DocsAPI
api = Proxy api = Proxy
@ -55,12 +55,12 @@ docsBS :: ByteString
docsBS = encodeUtf8 docsBS = encodeUtf8
. pack . pack
. markdown . markdown
$ docsWithIntros [intro] GS3.api $ docsWithIntros [intro] T3.api
where intro = DocIntro "Welcome" ["This is our super webservice's API.", "Enjoy!"] where intro = DocIntro "Welcome" ["This is our super webservice's API.", "Enjoy!"]
server :: Server DocsAPI server :: Server DocsAPI
server = GS3.server :<|> serveDocs server = T3.server :<|> serveDocs
where serveDocs _ respond = where serveDocs _ respond =
respond $ responseLBS ok200 [plain] docsBS respond $ responseLBS ok200 [plain] docsBS

View file

@ -2,7 +2,7 @@
{-# LANGUAGE TypeFamilies #-} {-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE DeriveGeneric #-} {-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE TypeOperators #-} {-# LANGUAGE TypeOperators #-}
module GS2 where module T2 where
import Data.Aeson import Data.Aeson
import Data.Time.Calendar import Data.Time.Calendar

View file

@ -2,7 +2,7 @@
{-# LANGUAGE TypeFamilies #-} {-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE DeriveGeneric #-} {-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE TypeOperators #-} {-# LANGUAGE TypeOperators #-}
module GS3 where module T3 where
import Control.Monad.Trans.Either import Control.Monad.Trans.Either
import Data.Aeson import Data.Aeson

View file

@ -4,7 +4,7 @@
{-# LANGUAGE TypeOperators #-} {-# LANGUAGE TypeOperators #-}
{-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE OverloadedStrings #-}
module GS4 where module T4 where
import Data.Aeson import Data.Aeson
import Data.Foldable (foldMap) import Data.Foldable (foldMap)

View file

@ -3,7 +3,7 @@
{-# LANGUAGE DeriveGeneric #-} {-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE TypeOperators #-} {-# LANGUAGE TypeOperators #-}
{-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE OverloadedStrings #-}
module GS5 where module T5 where
import Control.Monad.IO.Class import Control.Monad.IO.Class
import Control.Monad.Trans.Either import Control.Monad.Trans.Either

View file

@ -1,7 +1,7 @@
{-# LANGUAGE DataKinds #-} {-# LANGUAGE DataKinds #-}
{-# LANGUAGE TypeFamilies #-} {-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-} {-# LANGUAGE TypeOperators #-}
module GS6 where module T6 where
import Network.Wai import Network.Wai
import Servant import Servant
@ -12,7 +12,7 @@ api :: Proxy API
api = Proxy api = Proxy
server :: Server API server :: Server API
server = serveDirectory "getting-started" server = serveDirectory "tutorial"
app :: Application app :: Application
app = serve api server app = serve api server

View file

@ -1,7 +1,7 @@
{-# LANGUAGE DataKinds #-} {-# LANGUAGE DataKinds #-}
{-# LANGUAGE TypeFamilies #-} {-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-} {-# LANGUAGE TypeOperators #-}
module GS7 where module T7 where
import Control.Monad.Trans.Either import Control.Monad.Trans.Either
import Control.Monad.Trans.Reader import Control.Monad.Trans.Reader

View file

@ -1,14 +1,14 @@
{-# LANGUAGE DataKinds #-} {-# LANGUAGE DataKinds #-}
{-# LANGUAGE TypeFamilies #-} {-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-} {-# LANGUAGE TypeOperators #-}
module GS8 where module T8 where
import Control.Monad.Trans.Either import Control.Monad.Trans.Either
import Data.Aeson import Data.Aeson
import Servant import Servant
import Servant.Client import Servant.Client
import GS3 import T3
position :: Int -- ^ value for "x" position :: Int -- ^ value for "x"
-> Int -- ^ value for "y" -> Int -- ^ value for "y"

View file

@ -3,7 +3,7 @@
{-# LANGUAGE DeriveGeneric #-} {-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE TypeOperators #-} {-# LANGUAGE TypeOperators #-}
{-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE OverloadedStrings #-}
module GS9 where module T9 where
import Control.Applicative import Control.Applicative
import Control.Monad.IO.Class import Control.Monad.IO.Class
@ -89,16 +89,16 @@ server = randomPoint
server' :: Server API' server' :: Server API'
server' = server server' = server
:<|> serveDirectory "getting-started/gs9" :<|> serveDirectory "tutorial/t9"
apiJS :: String apiJS :: String
apiJS = jsForAPI api apiJS = jsForAPI api
writeJSFiles :: IO () writeJSFiles :: IO ()
writeJSFiles = do writeJSFiles = do
writeFile "getting-started/gs9/api.js" apiJS writeFile "tutorial/t9/api.js" apiJS
jq <- readFile =<< JQ.file jq <- readFile =<< JQ.file
writeFile "getting-started/gs9/jq.js" jq writeFile "tutorial/t9/jq.js" jq
app :: Application app :: Application
app = serve api' server' app = serve api' server'

View file

@ -1,4 +1,4 @@
import GS8 import T8
main :: IO () main :: IO ()
main = run main = run

View file

@ -3,7 +3,7 @@
<head> <head>
<meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Getting started - 9 - servant-jquery</title> <title>Tutorial - 9 - servant-jquery</title>
</head> </head>
<body> <body>
<h1>Books</h1> <h1>Books</h1>

View file

@ -0,0 +1,39 @@
import Network.Wai
import Network.Wai.Handler.Warp
import System.Environment
import qualified T1
import qualified T2
import qualified T3
import qualified T4
import qualified T5
import qualified T6
import qualified T7
import qualified T9
import qualified T10
app :: String -> (Application -> IO ()) -> IO ()
app n f = case n of
"1" -> f T1.app
"2" -> f T2.app
"3" -> f T3.app
"4" -> f T4.app
"5" -> f T5.app
"6" -> f T6.app
"7" -> f T7.app
"8" -> f T3.app
"9" -> T9.writeJSFiles >> f T9.app
"10" -> f T10.app
_ -> usage
main :: IO ()
main = do
args <- getArgs
case args of
[n] -> app n (run 8081)
_ -> usage
usage :: IO ()
usage = do
putStrLn "Usage:\t tutorial N"
putStrLn "\t\twhere N is the number of the example you want to run."