git.iko.soy/typeable/servant
on master help sign in
drop the dependency on interpolate and hence on haskell-src-exts, it's becoming too annoying to keep
commit3e76058d25f30687a03cb2f5c60b1b84723eae19 authorAlp Mestanogullari <alpmestan@gmail.com> dateMon 1 Dec 2014, 17:23 (12 years ago) parent91fc74b
3 files changed+15−24
examples/counter.hs+1−6 servant-jquery.cabal+1−1 src/Servant/JQuery.hs+13−17
examples/counter.hs+1−6
@@ -19,9 +19,6 @@ newtype Counter = Counter { value :: Int }
1919
2020instance ToJSON Counter
2121
22−instance ToSample Counter where
23− toSample = Just 0
24−
2522-- * Shared counter operations
2623
2724-- Creating a counter that starts from 0
@@ -42,7 +39,6 @@ currentValue counter = liftIO $ readTVarIO counter
4239-- * Our API type
4340type TestApi = "counter" :> Post Counter -- endpoint for increasing the counter
4441 :<|> "counter" :> Get Counter -- endpoint to get the current value
45− :<|> "doc" :> Raw -- serve the documentation
4642 :<|> Raw -- used for serving static files
4743
4844testApi :: Proxy TestApi
@@ -58,7 +54,6 @@ www = "examples/www"
5854server :: TVar Counter -> Server TestApi
5955server counter = counterPlusOne counter -- (+1) on the TVar
6056 :<|> currentValue counter -- read the TVar
61− :<|> serveDocumentation testApi -- serve the API docs
6257 :<|> serveDirectory www -- serve static files
6358
6459runServer :: TVar Counter -- ^ shared variable for the counter
@@ -70,7 +65,7 @@ runServer var port = run port (serve testApi $ server var)
7065incCounterNamed :: FunctionName -> AjaxReq
7166currentValueNamed :: FunctionName -> AjaxReq
7267
73−incCounterNamed :<|> currentValueNamed :<|> _ :<|> _ = jquery testApi
68+incCounterNamed :<|> currentValueNamed :<|> _ = jquery testApi
7469
7570writeJS :: FilePath -> [AjaxReq] -> IO ()
7671writeJS fp functions = writeFile fp $
servant-jquery.cabal+1−1
@@ -16,7 +16,7 @@ library
1616 exposed-modules: Servant.JQuery
1717 other-modules: Servant.JQuery.Internal
1818 -- other-extensions:
19− build-depends: base >=4.5 && <5, servant >= 0.2, lens >= 4, interpolate
19+ build-depends: base >=4.5 && <5, servant >= 0.2, lens >= 4
2020 hs-source-dirs: src
2121 default-language: Haskell2010
2222 ghc-options: -O2 -Wall
src/Servant/JQuery.hs+13−17
@@ -1,5 +1,4 @@
11{-# LANGUAGE DataKinds #-}
2−{-# LANGUAGE QuasiQuotes #-}
32{-# LANGUAGE TypeOperators #-}
43{-# LANGUAGE FlexibleInstances #-}
54-----------------------------------------------------------------------------
@@ -10,8 +9,6 @@
109-- Maintainer : Alp Mestanogullari <alpmestan@gmail.com>
1110-- Stability : experimental
1211-- Portability : non-portable
13−--
14−-- Usage:
1512module Servant.JQuery
1613 ( jquery
1714 , generateJS
@@ -21,8 +18,8 @@ module Servant.JQuery
2118
2219import Control.Lens
2320import Data.List
21+import Data.Monoid
2422import Data.Proxy
25−import Data.String.Interpolate
2623import Servant.JQuery.Internal
2724
2825jquery :: HasJQ layout => Proxy layout -> JQ layout
@@ -30,18 +27,17 @@ jquery p = jqueryFor p defReq
3027
3128-- js codegen
3229generateJS :: AjaxReq -> String
33−generateJS req =
34− [i|
35−function #{fname}(#{argsStr})
36−{
37− $.ajax(
38− { url: #{url}
39− , success: onSuccess #{dataBody}
40− , error: onError
41− , type: '#{method}'
42− });
43−}
44− |]
30+generateJS req = "\n" <>
31+ "function " <> fname <> "(" <> argsStr <> ")\n"
32+ <> "{\n"
33+ <> " $.ajax(\n"
34+ <> " { url: " <> url <> "\n"
35+ <> " , success: onSuccess\n"
36+ <> dataBody
37+ <> " , error: onError\n"
38+ <> " , type: '" <> method <> "'\n"
39+ <> " });\n"
40+ <> "}\n"
4541
4642 where argsStr = intercalate ", " args
4743 args = captures
@@ -61,7 +57,7 @@ function #{fname}(#{argsStr})
6157
6258 dataBody =
6359 if req ^. reqBody
64− then "\n , data: JSON.stringify(body)"
60+ then "\n , data: JSON.stringify(body)\n"
6561 else ""
6662
6763 fname = req ^. funcName