Skip to content

Commit c2b8a7c

Browse files
authored
use toSlug from slugger package instead of our own implementation (#2153)
* use toSlug from slugger package instead of our own implementation * remove toSlug tests
1 parent ff63977 commit c2b8a7c

File tree

3 files changed

+4
-24
lines changed

3 files changed

+4
-24
lines changed

ihp/IHP/NameSupport.hs

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import Control.Monad (join)
3333
import qualified Text.Inflections
3434
import qualified Data.Text as Text
3535
import Text.Countable (singularize, pluralize)
36+
import qualified Data.Text.Slugger
3637

3738
-- | Transforms a underscore table name to a camel case model name.
3839
--
@@ -245,17 +246,7 @@ haskellKeywords = [ "_"
245246
-- >>> toSlug "Hallo! @ Welt"
246247
-- "hallo-welt"
247248
toSlug :: Text -> Text
248-
toSlug text =
249-
text
250-
|> Text.toLower
251-
|> Text.map replaceChar
252-
|> Text.words
253-
|> Text.intercalate "-"
254-
where
255-
replaceChar 'ä' = 'a'
256-
replaceChar 'ö' = 'o'
257-
replaceChar 'ü' = 'u'
258-
replaceChar char = if Char.isAlphaNum char && Char.isAscii char then char else ' '
249+
toSlug text = Data.Text.Slugger.toSlug text
259250

260251

261252
-- | Transform a data-field name like @userName@ to a friendly human-readable name like @User name@

ihp/Test/NameSupportSpec.hs

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -113,16 +113,4 @@ tests = do
113113
escapeHaskellKeyword "DATA" `shouldBe` "DATA_"
114114

115115
it "should ignore non-haskell keywords" do
116-
escapeHaskellKeyword "hello" `shouldBe` "hello"
117-
118-
describe "toSlug" do
119-
it "should deal with empty input" do
120-
toSlug "" `shouldBe` ""
121-
122-
it "should make a slug string from a string" do
123-
toSlug "IHP Release: 21.08.2020 (v21082020)" `shouldBe` "ihp-release-21-08-2020-v21082020"
124-
toSlug "Hallo! @ Welt" `shouldBe` "hallo-welt"
125-
126-
it "should deal with umlaute" do
127-
toSlug "käuferpass" `shouldBe` "kauferpass"
128-
toSlug "äöüß" `shouldBe` "aou"
116+
escapeHaskellKeyword "hello" `shouldBe` "hello"

ihp/ihp.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ common shared-properties
136136
, stm
137137
, wai-asset-path
138138
, wai-flash-messages
139+
, slugger
139140
default-extensions:
140141
OverloadedStrings
141142
, NoImplicitPrelude

0 commit comments

Comments
 (0)