Revert "Replace <> with interpolate QQ"

This reverts commit 7fb4471b00.
This commit is contained in:
Freezeboy 2015-07-18 12:20:36 +02:00 committed by Alp Mestanogullari
parent a50d36c786
commit 688bc7520e
4 changed files with 42 additions and 52 deletions

View File

@ -42,7 +42,6 @@ library
, lens >= 4 , lens >= 4
, servant == 0.4.* , servant == 0.4.*
, text , text
, interpolate
hs-source-dirs: src hs-source-dirs: src
default-language: Haskell2010 default-language: Haskell2010
ghc-options: -Wall ghc-options: -Wall

View File

@ -1,11 +1,9 @@
{-# LANGUAGE QuasiQuotes #-}
module Servant.JQuery.Angular where module Servant.JQuery.Angular where
import Servant.JQuery.Internal import Servant.JQuery.Internal
import Control.Lens import Control.Lens
import Data.List import Data.List
import Data.Monoid import Data.Monoid
import Data.String.Interpolate
data AngularOptions = AngularOptions data AngularOptions = AngularOptions
{ serviceName :: String -- ^ When generating code with wrapInService, { serviceName :: String -- ^ When generating code with wrapInService,
@ -17,8 +15,8 @@ data AngularOptions = AngularOptions
defAngularOptions :: AngularOptions defAngularOptions :: AngularOptions
defAngularOptions = AngularOptions defAngularOptions = AngularOptions
{ serviceName = "" { serviceName = ""
, prologue = \svc m -> [i|#{m}service('#{svc}', function($http) { , prologue = \svc m -> m <> "service('" <> svc <> "', function($http) {\n"
return ({|] <> " return ({"
, epilogue = "});\n});\n" , epilogue = "});\n});\n"
} }
@ -48,17 +46,16 @@ generateAngularJS ngOpts = generateAngularJSWith ngOpts defCommonGeneratorOption
-- js codegen using $http service from Angular -- js codegen using $http service from Angular
generateAngularJSWith :: AngularOptions -> CommonGeneratorOptions -> AjaxReq -> String generateAngularJSWith :: AngularOptions -> CommonGeneratorOptions -> AjaxReq -> String
generateAngularJSWith ngOptions opts req = [i| generateAngularJSWith ngOptions opts req = "\n" <>
#{fname}#{fsep} function(#{argsStr}) fname <> fsep <> " function(" <> argsStr <> ")\n"
{ <> "{\n"
return $http( <> " return $http(\n"
{ url: #{url} <> " { url: " <> url <> "\n"
#{dataBody} <> dataBody
#{reqheaders} <> reqheaders
, method: '#{method}' <> " , method: '" <> method <> "'\n"
}); <> " });\n"
} <> "}\n"
|]
where argsStr = intercalate ", " args where argsStr = intercalate ", " args
args = http args = http

View File

@ -1,11 +1,9 @@
{-# LANGUAGE QuasiQuotes #-}
module Servant.JQuery.JQuery where module Servant.JQuery.JQuery where
import Servant.JQuery.Internal import Servant.JQuery.Internal
import Control.Lens import Control.Lens
import Data.List import Data.List
import Data.Monoid import Data.Monoid
import Data.String.Interpolate
-- | js codegen using JQuery using default options -- | js codegen using JQuery using default options
generateJQueryJS :: AjaxReq -> String generateJQueryJS :: AjaxReq -> String
@ -13,19 +11,18 @@ generateJQueryJS = generateJQueryJSWith defCommonGeneratorOptions
-- | js codegen using JQuery -- | js codegen using JQuery
generateJQueryJSWith :: CommonGeneratorOptions -> AjaxReq -> String generateJQueryJSWith :: CommonGeneratorOptions -> AjaxReq -> String
generateJQueryJSWith opts req = [i| generateJQueryJSWith opts req = "\n" <>
#{fname} = function(#{argsStr}) fname <> " = function(" <> argsStr <> ")\n"
{ <> "{\n"
$.ajax( <> " $.ajax(\n"
{ url: #{url} <> " { url: " <> url <> "\n"
, success: #{onSuccess} <> " , success: " <> onSuccess <> "\n"
#{dataBody} <> dataBody
#{reqheaders} <> reqheaders
, error: #{onError} <> " , error: " <> onError <> "\n"
, type: '#{method}' <> " , type: '" <> method <> "'\n"
}); <> " });\n"
} <> "}\n"
|]
where argsStr = intercalate ", " args where argsStr = intercalate ", " args
args = captures args = captures

View File

@ -1,11 +1,9 @@
{-# LANGUAGE QuasiQuotes #-}
module Servant.JQuery.Vanilla where module Servant.JQuery.Vanilla where
import Servant.JQuery.Internal import Servant.JQuery.Internal
import Control.Lens import Control.Lens
import Data.List import Data.List
import Data.Monoid import Data.Monoid
import Data.String.Interpolate
-- | js codegen using XmlHttpRequest using default generation options -- | js codegen using XmlHttpRequest using default generation options
generateVanillaJS :: AjaxReq -> String generateVanillaJS :: AjaxReq -> String
@ -13,25 +11,24 @@ generateVanillaJS = generateVanillaJSWith defCommonGeneratorOptions
-- | js codegen using XmlHttpRequest -- | js codegen using XmlHttpRequest
generateVanillaJSWith :: CommonGeneratorOptions -> AjaxReq -> String generateVanillaJSWith :: CommonGeneratorOptions -> AjaxReq -> String
generateVanillaJSWith opts req = [i| generateVanillaJSWith opts req = "\n" <>
#{fname} = function(#{argsStr}) fname <> " = function(" <> argsStr <> ")\n"
{ <> "{\n"
var xhr = new XMLHttpRequest(); <> " var xhr = new XMLHttpRequest();\n"
xhr.open('#{method}', #{url}, true); <> " xhr.open('" <> method <> "', " <> url <> ", true);\n"
#{reqheaders} <> reqheaders
xhr.onreadystatechange = function (e) { <> " xhr.onreadystatechange = function (e) {\n"
if (xhr.readyState == 4) { <> " if (xhr.readyState == 4) {\n"
var value = JSON.parse(xhr.responseText); <> " var value = JSON.parse(xhr.responseText);\n"
if (xhr.status == 200 || xhr.status == 201) { <> " if (xhr.status == 200 || xhr.status == 201) {\n"
#{onSuccess}(value); <> " onSuccess(value);\n"
} else { <> " } else {\n"
#{onError}(value); <> " onError(value);\n"
} <> " }\n"
} <> " }\n"
} <> " }\n"
xhr.send(#{dataBody}); <> " xhr.send(" <> dataBody <> ");\n"
} <> "}\n"
|]
where argsStr = intercalate ", " args where argsStr = intercalate ", " args
args = captures args = captures