Skip to content

Commit

Permalink
stylish haskell changes
Browse files Browse the repository at this point in the history
        And import fix.
  • Loading branch information
jkarni committed Aug 17, 2015
1 parent 55eab3f commit a1fcfd8
Show file tree
Hide file tree
Showing 9 changed files with 81 additions and 81 deletions.
2 changes: 1 addition & 1 deletion Setup.hs
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
import Distribution.Simple
import Distribution.Simple
main = defaultMain
34 changes: 17 additions & 17 deletions examples/counter.hs
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}

import Control.Concurrent.STM
import Control.Monad.IO.Class
import Data.Aeson
import Data.Proxy
import GHC.Generics
import Network.Wai.Handler.Warp (run)
import Servant
import Servant.JS
import qualified Servant.JS as SJS
import qualified Servant.JS.Angular as NG
import System.FilePath
{-# LANGUAGE TypeOperators #-}

import Control.Concurrent.STM
import Control.Monad.IO.Class
import Data.Aeson
import Data.Proxy
import GHC.Generics
import Network.Wai.Handler.Warp (run)
import Servant
import Servant.JS
import qualified Servant.JS as SJS
import qualified Servant.JS.Angular as NG
import System.FilePath

-- * A simple Counter data type
newtype Counter = Counter { value :: Int }
Expand Down Expand Up @@ -43,7 +43,7 @@ type TestApi = "counter" :> Post '[JSON] Counter -- endpoint for increasing the
:<|> "counter" :> Get '[JSON] Counter -- endpoint to get the current value

type TestApi' = TestApi
:<|> Raw -- used for serving static files
:<|> Raw -- used for serving static files

-- this proxy only targets the proper endpoints of our API,
-- not the static file serving bit
Expand Down Expand Up @@ -82,7 +82,7 @@ writeServiceJS fp =
(defCommonGeneratorOptions { SJS.moduleName = "counterApp" })
)
fp

main :: IO ()
main = do
-- write the JS code to www/api.js at startup
Expand Down
22 changes: 11 additions & 11 deletions src/Servant/JS.hs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE TypeOperators #-}
-----------------------------------------------------------------------------
-- |
-- Module : Servant.JS
Expand Down Expand Up @@ -114,13 +114,13 @@ module Servant.JS
, AjaxReq
) where

import Data.Proxy
import Servant.API
import Servant.JS.Angular
import Servant.JS.Axios
import Servant.JS.Internal
import Servant.JS.JQuery
import Servant.JS.Vanilla
import Data.Proxy
import Servant.API
import Servant.JS.Angular
import Servant.JS.Axios
import Servant.JS.Internal
import Servant.JS.JQuery
import Servant.JS.Vanilla

-- | Generate the data necessary to generate javascript code
-- for all the endpoints of an API, as ':<|>'-separated values
Expand Down Expand Up @@ -160,6 +160,6 @@ instance (GenerateList start, GenerateList rest) => GenerateList (start :<|> res
generateList (start :<|> rest) = (generateList start) ++ (generateList rest)

-- | Generate the necessary data for JS codegen as a list, each 'AjaxReq'
-- describing one endpoint from your API type.
-- describing one endpoint from your API type.
listFromAPI :: (HasJS api, GenerateList (JS api)) => Proxy api -> [AjaxReq]
listFromAPI p = generateList (javascript p)
26 changes: 13 additions & 13 deletions src/Servant/JS/Angular.hs
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
module Servant.JS.Angular where

import Servant.JS.Internal
import Control.Lens
import Data.List
import Data.Monoid
import Control.Lens
import Data.List
import Data.Monoid
import Servant.JS.Internal

-- | Options specific to the angular code generator
data AngularOptions = AngularOptions
{ serviceName :: String -- ^ When generating code with wrapInService,
-- name of the service to generate
, prologue :: String -> String -> String -- ^ beginning of the service definition
, epilogue :: String -- ^ end of the service definition
, prologue :: String -> String -> String -- ^ beginning of the service definition
, epilogue :: String -- ^ end of the service definition
}

-- | Default options for the Angular codegen. Used by 'wrapInService'.
Expand All @@ -31,7 +31,7 @@ angularService ngOpts = angularServiceWith ngOpts defCommonGeneratorOptions
-- | Instead of simply generating top level functions, generates a service instance
-- on which your controllers can depend to access your API
angularServiceWith :: AngularOptions -> CommonGeneratorOptions -> JavaScriptGenerator
angularServiceWith ngOpts opts reqs =
angularServiceWith ngOpts opts reqs =
prologue ngOpts svc mName
<> intercalate "," (map generator reqs) <>
epilogue ngOpts
Expand All @@ -54,7 +54,7 @@ angularWith ngopts opts = intercalate "\n\n" . map (generateAngularJSWith ngopts
-- | js codegen using $http service from Angular using default options
generateAngularJS :: AngularOptions -> AjaxReq -> String
generateAngularJS ngOpts = generateAngularJSWith ngOpts defCommonGeneratorOptions

-- | js codegen using $http service from Angular
generateAngularJSWith :: AngularOptions -> CommonGeneratorOptions -> AjaxReq -> String
generateAngularJSWith ngOptions opts req = "\n" <>
Expand All @@ -74,7 +74,7 @@ generateAngularJSWith ngOptions opts req = "\n" <>
++ map (view argName) queryparams
++ body
++ map (toValidFunctionName . (<>) "header" . headerArgName) hs

-- If we want to generate Top Level Function, they must depend on
-- the $http service, if we generate a service, the functions will
-- inherit this dependency from the service
Expand Down Expand Up @@ -118,13 +118,13 @@ generateAngularJSWith ngOptions opts req = "\n" <>
else (moduleName opts) <> "."
where
hasNoModule = null (moduleName opts)

hasService = not $ null (serviceName ngOptions)

fsep = if hasService then ":" else " ="

fname = namespace <> (functionNameBuilder opts $ req ^. funcName)

method = req ^. reqMethod
url = if url' == "'" then "'/'" else url'
url' = "'"
Expand Down
24 changes: 12 additions & 12 deletions src/Servant/JS/Axios.hs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
module Servant.JS.Axios where

import Servant.JS.Internal
import Control.Lens
import Data.Char (toLower)
import Data.List
import Data.Monoid
import Control.Lens
import Data.Char (toLower)
import Data.List
import Data.Monoid
import Servant.JS.Internal

-- | Axios 'configuration' type
-- Let you customize the generation using Axios capabilities
Expand All @@ -13,9 +13,9 @@ data AxiosOptions = AxiosOptions
-- should be made using credentials
withCredentials :: !Bool
-- | the name of the cookie to use as a value for xsrf token
, xsrfCookieName :: !(Maybe String)
, xsrfCookieName :: !(Maybe String)
-- | the name of the header to use as a value for xsrf token
, xsrfHeaderName :: !(Maybe String)
, xsrfHeaderName :: !(Maybe String)
}

-- | Default instance of the AxiosOptions
Expand All @@ -40,7 +40,7 @@ axiosWith aopts opts = intercalate "\n\n" . map (generateAxiosJSWith aopts opts)
-- | js codegen using axios library using default options
generateAxiosJS :: AxiosOptions -> AjaxReq -> String
generateAxiosJS aopts = generateAxiosJSWith aopts defCommonGeneratorOptions

-- | js codegen using axios library
generateAxiosJSWith :: AxiosOptions -> CommonGeneratorOptions -> AjaxReq -> String
generateAxiosJSWith aopts opts req = "\n" <>
Expand All @@ -61,7 +61,7 @@ generateAxiosJSWith aopts opts req = "\n" <>
++ map (view argName) queryparams
++ body
++ map (toValidFunctionName . (<>) "header" . headerArgName) hs

captures = map captureArg
. filter isCapture
$ req ^. reqUrl.path
Expand All @@ -85,7 +85,7 @@ generateAxiosJSWith aopts opts req = "\n" <>
then " , withCredentials: true\n"
else ""

xsrfCookie =
xsrfCookie =
case xsrfCookieName aopts of
Just name -> " , xsrfCookieName: '" <> name <> "'\n"
Nothing -> ""
Expand All @@ -111,9 +111,9 @@ generateAxiosJSWith aopts opts req = "\n" <>
else (moduleName opts) <> "."
where
hasNoModule = null (moduleName opts)

fname = namespace <> (functionNameBuilder opts $ req ^. funcName)

method = map toLower $ req ^. reqMethod
url = if url' == "'" then "'/'" else url'
url' = "'"
Expand Down
8 changes: 4 additions & 4 deletions src/Servant/JS/JQuery.hs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
module Servant.JS.JQuery where

import Servant.JS.Internal
import Control.Lens
import Data.List
import Data.Monoid
import Control.Lens
import Data.List
import Data.Monoid
import Servant.JS.Internal

-- | Generate javascript functions that use the /jQuery/ library
-- to make the AJAX calls. Uses 'defCommonGeneratorOptions'
Expand Down
8 changes: 4 additions & 4 deletions src/Servant/JS/Vanilla.hs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
module Servant.JS.Vanilla where

import Servant.JS.Internal
import Control.Lens
import Data.List
import Data.Monoid
import Control.Lens
import Data.List
import Data.Monoid
import Servant.JS.Internal

-- | Generate vanilla javascript functions to make AJAX requests
-- to your API, using /XMLHttpRequest/. Uses 'defCommonGeneratorOptions'
Expand Down
24 changes: 12 additions & 12 deletions test/Servant/JSSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@
{-# OPTIONS_GHC -fno-warn-orphans #-}
module Servant.JSSpec where

import Data.Either (isRight)
import Data.Proxy
import Language.ECMAScript3.Parser (parseFromString)
import Test.Hspec

import Servant.API
import Servant.JS
import qualified Servant.JS.Vanilla as JS
import qualified Servant.JS.JQuery as JQ
import qualified Servant.JS.Angular as NG
import qualified Servant.JS.Axios as AX
import Servant.JSSpec.CustomHeaders
import Data.Either (isRight)
import Data.Proxy
import Language.ECMAScript3.Parser (parseFromString)
import Test.Hspec

import Servant.API
import Servant.JS
import qualified Servant.JS.Angular as NG
import qualified Servant.JS.Axios as AX
import qualified Servant.JS.JQuery as JQ
import qualified Servant.JS.Vanilla as JS
import Servant.JSSpec.CustomHeaders

type TestAPI = "simple" :> ReqBody '[JSON,FormUrlEncoded] String :> Post '[JSON] Bool
:<|> "has.extension" :> Get '[FormUrlEncoded,JSON] Bool
Expand Down
14 changes: 7 additions & 7 deletions test/Servant/JSSpec/CustomHeaders.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@

module Servant.JSSpec.CustomHeaders where

import Control.Lens
import Data.Monoid
import Data.Proxy
import GHC.TypeLits
import Servant.API
import Servant.JS
import Servant.JS.Internal
import Control.Lens
import Data.Monoid
import Data.Proxy
import GHC.TypeLits
import Servant.API
import Servant.JS
import Servant.JS.Internal

-- | This is a hypothetical combinator that fetches an Authorization header.
-- The symbol in the header denotes what kind of authentication we are
Expand Down

0 comments on commit a1fcfd8

Please sign in to comment.