Add some codecs.

This commit is contained in:
Dillon Kearns 2021-06-17 09:57:33 -07:00
parent 2fe09bb0eb
commit 432587ba05
4 changed files with 76 additions and 1 deletions

View File

@ -9,6 +9,7 @@
"elm-version": "0.19.1",
"dependencies": {
"direct": {
"MartinSStewart/elm-serialize": "1.2.5",
"avh4/elm-color": "1.0.0",
"danyx23/elm-mimetype": "4.0.1",
"dillonkearns/elm-bcp47-language-tag": "1.0.1",
@ -36,7 +37,9 @@
"zwilias/json-decode-exploration": "6.0.0"
},
"indirect": {
"bburdette/toop": "1.0.1",
"billstclair/elm-xml-eeue56": "2.0.0",
"danfishgold/base64-bytes": "1.1.0",
"dmy/elm-imf-date-time": "1.0.1",
"elm/bytes": "1.0.8",
"elm/file": "1.0.5",

View File

@ -1,5 +1,6 @@
module DocsSection exposing (Section, all)
module DocsSection exposing (Section, all, codec)
import Codec exposing (Codec)
import DataSource exposing (DataSource)
import DataSource.Glob as Glob
@ -11,6 +12,16 @@ type alias Section =
}
codec : Codec (List Section)
codec =
Codec.object Section
|> Codec.field "filePath" .filePath Codec.string
|> Codec.field "order" .order Codec.int
|> Codec.field "slug" .slug Codec.string
|> Codec.buildObject
|> Codec.list
all : DataSource (List Section)
all =
Glob.succeed Section

View File

@ -3,6 +3,7 @@ module NextPrevious exposing (..)
import Css
import Html.Styled exposing (..)
import Html.Styled.Attributes as Attr exposing (css)
import Serialize as S
import Svg.Styled exposing (path, svg)
import Svg.Styled.Attributes as SvgAttr
import Tailwind.Utilities as Tw
@ -12,6 +13,14 @@ type alias Item =
{ title : String, url : String }
serialize : S.Codec Never { title : String, url : String }
serialize =
S.record Item
|> S.field .title S.string
|> S.field .url S.string
|> S.finishRecord
view : ( Maybe Item, Maybe Item ) -> Html msg
view ( maybeLeft, maybeRight ) =
div

View File

@ -1,5 +1,6 @@
module TableOfContents exposing (..)
import Codec exposing (Codec)
import Css
import DataSource exposing (DataSource)
import DataSource.File
@ -9,6 +10,7 @@ import List.Extra
import Markdown.Block as Block exposing (Block, Inline)
import Markdown.Parser
import OptimizedDecoder
import Serialize as S
import Tailwind.Breakpoints as Bp
import Tailwind.Utilities as Tw
@ -32,6 +34,56 @@ dataSource docFiles =
|> DataSource.map List.reverse
codec : Codec (TableOfContents Data)
codec =
Codec.list entryCodec
entryCodec : Codec (Entry Data)
entryCodec =
Codec.custom
(\vEntry value ->
case value of
Entry data list ->
vEntry data list
)
|> Codec.variant2 "Entry" Entry dataCodec (Codec.list (Codec.lazy (\() -> entryCodec)))
|> Codec.buildCustom
dataCodec : Codec Data
dataCodec =
Codec.object Data
|> Codec.field "anchorId" .anchorId Codec.string
|> Codec.field "name" .name Codec.string
|> Codec.field "level" .level Codec.int
|> Codec.buildObject
serialize : S.Codec e (TableOfContents Data)
serialize =
S.list serializeEntry
serializeEntry =
S.customType
(\vEntry value ->
case value of
Entry data list ->
vEntry data list
)
|> S.variant2 Entry serializeData (S.list (S.lazy (\() -> serializeEntry)))
|> S.finishCustomType
serializeData =
S.record Data
|> S.field .anchorId S.string
|> S.field .name S.string
|> S.field .level S.int
|> S.finishRecord
headingsDecoder : String -> String -> DataSource (Entry Data)
headingsDecoder slug rawBody =
rawBody