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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -3,7 +3,7 @@
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<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>
<body>
<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."