on master help sign in
Switched out MissingH for an implementation using split
21e9c9fGeoffrey Roberts
servant-jquery.cabal+3−3
@@ -32,10 +32,10 @@ library
32 exposed-modules: Servant.JQuery
32 exposed-modules: Servant.JQuery
33 other-modules: Servant.JQuery.Internal
33 other-modules: Servant.JQuery.Internal
34 build-depends: base >=4.5 && <5
34 build-depends: base >=4.5 && <5
35− , servant >= 0.2.1
36− , lens >= 4
37− , MissingH
38 , charset
35 , charset
36+ , lens >= 4
37+ , servant >= 0.2.1
38+ , split
39 hs-source-dirs: src
39 hs-source-dirs: src
40 default-language: Haskell2010
40 default-language: Haskell2010
41 ghc-options: -Wall
41 ghc-options: -Wall
src/Servant/JQuery/Internal.hs+7−4
@@ -12,9 +12,9 @@ import Data.Char (toLower)
12import qualified Data.CharSet as Set
12import qualified Data.CharSet as Set
13import qualified Data.CharSet.Unicode.Category as Set
13import qualified Data.CharSet.Unicode.Category as Set
14import Data.List
14import Data.List
15+import Data.List.Split
15import Data.Monoid
16import Data.Monoid
16import Data.Proxy
17import Data.Proxy
17−import Data.String.Utils
18import GHC.TypeLits
18import GHC.TypeLits
19import Servant.API
19import Servant.API
20
20
@@ -68,14 +68,17 @@ data HeaderArg = HeaderArg
68instance Show HeaderArg where
68instance Show HeaderArg where
69 show (HeaderArg n) = toValidFunctionName ("header" <> n)
69 show (HeaderArg n) = toValidFunctionName ("header" <> n)
70 show (ReplaceHeaderArg n p)
70 show (ReplaceHeaderArg n p)
71− | pn `startswith` p = pv <> " + \"" <> rp <> "\""
71+ | pn `isPrefixOf` p = pv <> " + \"" <> rp <> "\""
72− | pn `endswith` p = "\"" <> rp <> "\" + " <> pv
72+ | pn `isSuffixOf` p = "\"" <> rp <> "\" + " <> pv
73− | pn `isInfixOf` p = "\"" <> (replace pn ("\" + " <> pv <> " + \"") p) <> "\""
73+ | pn `isInfixOf` p = "\"" <> (replace pn ("\" + " <> pv <> " + \"") p)
74+ <> "\""
74 | otherwise = p
75 | otherwise = p
75 where
76 where
76 pv = toValidFunctionName ("header" <> n)
77 pv = toValidFunctionName ("header" <> n)
77 pn = "{" <> n <> "}"
78 pn = "{" <> n <> "}"
78 rp = replace pn "" p
79 rp = replace pn "" p
80+ -- Nicked from Data.String.Utils, works on lists
81+ replace old new l = intercalate new . splitOn old $ l
79
82
80-- | Attempts to reduce the function name provided to that allowed by JS.
83-- | Attempts to reduce the function name provided to that allowed by JS.
81-- https://mathiasbynens.be/notes/javascript-identifiers
84-- https://mathiasbynens.be/notes/javascript-identifiers