From cfde41dda4d6cba70ef8da9a89491c9cecf979a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6nke=20Hahn?= Date: Thu, 28 Jan 2016 18:44:37 +0100 Subject: [PATCH] tutorial: make Javascript.lhs compile --- doc/tutorial/Javascript.lhs | 17 +++++++++-------- doc/tutorial/tinc.yaml | 2 -- doc/tutorial/tutorial.cabal | 3 ++- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/doc/tutorial/Javascript.lhs b/doc/tutorial/Javascript.lhs index 69d96547..9ab4740e 100644 --- a/doc/tutorial/Javascript.lhs +++ b/doc/tutorial/Javascript.lhs @@ -30,13 +30,14 @@ module Javascript where import Control.Monad.IO.Class import Data.Aeson import Data.Proxy -import Data.Text (Text) +import Data.Text as T (Text) +import Data.Text.IO as T (writeFile, readFile) import qualified Data.Text as T import GHC.Generics import Language.Javascript.JQuery import Network.Wai import Servant -import Servant.JQuery +import Servant.JS import System.Random ``` @@ -133,7 +134,7 @@ server' = server :<|> serveDirectory "tutorial/t9" app :: Application -app = serve api' server' +app = serve api' EmptyConfig server' ``` Why two different API types, proxies and servers though? Simply because we don't want to generate javascript functions for the `Raw` part of our API type, so we need a `Proxy` for our API type `API'` without its `Raw` endpoint. @@ -141,8 +142,8 @@ Why two different API types, proxies and servers though? Simply because we don't Very similarly to how one can derive haskell functions, we can derive the javascript with just a simple function call to `jsForAPI` from `Servant.JQuery`. ``` haskell -apiJS :: String -apiJS = jsForAPI api +apiJS :: Text +apiJS = jsForAPI api vanillaJS ``` This `String` contains 2 Javascript functions: @@ -175,9 +176,9 @@ Right before starting up our server, we will need to write this `String` to a fi ``` haskell writeJSFiles :: IO () writeJSFiles = do - writeFile "getting-started/gs9/api.js" apiJS - jq <- readFile =<< Language.Javascript.JQuery.file - writeFile "getting-started/gs9/jq.js" jq + T.writeFile "getting-started/gs9/api.js" apiJS + jq <- T.readFile =<< Language.Javascript.JQuery.file + T.writeFile "getting-started/gs9/jq.js" jq ``` And we're good to go. Start the server with `dist/build/tutorial/tutorial 9` and go to `http://localhost:8081/`. Start typing in the name of one of the authors in our database or part of a book title, and check out how long it takes to approximate π using the method mentioned above. diff --git a/doc/tutorial/tinc.yaml b/doc/tutorial/tinc.yaml index b2164752..f52bab2d 100644 --- a/doc/tutorial/tinc.yaml +++ b/doc/tutorial/tinc.yaml @@ -7,8 +7,6 @@ dependencies: path: ../../servant-client - name: servant-js path: ../../servant-js - - name: servant-lucid - path: ../../servant-lucid - name: servant-docs path: ../../servant-docs - name: servant-foreign diff --git a/doc/tutorial/tutorial.cabal b/doc/tutorial/tutorial.cabal index 501dace4..9c3d664b 100644 --- a/doc/tutorial/tutorial.cabal +++ b/doc/tutorial/tutorial.cabal @@ -17,7 +17,7 @@ library exposed-modules: ApiType , Client , Docs - -- , Javascript + , Javascript , Server -- other-modules: -- other-extensions: @@ -32,6 +32,7 @@ library , servant-server == 0.5.* , servant-client == 0.5.* , servant-docs == 0.5.* + , servant-js == 0.5.* , warp , http-media , lucid