Skip to content

Commit

Permalink
Merge pull request #9 from MaybeJustJames/prepare-release-1-0-0
Browse files Browse the repository at this point in the history
Prepare release v1.0.0
  • Loading branch information
MaybeJustJames committed Jul 16, 2020
2 parents 45d564c + 73c008e commit c69e59f
Show file tree
Hide file tree
Showing 4 changed files with 362 additions and 95 deletions.
81 changes: 61 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,26 @@
# YAML in Elm

This package helps you convert between Elm values and YAML values.
Convert between type-safe Elm values and [YAML](https://yaml.org).

## Example
This is forked from [terezka/yaml](https://package.elm-lang.org/packages/terezka/yaml/latest/).

## Install

```bash
$ elm install MaybeJustJames/yaml
```

and import the library in an elm file like this

```elm
import Yaml.Decode -- for decoders
```

## Documentation

Find the documentation on [Elm's package website](http://package.elm-lang.org/packages/MaybeJustJames/yaml/latest).

## Example Usage

Say you have some YAML which looks like this:

Expand All @@ -12,46 +30,69 @@ Say you have some YAML which looks like this:
first: Marie
last: Curie
occupation: [ chemist, physicist ]
nationality: Polish
age: 66
children: [ Irène, Ève ]
- name:
first: Alva
last: Myrdal
occupation: [ sociologist, diplomat, politician ]
nationality: Swedish
age: 84
children: []
- name:
first: Svetlana
last: Alexievich
occupation: [ journalist, historian ]
nationality: Belarusian
age: 72
children: []
...
```

to decode this, you could write

```elm
module Woman exposing (Woman, decoder)

import Yaml.Decode
import Yaml.Decode (..)

type alias Woman =
{ firstName : String
, lastName : String
{ name : String
, occupation : List String
, nationality : String
, age : Int
, children : Int -- number of children
}

decoder : Yaml.Decode.Decoder Woman
decoder : Decoder Woman
decoder =
Yaml.Decode.map4 Woman
(Yaml.Decode.at [ "name", "first" ] Yaml.Decode.string)
(Yaml.Decode.at [ "name", "last" ] Yaml.Decode.string)
(Yaml.Decode.field "occupation" (Yaml.Decode.list Yaml.Decode.string))
(Yaml.Decode.field "nationality" Yaml.Decode.string)
map4 Woman
(map2 (\first last -> first ++ " " ++ last)
(at ["name", "first"] string)
(at ["name", "last"] string))
(field "occupation" (list string))
(field "age" int)
(map List.length (field "children" (list string)))


fromString
(list decoder)
yamlString -- The string containing the YAML example above

```

and run your decoder with `Yaml.Decode.fromString (Yaml.Decode.list Woman.decoder) yamlString`!
## Development

The branch `parser-logging` contains a version of the
[parser logger](https://discourse.elm-lang.org/t/improved-parser-logger/5964)
by @Janiczek.

This, along with writing detailed tests using [elm-test](https://github.com/elm-community/elm-test)
is how I've been developing this package.

Please feel encouraged and welcome to submit bugs, PRs, etc.


## Major Missing Features

- `Yaml.Encode` to encode Elm values into YAML.
- Testing against the official [YAML test suite](https://github.com/yaml/yaml-test-suite).

## Work in progress
## Copying

This package was build to be able to parse data like [this](https://github.com/unitedstates/congress-legislators/blob/master/legislators-current.yaml), and even if it has a few more features (multiline strings, comments) than necessary to parse that file, YAML is a large and complex format, and this parser is still missing a lot of YAML features like references and various logical operations. It is also missing `Yaml.Encode`!
You are free to copy, modify, and distribute this package with attribution under the terms of the MIT license. See the [LICENSE](LICENSE) file for details.
6 changes: 3 additions & 3 deletions elm.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"type": "package",
"name": "terezka/yaml",
"summary": "A library for parsing and decoding YAML.",
"name": "MaybeJustJames/yaml",
"summary": "Work with YAML in Elm",
"license": "BSD-3-Clause",
"version": "1.0.1",
"version": "1.0.0",
"exposed-modules": [
"Yaml.Decode"
],
Expand Down

0 comments on commit c69e59f

Please sign in to comment.