git.iko.soy/typeable/servant
on master help sign in
Replace <> with interpolate QQ
a50d36cFreezeboy
servant-jquery/servant-jquery.cabal+1
@@ -42,6 +42,7 @@ library
42 , lens >= 4
42 , lens >= 4
43 , servant == 0.4.*
43 , servant == 0.4.*
44 , text
44 , text
45+ , interpolate
45 hs-source-dirs: src
46 hs-source-dirs: src
46 default-language: Haskell2010
47 default-language: Haskell2010
47 ghc-options: -Wall
48 ghc-options: -Wall
servant-jquery/src/Servant/JQuery/Angular.hs+15−12
@@ -1,9 +1,11 @@
1+{-# LANGUAGE QuasiQuotes #-}
1module Servant.JQuery.Angular where
2module Servant.JQuery.Angular where
2
3
3import Servant.JQuery.Internal
4import Servant.JQuery.Internal
4import Control.Lens
5import Control.Lens
5import Data.List
6import Data.List
6import Data.Monoid
7import Data.Monoid
8+import Data.String.Interpolate
7
9
8data AngularOptions = AngularOptions
10data AngularOptions = AngularOptions
9 { serviceName :: String -- ^ When generating code with wrapInService,
11 { serviceName :: String -- ^ When generating code with wrapInService,
@@ -15,8 +17,8 @@ data AngularOptions = AngularOptions
15defAngularOptions :: AngularOptions
17defAngularOptions :: AngularOptions
16defAngularOptions = AngularOptions
18defAngularOptions = AngularOptions
17 { serviceName = ""
19 { serviceName = ""
18− , prologue = \svc m -> m <> "service('" <> svc <> "', function($http) {\n"
20+ , prologue = \svc m -> [i|#{m}service('#{svc}', function($http) {
19− <> " return ({"
21+ return ({|]
20 , epilogue = "});\n});\n"
22 , epilogue = "});\n});\n"
21 }
23 }
22
24
@@ -46,16 +48,17 @@ generateAngularJS ngOpts = generateAngularJSWith ngOpts defCommonGeneratorOption
46
48
47-- js codegen using $http service from Angular
49-- js codegen using $http service from Angular
48generateAngularJSWith :: AngularOptions -> CommonGeneratorOptions -> AjaxReq -> String
50generateAngularJSWith :: AngularOptions -> CommonGeneratorOptions -> AjaxReq -> String
49−generateAngularJSWith ngOptions opts req = "\n" <>
51+generateAngularJSWith ngOptions opts req = [i|
50− fname <> fsep <> " function(" <> argsStr <> ")\n"
52+ #{fname}#{fsep} function(#{argsStr})
51− <> "{\n"
53+ {
52− <> " return $http(\n"
54+ return $http(
53− <> " { url: " <> url <> "\n"
55+ { url: #{url}
54− <> dataBody
56+ #{dataBody}
55− <> reqheaders
57+ #{reqheaders}
56− <> " , method: '" <> method <> "'\n"
58+ , method: '#{method}'
57− <> " });\n"
59+ });
58− <> "}\n"
60+ }
61+|]
59
62
60 where argsStr = intercalate ", " args
63 where argsStr = intercalate ", " args
61 args = http
64 args = http
servant-jquery/src/Servant/JQuery/JQuery.hs+15−12
@@ -1,9 +1,11 @@
1+{-# LANGUAGE QuasiQuotes #-}
1module Servant.JQuery.JQuery where
2module Servant.JQuery.JQuery where
2
3
3import Servant.JQuery.Internal
4import Servant.JQuery.Internal
4import Control.Lens
5import Control.Lens
5import Data.List
6import Data.List
6import Data.Monoid
7import Data.Monoid
8+import Data.String.Interpolate
7
9
8-- | js codegen using JQuery using default options
10-- | js codegen using JQuery using default options
9generateJQueryJS :: AjaxReq -> String
11generateJQueryJS :: AjaxReq -> String
@@ -11,18 +13,19 @@ generateJQueryJS = generateJQueryJSWith defCommonGeneratorOptions
11
13
12-- | js codegen using JQuery
14-- | js codegen using JQuery
13generateJQueryJSWith :: CommonGeneratorOptions -> AjaxReq -> String
15generateJQueryJSWith :: CommonGeneratorOptions -> AjaxReq -> String
14−generateJQueryJSWith opts req = "\n" <>
16+generateJQueryJSWith opts req = [i|
15− fname <> " = function(" <> argsStr <> ")\n"
17+ #{fname} = function(#{argsStr})
16− <> "{\n"
18+ {
17− <> " $.ajax(\n"
19+ $.ajax(
18− <> " { url: " <> url <> "\n"
20+ { url: #{url}
19− <> " , success: " <> onSuccess <> "\n"
21+ , success: #{onSuccess}
20− <> dataBody
22+ #{dataBody}
21− <> reqheaders
23+ #{reqheaders}
22− <> " , error: " <> onError <> "\n"
24+ , error: #{onError}
23− <> " , type: '" <> method <> "'\n"
25+ , type: '#{method}'
24− <> " });\n"
26+ });
25− <> "}\n"
27+ }
28+|]
26
29
27 where argsStr = intercalate ", " args
30 where argsStr = intercalate ", " args
28 args = captures
31 args = captures
servant-jquery/src/Servant/JQuery/Vanilla.hs+21−18
@@ -1,9 +1,11 @@
1+{-# LANGUAGE QuasiQuotes #-}
1module Servant.JQuery.Vanilla where
2module Servant.JQuery.Vanilla where
2
3
3import Servant.JQuery.Internal
4import Servant.JQuery.Internal
4import Control.Lens
5import Control.Lens
5import Data.List
6import Data.List
6import Data.Monoid
7import Data.Monoid
8+import Data.String.Interpolate
7
9
8-- | js codegen using XmlHttpRequest using default generation options
10-- | js codegen using XmlHttpRequest using default generation options
9generateVanillaJS :: AjaxReq -> String
11generateVanillaJS :: AjaxReq -> String
@@ -11,24 +13,25 @@ generateVanillaJS = generateVanillaJSWith defCommonGeneratorOptions
11
13
12-- | js codegen using XmlHttpRequest
14-- | js codegen using XmlHttpRequest
13generateVanillaJSWith :: CommonGeneratorOptions -> AjaxReq -> String
15generateVanillaJSWith :: CommonGeneratorOptions -> AjaxReq -> String
14−generateVanillaJSWith opts req = "\n" <>
16+generateVanillaJSWith opts req = [i|
15− fname <> " = function(" <> argsStr <> ")\n"
17+ #{fname} = function(#{argsStr})
16− <> "{\n"
18+ {
17− <> " var xhr = new XMLHttpRequest();\n"
19+ var xhr = new XMLHttpRequest();
18− <> " xhr.open('" <> method <> "', " <> url <> ", true);\n"
20+ xhr.open('#{method}', #{url}, true);
19− <> reqheaders
21+ #{reqheaders}
20− <> " xhr.onreadystatechange = function (e) {\n"
22+ xhr.onreadystatechange = function (e) {
21− <> " if (xhr.readyState == 4) {\n"
23+ if (xhr.readyState == 4) {
22− <> " var value = JSON.parse(xhr.responseText);\n"
24+ var value = JSON.parse(xhr.responseText);
23− <> " if (xhr.status == 200 || xhr.status == 201) {\n"
25+ if (xhr.status == 200 || xhr.status == 201) {
24− <> " onSuccess(value);\n"
26+ #{onSuccess}(value);
25− <> " } else {\n"
27+ } else {
26− <> " onError(value);\n"
28+ #{onError}(value);
27− <> " }\n"
29+ }
28− <> " }\n"
30+ }
29− <> " }\n"
31+ }
30− <> " xhr.send(" <> dataBody <> ");\n"
32+ xhr.send(#{dataBody});
31− <> "}\n"
33+ }
34+|]
32
35
33 where argsStr = intercalate ", " args
36 where argsStr = intercalate ", " args
34 args = captures
37 args = captures