From 688bc7520eda356df76b3b3b8bbc4f55f63f4e0f Mon Sep 17 00:00:00 2001 From: Freezeboy Date: Sat, 18 Jul 2015 12:20:36 +0200 Subject: [PATCH] Revert "Replace <> with interpolate QQ" This reverts commit 7fb4471b00919dfe0edf876f72793721ba6198ce. --- servant-jquery/servant-jquery.cabal | 1 - servant-jquery/src/Servant/JQuery/Angular.hs | 27 ++++++-------- servant-jquery/src/Servant/JQuery/JQuery.hs | 27 ++++++-------- servant-jquery/src/Servant/JQuery/Vanilla.hs | 39 +++++++++----------- 4 files changed, 42 insertions(+), 52 deletions(-) diff --git a/servant-jquery/servant-jquery.cabal b/servant-jquery/servant-jquery.cabal index 8dca1658..c690e806 100644 --- a/servant-jquery/servant-jquery.cabal +++ b/servant-jquery/servant-jquery.cabal @@ -42,7 +42,6 @@ library , lens >= 4 , servant == 0.4.* , text - , interpolate hs-source-dirs: src default-language: Haskell2010 ghc-options: -Wall diff --git a/servant-jquery/src/Servant/JQuery/Angular.hs b/servant-jquery/src/Servant/JQuery/Angular.hs index 4015f937..409a306f 100644 --- a/servant-jquery/src/Servant/JQuery/Angular.hs +++ b/servant-jquery/src/Servant/JQuery/Angular.hs @@ -1,11 +1,9 @@ -{-# LANGUAGE QuasiQuotes #-} module Servant.JQuery.Angular where import Servant.JQuery.Internal import Control.Lens import Data.List import Data.Monoid -import Data.String.Interpolate data AngularOptions = AngularOptions { serviceName :: String -- ^ When generating code with wrapInService, @@ -17,8 +15,8 @@ data AngularOptions = AngularOptions defAngularOptions :: AngularOptions defAngularOptions = AngularOptions { serviceName = "" - , prologue = \svc m -> [i|#{m}service('#{svc}', function($http) { - return ({|] + , prologue = \svc m -> m <> "service('" <> svc <> "', function($http) {\n" + <> " return ({" , epilogue = "});\n});\n" } @@ -48,17 +46,16 @@ generateAngularJS ngOpts = generateAngularJSWith ngOpts defCommonGeneratorOption -- js codegen using $http service from Angular generateAngularJSWith :: AngularOptions -> CommonGeneratorOptions -> AjaxReq -> String -generateAngularJSWith ngOptions opts req = [i| - #{fname}#{fsep} function(#{argsStr}) - { - return $http( - { url: #{url} - #{dataBody} - #{reqheaders} - , method: '#{method}' - }); - } -|] +generateAngularJSWith ngOptions opts req = "\n" <> + fname <> fsep <> " function(" <> argsStr <> ")\n" + <> "{\n" + <> " return $http(\n" + <> " { url: " <> url <> "\n" + <> dataBody + <> reqheaders + <> " , method: '" <> method <> "'\n" + <> " });\n" + <> "}\n" where argsStr = intercalate ", " args args = http diff --git a/servant-jquery/src/Servant/JQuery/JQuery.hs b/servant-jquery/src/Servant/JQuery/JQuery.hs index 25af6b06..01fabfda 100644 --- a/servant-jquery/src/Servant/JQuery/JQuery.hs +++ b/servant-jquery/src/Servant/JQuery/JQuery.hs @@ -1,11 +1,9 @@ -{-# LANGUAGE QuasiQuotes #-} module Servant.JQuery.JQuery where import Servant.JQuery.Internal import Control.Lens import Data.List import Data.Monoid -import Data.String.Interpolate -- | js codegen using JQuery using default options generateJQueryJS :: AjaxReq -> String @@ -13,19 +11,18 @@ generateJQueryJS = generateJQueryJSWith defCommonGeneratorOptions -- | js codegen using JQuery generateJQueryJSWith :: CommonGeneratorOptions -> AjaxReq -> String -generateJQueryJSWith opts req = [i| - #{fname} = function(#{argsStr}) - { - $.ajax( - { url: #{url} - , success: #{onSuccess} - #{dataBody} - #{reqheaders} - , error: #{onError} - , type: '#{method}' - }); - } -|] +generateJQueryJSWith opts req = "\n" <> + fname <> " = function(" <> argsStr <> ")\n" + <> "{\n" + <> " $.ajax(\n" + <> " { url: " <> url <> "\n" + <> " , success: " <> onSuccess <> "\n" + <> dataBody + <> reqheaders + <> " , error: " <> onError <> "\n" + <> " , type: '" <> method <> "'\n" + <> " });\n" + <> "}\n" where argsStr = intercalate ", " args args = captures diff --git a/servant-jquery/src/Servant/JQuery/Vanilla.hs b/servant-jquery/src/Servant/JQuery/Vanilla.hs index 302bb5cf..919cb97f 100644 --- a/servant-jquery/src/Servant/JQuery/Vanilla.hs +++ b/servant-jquery/src/Servant/JQuery/Vanilla.hs @@ -1,11 +1,9 @@ -{-# LANGUAGE QuasiQuotes #-} module Servant.JQuery.Vanilla where import Servant.JQuery.Internal import Control.Lens import Data.List import Data.Monoid -import Data.String.Interpolate -- | js codegen using XmlHttpRequest using default generation options generateVanillaJS :: AjaxReq -> String @@ -13,25 +11,24 @@ generateVanillaJS = generateVanillaJSWith defCommonGeneratorOptions -- | js codegen using XmlHttpRequest generateVanillaJSWith :: CommonGeneratorOptions -> AjaxReq -> String -generateVanillaJSWith opts req = [i| - #{fname} = function(#{argsStr}) - { - var xhr = new XMLHttpRequest(); - xhr.open('#{method}', #{url}, true); - #{reqheaders} - xhr.onreadystatechange = function (e) { - if (xhr.readyState == 4) { - var value = JSON.parse(xhr.responseText); - if (xhr.status == 200 || xhr.status == 201) { - #{onSuccess}(value); - } else { - #{onError}(value); - } - } - } - xhr.send(#{dataBody}); - } -|] +generateVanillaJSWith opts req = "\n" <> + fname <> " = function(" <> argsStr <> ")\n" + <> "{\n" + <> " var xhr = new XMLHttpRequest();\n" + <> " xhr.open('" <> method <> "', " <> url <> ", true);\n" + <> reqheaders + <> " xhr.onreadystatechange = function (e) {\n" + <> " if (xhr.readyState == 4) {\n" + <> " var value = JSON.parse(xhr.responseText);\n" + <> " if (xhr.status == 200 || xhr.status == 201) {\n" + <> " onSuccess(value);\n" + <> " } else {\n" + <> " onError(value);\n" + <> " }\n" + <> " }\n" + <> " }\n" + <> " xhr.send(" <> dataBody <> ");\n" + <> "}\n" where argsStr = intercalate ", " args args = captures