git.iko.soy/typeable/servant
on master help sign in
adapt to the servant/servant-server split, prepare new release
commitd106989d624d6aeb6e51cd5767a854409a317f92 authorAlp Mestanogullari <alpmestan@gmail.com> dateWed 10 Dec 2014, 16:29 (12 years ago) parentc660b9c
2 files changed+69−88
docs.sh+52 servant-jquery.cabal+17−88
docs.shnew file+52
@@ -0,0 +1,52 @@
1+SERVANT_DIR=/tmp/servant-jquery-gh-pages
2+
3+# Make a temporary clone
4+
5+rm -rf $SERVANT_DIR
6+
7+git clone . $SERVANT_DIR
8+
9+cd $SERVANT_DIR
10+
11+# Make sure to pull the latest
12+
13+git remote add haskell-servant git@github.com:haskell-servant/servant-jquery.git
14+
15+git fetch haskell-servant
16+
17+git reset --hard haskell-servant/gh-pages
18+
19+# Clear everything away
20+
21+git rm -rf $SERVANT_DIR/*
22+
23+# Switch back and build the haddocks
24+
25+cd -
26+
27+cabal configure --builddir=$SERVANT_DIR
28+
29+cabal haddock --hoogle --hyperlink-source --html-location='https://hackage.haskell.org/package/$pkg-$version/docs' --builddir=$SERVANT_DIR
30+
31+commit_hash=$(git rev-parse HEAD)
32+
33+# Move the HTML docs to the root
34+
35+cd $SERVANT_DIR
36+
37+rm *
38+rm -rf build
39+mv doc/html/servant-jquery/* .
40+rm -r doc/
41+
42+# Add everything
43+
44+git add .
45+
46+git commit -m "Built from $commit_hash"
47+
48+# Push to update the pages
49+
50+git push haskell-servant HEAD:gh-pages
51+
52+rm -rf $SERVANT_DIR
servant-jquery.cabal+17−88
@@ -1,94 +1,11 @@
11name: servant-jquery
2−version: 0.2
2+version: 0.2.1
33synopsis: Automatically derive jquery-based javascript functions to query servant webservices
44description:
55 Automatically derive jquery-based javascript functions to query servant webservices.
66 .
7− Example below that serves the generated javascript to a webpage that lets you
7+ Example <https://github.com/haskell-servant/servant-jquery/blob/master/examples/counter.hs here> that serves the generated javascript to a webpage that lets you
88 trigger webservice calls.
9− .
10− > {-# LANGUAGE DataKinds #-}
11− > {-# LANGUAGE TypeOperators #-}
12− > {-# LANGUAGE DeriveGeneric #-}
13− > {-# LANGUAGE GeneralizedNewtypeDeriving #-}
14− >
15− > import Control.Concurrent.STM
16− > import Control.Monad.IO.Class
17− > import Data.Aeson
18− > import Data.Proxy
19− > import GHC.Generics
20− > import Network.Wai.Handler.Warp (run)
21− > import Servant
22− > import Servant.JQuery
23− > import System.FilePath
24− >
25− > -- * A simple Counter data type
26− > newtype Counter = Counter { value :: Int }
27− > deriving (Generic, Show, Num)
28− >
29− > instance ToJSON Counter
30− >
31− > -- * Shared counter operations
32− >
33− > -- Creating a counter that starts from 0
34− > newCounter :: IO (TVar Counter)
35− > newCounter = newTVarIO 0
36− >
37− > -- Increasing the counter by 1
38− > counterPlusOne :: MonadIO m => TVar Counter -> m Counter
39− > counterPlusOne counter = liftIO . atomically $ do
40− > oldValue <- readTVar counter
41− > let newValue = oldValue + 1
42− > writeTVar counter newValue
43− > return newValue
44− >
45− > currentValue :: MonadIO m => TVar Counter -> m Counter
46− > currentValue counter = liftIO $ readTVarIO counter
47− >
48− > -- * Our API type
49− > type TestApi = "counter" :> Post Counter -- endpoint for increasing the counter
50− > :<|> "counter" :> Get Counter -- endpoint to get the current value
51− > :<|> Raw -- used for serving static files
52− >
53− > testApi :: Proxy TestApi
54− > testApi = Proxy
55− >
56− > -- * Server-side handler
57− >
58− > -- where our static files reside
59− > www :: FilePath
60− > www = "examples/www"
61− >
62− > -- defining handlers
63− > server :: TVar Counter -> Server TestApi
64− > server counter = counterPlusOne counter -- (+1) on the TVar
65− > :<|> currentValue counter -- read the TVar
66− > :<|> serveDirectory www -- serve static files
67− >
68− > runServer :: TVar Counter -- ^ shared variable for the counter
69− > -> Int -- ^ port the server should listen on
70− > -> IO ()
71− > runServer var port = run port (serve testApi $ server var)
72− >
73− > -- * Generating the JQuery code
74− >
75− > incCounterJS :<|> currentValueJS :<|> _ = jquery testApi
76− >
77− > writeJS :: FilePath -> [AjaxReq] -> IO ()
78− > writeJS fp functions = writeFile fp $
79− > concatMap generateJS functions
80− >
81− > main :: IO ()
82− > main = do
83− > -- write the JS code to www/api.js at startup
84− > writeJS (www </> "api.js")
85− > [ incCounterJS, currentValueJS ]
86− >
87− > -- setup a shared counter
88− > cnt <- newCounter
89− >
90− > -- listen to requests on port 8080
91− > runServer cnt 8080
929license: BSD3
9310license-file: LICENSE
9411author: Alp Mestanogullari
@@ -103,10 +20,15 @@ source-repository head
10320 type: git
10421 location: http://github.com/haskell-servant/servant-jquery.git
10522
23+flag example
24+ description: Build the example too
25+ manual: True
26+ default: False
27+
10628library
10729 exposed-modules: Servant.JQuery
10830 other-modules: Servant.JQuery.Internal
109− build-depends: base >=4.5 && <5, servant >= 0.2, lens >= 4
31+ build-depends: base >=4.5 && <5, servant >= 0.2.1, lens >= 4
11032 hs-source-dirs: src
11133 default-language: Haskell2010
11234 ghc-options: -Wall
@@ -115,12 +37,19 @@ executable counter
11537 main-is: counter.hs
11638 ghc-options: -O2 -Wall
11739 hs-source-dirs: examples
40+
41+ if flag(example)
42+ buildable: True
43+ else
44+ buildable: False
45+
11846 build-depends:
11947 aeson
12048 , base
12149 , filepath
122− , servant >= 0.2
123− , servant-jquery >= 0.2
50+ , servant >= 0.2.1
51+ , servant-server >= 0.2.1
52+ , servant-jquery >= 0.2.1
12453 , stm
12554 , transformers
12655 , warp