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-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-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".
## Tutorial

View File

@ -9,12 +9,12 @@ let modifiedHaskellPackages = haskellngPackages.override {
../servant-server {}) "--ghc-options=-Werror";
servant-client = appendConfigureFlag (self.callPackage
../servant-client {}) "--ghc-options=-Werror";
servant-jquery = appendConfigureFlag (self.callPackage
../servant-jquery {}) "--ghc-options=-Werror";
servant-js = appendConfigureFlag (self.callPackage
../servant-js {}) "--ghc-options=-Werror";
servant-docs = appendConfigureFlag (self.callPackage ../servant-docs
{}) "--ghc-options=-Werror";
};
};
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
, servant == 0.4.*
, servant-docs == 0.4.*
, servant-jquery == 0.4.*
, servant-js == 0.4.*
, servant-lucid == 0.4.*
, servant-server == 0.4.*
, text

View File

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

View File

@ -3,7 +3,7 @@
, servant-server, stdenv, stm, text, transformers, warp
}:
mkDerivation {
pname = "servant-jquery";
pname = "servant-js";
version = "0.4.0";
src = ./.;
isLibrary = true;
@ -16,6 +16,6 @@ mkDerivation {
base hspec hspec-expectations language-ecmascript lens servant
];
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;
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,9 +1,11 @@
name: servant-jquery
name: servant-js
version: 0.4.1
synopsis: Automatically derive (jquery) javascript functions to query servant webservices
synopsis: Automatically derive javascript functions to query servant webservices.
description:
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>
which serves the generated javascript to a webpage that allows you to trigger
webservice calls.
@ -32,11 +34,11 @@ flag example
default: False
library
exposed-modules: Servant.JQuery
Servant.JQuery.Angular
Servant.JQuery.JQuery
Servant.JQuery.Vanilla
other-modules: Servant.JQuery.Internal
exposed-modules: Servant.JS
Servant.JS.Angular
Servant.JS.JQuery
Servant.JS.Vanilla
other-modules: Servant.JS.Internal
build-depends: base >=4.5 && <5
, charset
, lens >= 4
@ -62,7 +64,7 @@ executable counter
, filepath
, servant == 0.4.*
, servant-server == 0.4.*
, servant-jquery == 0.4.*
, servant-js == 0.4.*
, stm
, transformers
, warp
@ -76,7 +78,7 @@ test-suite spec
build-depends:
base == 4.*
, lens
, servant-jquery
, servant-js
, servant
, hspec >= 2.0
, hspec-expectations

View File

@ -5,25 +5,24 @@
-----------------------------------------------------------------------------
-- |
-- Module : Servant.JQuery
-- Copyright : (C) 2014 Alp Mestanogullari
-- License : BSD3
-- Maintainer : Alp Mestanogullari <alpmestan@gmail.com>
-- Stability : experimental
-- Portability : non-portable
module Servant.JQuery
module Servant.JS
( javascript
, generateJS
, jsForAPI
, listFromAPI
, printJS
, module Servant.JQuery.Internal
, module Servant.JS.Internal
, GenerateCode(..)
, CommonGeneratorOptions(..)
) where
import Data.Proxy
import Servant.API
import Servant.JQuery.Internal
import Servant.JS.Internal
javascript :: HasJS layout => Proxy layout -> JS layout
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 Data.List
import Data.Monoid
data AngularOptions = AngularOptions
{ 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
, epilogue :: String -- ^ end of the service definition
}
-- | Default options for the Angular codegen. Used by 'wrapInService'.
defAngularOptions :: AngularOptions
defAngularOptions = AngularOptions
{ serviceName = ""
@ -21,8 +22,8 @@ defAngularOptions = AngularOptions
}
-- | Instead of simply generating top level functions, generates a service instance
-- on which your controllers can depend to access your API
-- This variant uses default AngularOptions
-- on which your controllers can depend to access your API.
-- This variant uses default 'AngularOptions'.
wrapInService :: AngularOptions -> [AjaxReq] -> String
wrapInService ngOpts reqs = wrapInServiceWith ngOpts defCommonGeneratorOptions reqs

View File

@ -8,7 +8,7 @@
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE UndecidableInstances #-}
module Servant.JQuery.Internal where
module Servant.JS.Internal where
#if !MIN_VERSION_base(4,8,0)
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 Data.List
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 Data.List
import Data.Monoid

View File

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

View File

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

View File

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