rename servant-jquery to servant-js, Servant.JQuery to Servant.JS

This commit is contained in:
Alp Mestanogullari 2015-07-22 12:55:44 +02:00
parent 688bc7520e
commit eabf13ebdb
30 changed files with 48 additions and 50 deletions

View file

@ -13,7 +13,7 @@ In order to minimize the dependencies depending on your needs, we provide these
- `servant-server`, which lets you *implement* an HTTP server with handlers for each endpoint of an API. - `servant-server`, which lets you *implement* an HTTP server with handlers for each endpoint of an API.
- `servant-client`, which lets you derive automatically Haskell functions that let you query each endpoint of a `servant` webservice. - `servant-client`, which lets you derive automatically Haskell functions that let you query each endpoint of a `servant` webservice.
- `servant-docs`, which lets you generate API docs for your webservice. - `servant-docs`, which lets you generate API docs for your webservice.
- `servant-jquery`, which lets you derive Javascript functions (based on jquery) to query your API's endpoints, in the same spirit as `servant-client`. - `servant-js`, which lets you derive Javascript functions (using vanilla JS ajax requests, angular or jquery) to query your API's endpoints, in the same spirit as `servant-client`.
- `servant-blaze` and `servant-lucid` provide easy HTML rendering of your data as an `HTML` content-type "combinator". - `servant-blaze` and `servant-lucid` provide easy HTML rendering of your data as an `HTML` content-type "combinator".
## Tutorial ## Tutorial

View file

@ -9,12 +9,12 @@ let modifiedHaskellPackages = haskellngPackages.override {
../servant-server {}) "--ghc-options=-Werror"; ../servant-server {}) "--ghc-options=-Werror";
servant-client = appendConfigureFlag (self.callPackage servant-client = appendConfigureFlag (self.callPackage
../servant-client {}) "--ghc-options=-Werror"; ../servant-client {}) "--ghc-options=-Werror";
servant-jquery = appendConfigureFlag (self.callPackage servant-js = appendConfigureFlag (self.callPackage
../servant-jquery {}) "--ghc-options=-Werror"; ../servant-js {}) "--ghc-options=-Werror";
servant-docs = appendConfigureFlag (self.callPackage ../servant-docs servant-docs = appendConfigureFlag (self.callPackage ../servant-docs
{}) "--ghc-options=-Werror"; {}) "--ghc-options=-Werror";
}; };
}; };
in modifiedHaskellPackages.ghcWithPackages ( p : with p ; [ in modifiedHaskellPackages.ghcWithPackages ( p : with p ; [
servant servant-server servant-client servant-jquery servant-docs servant servant-server servant-client servant-js servant-docs
]) ])

View file

@ -32,7 +32,7 @@ executable tutorial
, random , random
, servant == 0.4.* , servant == 0.4.*
, servant-docs == 0.4.* , servant-docs == 0.4.*
, servant-jquery == 0.4.* , servant-js == 0.4.*
, servant-lucid == 0.4.* , servant-lucid == 0.4.*
, servant-server == 0.4.* , servant-server == 0.4.*
, text , text

View file

@ -1,4 +1,4 @@
# servant-jquery # servant-js
![servant](https://raw.githubusercontent.com/haskell-servant/servant/master/servant.png) ![servant](https://raw.githubusercontent.com/haskell-servant/servant/master/servant.png)

View file

@ -3,7 +3,7 @@
, servant-server, stdenv, stm, text, transformers, warp , servant-server, stdenv, stm, text, transformers, warp
}: }:
mkDerivation { mkDerivation {
pname = "servant-jquery"; pname = "servant-js";
version = "0.4.0"; version = "0.4.0";
src = ./.; src = ./.;
isLibrary = true; isLibrary = true;
@ -16,6 +16,6 @@ mkDerivation {
base hspec hspec-expectations language-ecmascript lens servant base hspec hspec-expectations language-ecmascript lens servant
]; ];
homepage = "http://haskell-servant.github.io/"; homepage = "http://haskell-servant.github.io/";
description = "Automatically derive (jquery) javascript functions to query servant webservices"; description = "Automatically derive javascript functions to query servant webservices";
license = stdenv.lib.licenses.bsd3; license = stdenv.lib.licenses.bsd3;
} }

View file

@ -10,11 +10,11 @@ import Data.Proxy
import GHC.Generics import GHC.Generics
import Network.Wai.Handler.Warp (run) import Network.Wai.Handler.Warp (run)
import Servant import Servant
import Servant.JQuery import Servant.JS
import qualified Servant.JQuery as SJQ import qualified Servant.JS as SJS
import qualified Servant.JQuery.Vanilla as JS import qualified Servant.JS.Vanilla as JS
import qualified Servant.JQuery.JQuery as JQ import qualified Servant.JS.JQuery as JQ
import qualified Servant.JQuery.Angular as NG import qualified Servant.JS.Angular as NG
import System.FilePath import System.FilePath
-- * A simple Counter data type -- * A simple Counter data type
@ -77,7 +77,7 @@ writeJS gen fp functions = writeFile fp $
writeServiceJS :: FilePath -> [AjaxReq] -> IO () writeServiceJS :: FilePath -> [AjaxReq] -> IO ()
writeServiceJS fp functions = writeFile fp $ writeServiceJS fp functions = writeFile fp $
NG.wrapInServiceWith (NG.defAngularOptions { NG.serviceName = "counterSvc" }) NG.wrapInServiceWith (NG.defAngularOptions { NG.serviceName = "counterSvc" })
(defCommonGeneratorOptions { SJQ.moduleName = "counterApp" }) functions (defCommonGeneratorOptions { SJS.moduleName = "counterApp" }) functions
main :: IO () main :: IO ()
main = do main = do

View file

@ -13,7 +13,6 @@
<h1>Angular version</h1> <h1>Angular version</h1>
<span id="counter">{{ 'Counter: ' + counter }}</span> <span id="counter">{{ 'Counter: ' + counter }}</span>
<button ng-click="incCounter()" id="inc">Increase</button> <button ng-click="incCounter()" id="inc">Increase</button>
or <a href="/doc">view the docs</a>
<script type="text/javascript"> <script type="text/javascript">
var counterApp = angular.module('counterApp', []); var counterApp = angular.module('counterApp', []);

View file

@ -12,7 +12,6 @@
<h1>Angular version (Service version)</h1> <h1>Angular version (Service version)</h1>
<span id="counter">{{ 'Counter: ' + counter }}</span> <span id="counter">{{ 'Counter: ' + counter }}</span>
<button ng-click="incCounter()" id="inc">Increase</button> <button ng-click="incCounter()" id="inc">Increase</button>
or <a href="/doc">view the docs</a>
<script type="text/javascript"> <script type="text/javascript">
var counterApp = angular.module('counterApp', []); var counterApp = angular.module('counterApp', []);

View file

@ -11,7 +11,6 @@
<h1>JQuery version</h1> <h1>JQuery version</h1>
<span id="counter">Counter: 0</span> <span id="counter">Counter: 0</span>
<button id="inc">Increase</button> <button id="inc">Increase</button>
or <a href="/doc">view the docs</a>
<script src="jquery.min.js" type="text/javascript"></script> <script src="jquery.min.js" type="text/javascript"></script>
<script src="api.js" type="text/javascript"></script> <script src="api.js" type="text/javascript"></script>

View file

@ -11,7 +11,6 @@
<h1>Vanilla version</h1> <h1>Vanilla version</h1>
<span id="counter">Counter: 0</span> <span id="counter">Counter: 0</span>
<button id="inc">Increase</button> <button id="inc">Increase</button>
or <a href="/doc">view the docs</a>
<script src="api.js" type="text/javascript"></script> <script src="api.js" type="text/javascript"></script>
<script type="text/javascript"> <script type="text/javascript">

View file

@ -1,9 +1,11 @@
name: servant-jquery name: servant-js
version: 0.4.1 version: 0.4.1
synopsis: Automatically derive (jquery) javascript functions to query servant webservices synopsis: Automatically derive javascript functions to query servant webservices.
description: description:
Automatically derive jquery-based javascript functions to query servant webservices. Automatically derive jquery-based javascript functions to query servant webservices.
. .
Supports deriving functions using vanilla javascript AJAX requests, Angular or JQuery.
.
You can find an example <https://github.com/haskell-servant/servant/blob/master/servant-jquery/examples/counter.hs here> You can find an example <https://github.com/haskell-servant/servant/blob/master/servant-jquery/examples/counter.hs here>
which serves the generated javascript to a webpage that allows you to trigger which serves the generated javascript to a webpage that allows you to trigger
webservice calls. webservice calls.
@ -32,11 +34,11 @@ flag example
default: False default: False
library library
exposed-modules: Servant.JQuery exposed-modules: Servant.JS
Servant.JQuery.Angular Servant.JS.Angular
Servant.JQuery.JQuery Servant.JS.JQuery
Servant.JQuery.Vanilla Servant.JS.Vanilla
other-modules: Servant.JQuery.Internal other-modules: Servant.JS.Internal
build-depends: base >=4.5 && <5 build-depends: base >=4.5 && <5
, charset , charset
, lens >= 4 , lens >= 4
@ -62,7 +64,7 @@ executable counter
, filepath , filepath
, servant == 0.4.* , servant == 0.4.*
, servant-server == 0.4.* , servant-server == 0.4.*
, servant-jquery == 0.4.* , servant-js == 0.4.*
, stm , stm
, transformers , transformers
, warp , warp
@ -76,7 +78,7 @@ test-suite spec
build-depends: build-depends:
base == 4.* base == 4.*
, lens , lens
, servant-jquery , servant-js
, servant , servant
, hspec >= 2.0 , hspec >= 2.0
, hspec-expectations , hspec-expectations

View file

@ -5,25 +5,24 @@
----------------------------------------------------------------------------- -----------------------------------------------------------------------------
-- | -- |
-- Module : Servant.JQuery -- Module : Servant.JQuery
-- Copyright : (C) 2014 Alp Mestanogullari
-- License : BSD3 -- License : BSD3
-- Maintainer : Alp Mestanogullari <alpmestan@gmail.com> -- Maintainer : Alp Mestanogullari <alpmestan@gmail.com>
-- Stability : experimental -- Stability : experimental
-- Portability : non-portable -- Portability : non-portable
module Servant.JQuery module Servant.JS
( javascript ( javascript
, generateJS , generateJS
, jsForAPI , jsForAPI
, listFromAPI , listFromAPI
, printJS , printJS
, module Servant.JQuery.Internal , module Servant.JS.Internal
, GenerateCode(..) , GenerateCode(..)
, CommonGeneratorOptions(..) , CommonGeneratorOptions(..)
) where ) where
import Data.Proxy import Data.Proxy
import Servant.API import Servant.API
import Servant.JQuery.Internal import Servant.JS.Internal
javascript :: HasJS layout => Proxy layout -> JS layout javascript :: HasJS layout => Proxy layout -> JS layout
javascript p = javascriptFor p defReq javascript p = javascriptFor p defReq

View file

@ -1,17 +1,18 @@
module Servant.JQuery.Angular where module Servant.JS.Angular where
import Servant.JQuery.Internal import Servant.JS.Internal
import Control.Lens import Control.Lens
import Data.List import Data.List
import Data.Monoid import Data.Monoid
data AngularOptions = AngularOptions data AngularOptions = AngularOptions
{ serviceName :: String -- ^ When generating code with wrapInService, { serviceName :: String -- ^ When generating code with wrapInService,
-- ^ name of the service to generate -- name of the service to generate
, prologue :: String -> String -> String -- ^ beginning of the service definition , prologue :: String -> String -> String -- ^ beginning of the service definition
, epilogue :: String -- ^ end of the service definition , epilogue :: String -- ^ end of the service definition
} }
-- | Default options for the Angular codegen. Used by 'wrapInService'.
defAngularOptions :: AngularOptions defAngularOptions :: AngularOptions
defAngularOptions = AngularOptions defAngularOptions = AngularOptions
{ serviceName = "" { serviceName = ""
@ -21,8 +22,8 @@ defAngularOptions = AngularOptions
} }
-- | Instead of simply generating top level functions, generates a service instance -- | Instead of simply generating top level functions, generates a service instance
-- on which your controllers can depend to access your API -- on which your controllers can depend to access your API.
-- This variant uses default AngularOptions -- This variant uses default 'AngularOptions'.
wrapInService :: AngularOptions -> [AjaxReq] -> String wrapInService :: AngularOptions -> [AjaxReq] -> String
wrapInService ngOpts reqs = wrapInServiceWith ngOpts defCommonGeneratorOptions reqs wrapInService ngOpts reqs = wrapInServiceWith ngOpts defCommonGeneratorOptions reqs

View file

@ -8,7 +8,7 @@
{-# LANGUAGE TypeFamilies #-} {-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-} {-# LANGUAGE TypeOperators #-}
{-# LANGUAGE UndecidableInstances #-} {-# LANGUAGE UndecidableInstances #-}
module Servant.JQuery.Internal where module Servant.JS.Internal where
#if !MIN_VERSION_base(4,8,0) #if !MIN_VERSION_base(4,8,0)
import Control.Applicative import Control.Applicative

View file

@ -1,6 +1,6 @@
module Servant.JQuery.JQuery where module Servant.JS.JQuery where
import Servant.JQuery.Internal import Servant.JS.Internal
import Control.Lens import Control.Lens
import Data.List import Data.List
import Data.Monoid import Data.Monoid

View file

@ -1,6 +1,6 @@
module Servant.JQuery.Vanilla where module Servant.JS.Vanilla where
import Servant.JQuery.Internal import Servant.JS.Internal
import Control.Lens import Control.Lens
import Data.List import Data.List
import Data.Monoid import Data.Monoid

View file

@ -5,7 +5,7 @@
{-# LANGUAGE TypeFamilies #-} {-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-} {-# LANGUAGE TypeOperators #-}
{-# OPTIONS_GHC -fno-warn-orphans #-} {-# OPTIONS_GHC -fno-warn-orphans #-}
module Servant.JQuerySpec where module Servant.JSSpec where
import Data.Either (isRight) import Data.Either (isRight)
import Data.Proxy import Data.Proxy
@ -13,11 +13,11 @@ import Language.ECMAScript3.Parser (parseFromString)
import Test.Hspec import Test.Hspec
import Servant.API import Servant.API
import Servant.JQuery import Servant.JS
import qualified Servant.JQuery.Vanilla as JS import qualified Servant.JS.Vanilla as JS
import qualified Servant.JQuery.JQuery as JQ import qualified Servant.JS.JQuery as JQ
import qualified Servant.JQuery.Angular as NG import qualified Servant.JS.Angular as NG
import Servant.JQuerySpec.CustomHeaders import Servant.JSSpec.CustomHeaders
type TestAPI = "simple" :> ReqBody '[JSON,FormUrlEncoded] String :> Post '[JSON] Bool type TestAPI = "simple" :> ReqBody '[JSON,FormUrlEncoded] String :> Post '[JSON] Bool
:<|> "has.extension" :> Get '[FormUrlEncoded,JSON] Bool :<|> "has.extension" :> Get '[FormUrlEncoded,JSON] Bool

View file

@ -6,14 +6,14 @@
{-# LANGUAGE TypeFamilies #-} {-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-} {-# LANGUAGE TypeOperators #-}
module Servant.JQuerySpec.CustomHeaders where module Servant.JSSpec.CustomHeaders where
import Control.Lens import Control.Lens
import Data.Monoid import Data.Monoid
import Data.Proxy import Data.Proxy
import GHC.TypeLits import GHC.TypeLits
import Servant.API import Servant.API
import Servant.JQuery import Servant.JS
-- | This is a hypothetical combinator that fetches an Authorization header. -- | This is a hypothetical combinator that fetches an Authorization header.
-- The symbol in the header denotes what kind of authentication we are -- The symbol in the header denotes what kind of authentication we are

View file

@ -1,7 +1,7 @@
servant servant
servant-client servant-client
servant-docs servant-docs
servant-jquery servant-js
servant-server servant-server
servant-examples servant-examples
servant-blaze servant-blaze