doc(servant-foreign): Inflection docs & module docs
This commit is contained in:
parent
0743ca724d
commit
c3a517cb4f
3 changed files with 23 additions and 14 deletions
|
@ -1,5 +1,7 @@
|
|||
-- | Generalizes all the data needed to make code generation work with
|
||||
-- arbitrary programming languages.
|
||||
--
|
||||
-- See documentation of 'HasForeignType' for a simple example. 'listFromAPI' returns a list of all your endpoints and their foreign types, given a mapping from Haskell types to foreign types (conventionally called `ftypes` below).
|
||||
module Servant.Foreign
|
||||
( ArgType(..)
|
||||
, HeaderArg(..)
|
||||
|
|
|
@ -20,20 +20,31 @@ import Prelude hiding
|
|||
(head, tail)
|
||||
import Servant.Foreign.Internal
|
||||
|
||||
-- | Simply concat each part of the FunctionName together.
|
||||
--
|
||||
-- @[ "get", "documents", "by", "id" ] → "getdocumentsbyid"@
|
||||
concatCase :: FunctionName -> Text
|
||||
concatCase = view concatCaseL
|
||||
|
||||
concatCaseL :: Getter FunctionName Text
|
||||
concatCaseL = _FunctionName . to mconcat
|
||||
|
||||
-- | Function name builder that simply concat each part together
|
||||
concatCase :: FunctionName -> Text
|
||||
concatCase = view concatCaseL
|
||||
-- | Use the snake_case convention.
|
||||
-- Each part is separated by a single underscore character.
|
||||
--
|
||||
-- @[ "get", "documents", "by", "id" ] → "get_documents_by_id"@
|
||||
snakeCase :: FunctionName -> Text
|
||||
snakeCase = view snakeCaseL
|
||||
|
||||
snakeCaseL :: Getter FunctionName Text
|
||||
snakeCaseL = _FunctionName . to (intercalate "_")
|
||||
|
||||
-- | Function name builder using the snake_case convention.
|
||||
-- each part is separated by a single underscore character.
|
||||
snakeCase :: FunctionName -> Text
|
||||
snakeCase = view snakeCaseL
|
||||
-- | Use the camelCase convention.
|
||||
-- The first part is lower case, every other part starts with an upper case character.
|
||||
--
|
||||
-- @[ "get", "documents", "by", "id" ] → "getDocumentsById"@
|
||||
camelCase :: FunctionName -> Text
|
||||
camelCase = view camelCaseL
|
||||
|
||||
camelCaseL :: Getter FunctionName Text
|
||||
camelCaseL = _FunctionName . to convert
|
||||
|
@ -42,8 +53,3 @@ camelCaseL = _FunctionName . to convert
|
|||
convert (p:ps) = mconcat $ p : map capitalize ps
|
||||
capitalize "" = ""
|
||||
capitalize name = C.toUpper (head name) `cons` tail name
|
||||
|
||||
-- | Function name builder using the CamelCase convention.
|
||||
-- each part begins with an upper case character.
|
||||
camelCase :: FunctionName -> Text
|
||||
camelCase = view camelCaseL
|
||||
|
|
|
@ -13,8 +13,6 @@
|
|||
{-# LANGUAGE TypeOperators #-}
|
||||
{-# LANGUAGE UndecidableInstances #-}
|
||||
|
||||
-- | Generalizes all the data needed to make code generation work with
|
||||
-- arbitrary programming languages.
|
||||
module Servant.Foreign.Internal where
|
||||
|
||||
import Prelude ()
|
||||
|
@ -40,6 +38,9 @@ import Servant.API.Modifiers
|
|||
(RequiredArgument)
|
||||
import Servant.API.TypeLevel
|
||||
|
||||
-- | Canonical name of the endpoint, can be used to generate a function name.
|
||||
--
|
||||
-- You can use the functions in "Servant.Foreign.Inflections", like 'Servant.Foreign.Inflections.camelCase' to transform to `Text`.
|
||||
newtype FunctionName = FunctionName { unFunctionName :: [Text] }
|
||||
deriving (Data, Show, Eq, Semigroup, Monoid, Typeable)
|
||||
|
||||
|
|
Loading…
Reference in a new issue