Add part5
This commit is contained in:
35
advanced/part5/src/Article/Slug.elm
Normal file
35
advanced/part5/src/Article/Slug.elm
Normal file
@@ -0,0 +1,35 @@
|
||||
module Article.Slug exposing (Slug, decoder, toString, urlParser)
|
||||
|
||||
import Json.Decode as Decode exposing (Decoder)
|
||||
import Url.Parser exposing (Parser)
|
||||
|
||||
|
||||
|
||||
-- TYPES
|
||||
|
||||
|
||||
type Slug
|
||||
= Slug String
|
||||
|
||||
|
||||
|
||||
-- CREATE
|
||||
|
||||
|
||||
urlParser : Parser (Slug -> a) a
|
||||
urlParser =
|
||||
Url.Parser.custom "SLUG" (\str -> Just (Slug str))
|
||||
|
||||
|
||||
decoder : Decoder Slug
|
||||
decoder =
|
||||
Decode.map Slug Decode.string
|
||||
|
||||
|
||||
|
||||
-- TRANSFORM
|
||||
|
||||
|
||||
toString : Slug -> String
|
||||
toString (Slug str) =
|
||||
str
|
||||
Reference in New Issue
Block a user