Add some parsing stuff to finished/ for Tag
This commit is contained in:
@@ -3,15 +3,12 @@ module Data.Article
|
||||
( Article
|
||||
, Body
|
||||
, Slug
|
||||
, Tag
|
||||
, bodyToHtml
|
||||
, bodyToMarkdownString
|
||||
, decoder
|
||||
, decoderWithBody
|
||||
, slugParser
|
||||
, slugToString
|
||||
, tagDecoder
|
||||
, tagToString
|
||||
)
|
||||
|
||||
import Data.Article.Author as Author exposing (Author)
|
||||
@@ -110,24 +107,6 @@ slugToString (Slug slug) =
|
||||
|
||||
|
||||
|
||||
-- TAGS --
|
||||
|
||||
|
||||
type Tag
|
||||
= Tag String
|
||||
|
||||
|
||||
tagToString : Tag -> String
|
||||
tagToString (Tag slug) =
|
||||
slug
|
||||
|
||||
|
||||
tagDecoder : Decoder Tag
|
||||
tagDecoder =
|
||||
Decode.map Tag Decode.string
|
||||
|
||||
|
||||
|
||||
-- BODY --
|
||||
|
||||
|
||||
|
||||
55
finished/src/Data/Article/Tag.elm
Normal file
55
finished/src/Data/Article/Tag.elm
Normal file
@@ -0,0 +1,55 @@
|
||||
module Data.Article.Tag
|
||||
exposing
|
||||
( Tag
|
||||
, decoder
|
||||
, encode
|
||||
, listParser
|
||||
, toString
|
||||
)
|
||||
|
||||
import Json.Decode as Decode exposing (Decoder)
|
||||
import Json.Encode as Encode exposing (Value)
|
||||
import Parser exposing ((|.), (|=), Parser, end, ignore, keep, oneOrMore, repeat, zeroOrMore)
|
||||
|
||||
|
||||
type Tag
|
||||
= Tag String
|
||||
|
||||
|
||||
toString : Tag -> String
|
||||
toString (Tag str) =
|
||||
str
|
||||
|
||||
|
||||
encode : Tag -> Value
|
||||
encode (Tag str) =
|
||||
Encode.string str
|
||||
|
||||
|
||||
decoder : Decoder Tag
|
||||
decoder =
|
||||
Decode.map Tag Decode.string
|
||||
|
||||
|
||||
listParser : Parser (List Tag)
|
||||
listParser =
|
||||
Parser.succeed (List.map Tag)
|
||||
|. ignore zeroOrMore isWhitespace
|
||||
|= repeat zeroOrMore tag
|
||||
|. end
|
||||
|
||||
|
||||
|
||||
-- INTERNAL --
|
||||
|
||||
|
||||
tag : Parser String
|
||||
tag =
|
||||
keep oneOrMore (\char -> not (isWhitespace char))
|
||||
|. ignore zeroOrMore isWhitespace
|
||||
|
||||
|
||||
isWhitespace : Char -> Bool
|
||||
isWhitespace char =
|
||||
-- Treat hashtags and commas as effectively whitespace; ignore them.
|
||||
char == '#' || char == ',' || char == ' '
|
||||
Reference in New Issue
Block a user