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
other-modules: Servant.JQuery.Internal
build-depends: base >=4.5 && <5
, servant >= 0.2.1
, lens >= 4
, MissingH
, charset
, lens >= 4
, servant >= 0.2.1
, split
hs-source-dirs: src
default-language: Haskell2010
ghc-options: -Wall

View file

@ -12,9 +12,9 @@ import Data.Char (toLower)
import qualified Data.CharSet as Set
import qualified Data.CharSet.Unicode.Category as Set
import Data.List
import Data.List.Split
import Data.Monoid
import Data.Proxy
import Data.String.Utils
import GHC.TypeLits
import Servant.API
@ -68,14 +68,17 @@ data HeaderArg = HeaderArg
instance Show HeaderArg where
show (HeaderArg n) = toValidFunctionName ("header" <> n)
show (ReplaceHeaderArg n p)
| pn `startswith` p = pv <> " + \"" <> rp <> "\""
| pn `endswith` p = "\"" <> rp <> "\" + " <> pv
| pn `isInfixOf` p = "\"" <> (replace pn ("\" + " <> pv <> " + \"") p) <> "\""
| pn `isPrefixOf` p = pv <> " + \"" <> rp <> "\""
| pn `isSuffixOf` p = "\"" <> rp <> "\" + " <> pv
| pn `isInfixOf` p = "\"" <> (replace pn ("\" + " <> pv <> " + \"") p)
<> "\""
| otherwise = p
where
pv = toValidFunctionName ("header" <> n)
pn = "{" <> n <> "}"
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.
-- https://mathiasbynens.be/notes/javascript-identifiers