Switched out MissingH for an implementation using split

This commit is contained in:
Geoffrey Roberts 2015-01-22 11:24:36 +11:00
parent 745dbd09a9
commit 21e9c9f5c9
2 changed files with 10 additions and 7 deletions

View file

@ -32,10 +32,10 @@ library
exposed-modules: Servant.JQuery exposed-modules: Servant.JQuery
other-modules: Servant.JQuery.Internal other-modules: Servant.JQuery.Internal
build-depends: base >=4.5 && <5 build-depends: base >=4.5 && <5
, servant >= 0.2.1
, lens >= 4
, MissingH
, charset , charset
, lens >= 4
, servant >= 0.2.1
, split
hs-source-dirs: src hs-source-dirs: src
default-language: Haskell2010 default-language: Haskell2010
ghc-options: -Wall ghc-options: -Wall

View file

@ -12,9 +12,9 @@ import Data.Char (toLower)
import qualified Data.CharSet as Set import qualified Data.CharSet as Set
import qualified Data.CharSet.Unicode.Category as Set import qualified Data.CharSet.Unicode.Category as Set
import Data.List import Data.List
import Data.List.Split
import Data.Monoid import Data.Monoid
import Data.Proxy import Data.Proxy
import Data.String.Utils
import GHC.TypeLits import GHC.TypeLits
import Servant.API import Servant.API
@ -68,14 +68,17 @@ data HeaderArg = HeaderArg
instance Show HeaderArg where instance Show HeaderArg where
show (HeaderArg n) = toValidFunctionName ("header" <> n) show (HeaderArg n) = toValidFunctionName ("header" <> n)
show (ReplaceHeaderArg n p) show (ReplaceHeaderArg n p)
| pn `startswith` p = pv <> " + \"" <> rp <> "\"" | pn `isPrefixOf` p = pv <> " + \"" <> rp <> "\""
| pn `endswith` p = "\"" <> rp <> "\" + " <> pv | pn `isSuffixOf` p = "\"" <> rp <> "\" + " <> pv
| pn `isInfixOf` p = "\"" <> (replace pn ("\" + " <> pv <> " + \"") p) <> "\"" | pn `isInfixOf` p = "\"" <> (replace pn ("\" + " <> pv <> " + \"") p)
<> "\""
| otherwise = p | otherwise = p
where where
pv = toValidFunctionName ("header" <> n) pv = toValidFunctionName ("header" <> n)
pn = "{" <> n <> "}" pn = "{" <> n <> "}"
rp = replace pn "" p rp = replace pn "" p
-- Nicked from Data.String.Utils, works on lists
replace old new l = intercalate new . splitOn old $ l
-- | Attempts to reduce the function name provided to that allowed by JS. -- | Attempts to reduce the function name provided to that allowed by JS.
-- https://mathiasbynens.be/notes/javascript-identifiers -- https://mathiasbynens.be/notes/javascript-identifiers