1{-# LANGUAGE DataKinds #-}
2{-# LANGUAGE TypeOperators #-}
3{-# LANGUAGE FlexibleInstances #-}
4-----------------------------------------------------------------------------
6-- Module : Servant.JQuery
7-- Copyright : (C) 2014 Alp Mestanogullari
9-- Maintainer : Alp Mestanogullari <alpmestan@gmail.com>
10-- Stability : experimental
11-- Portability : non-portable
16 , module Servant.JQuery.Internal
23import Servant.JQuery.Internal
25jquery :: HasJQ layout => Proxy layout -> JQ layout
26jquery p = jqueryFor p defReq
29generateJS :: AjaxReq -> String
30generateJS req = "\n" <>
31 "function " <> fname <> "(" <> argsStr <> ")\n"
34 <> " { url: " <> url <> "\n"
35 <> " , success: onSuccess\n"
38 <> " , error: onError\n"
39 <> " , type: '" <> method <> "'\n"
43 where argsStr = intercalate ", " args
45 ++ map (view argName) queryparams
47 ++ map (toValidFunctionName . (<>) "header" . headerArgName) hs
48 ++ ["onSuccess", "onError"]
50 captures = map captureArg
54 hs = req ^. reqHeaders
56 queryparams = req ^.. reqUrl.queryStr.traverse
58 body = if req ^. reqBody
64 then "\n , data: JSON.stringify(body)\n"
70 else "\n , headers: { " ++ headersStr ++ " }\n"
72 where headersStr = intercalate ", " $ map headerStr hs
73 headerStr header = "\"" ++
74 headerArgName header ++
77 fname = req ^. funcName
78 method = req ^. reqMethod
84 $ req ^.. reqUrl.path.traverse
86 queryArgs = if null queryparams
88 else " + '?" ++ jsParams queryparams
90printJS :: AjaxReq -> IO ()
91printJS = putStrLn . generateJS
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list