-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from gbtb/dev
Dev
- Loading branch information
Showing
19 changed files
with
623 additions
and
7,554 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,41 @@ | ||
![](https://travis-ci.org/gbtb/elm-gen.svg?branch=master) | ||
![](https://travis-ci.org/gbtb/elm-gen.svg?branch=master) [![npm version](https://badge.fury.io/js/elm-gen.svg)](https://badge.fury.io/js/elm-gen) | ||
# elm-gen | ||
Experimental CLI tool for generating Elm JSON Decoders and Encoders, written mostly in Elm. | ||
Based on top of [elm-ast](https://github.com/Bogdanp/elm-ast) parsing library. | ||
|
||
## Usage | ||
|
||
### Online demo | ||
Simplified demonstration available [here](https://gbtb.github.io/elm-gen/). | ||
|
||
### CLI tool | ||
CLI tool can be obtained from [NPM](https://www.npmjs.com/package/elm-gen). After installation, you can used it like that: | ||
`elm-gen decoders&encoders Model.elm .` | ||
Also look at functional tests in ts/MainTests.ts and correspondent files in tests_data folder. | ||
Call above will produce new file ModelEncodersAndDecoders.elm, which will contain decoders and encoders for types present in Model.elm. | ||
Also note, that generated elm code for decoders uses NoRedInk elm-decode-pipeline package functions, so it must be installed into your project. | ||
For more examples you may also look at functional tests in ts/MainTests.ts and correspondent files in tests_data folder. | ||
## Features | ||
* elm-gen can generate decoders and/or encoders for user defined Record and Union types without type variables. | ||
* elm-gen supports basic elm types supported by Json.(Encode|Decode) plus tuples and Maybe's. | ||
* elm-gen can use hand-made decoders and encoders `Decoder X` and `X -> Value` in order to generate decoders for types, dependent on type `X` | ||
* elm-gen will follow **explicit** import type references to look for type definitions doesnot present in current file | ||
* elm-gen dont require to break your Elm code in any way (its still compilable by `elm-make` without pre-processing), except for some [meta-comments](#meta-comments) insertion. | ||
|
||
### Config | ||
Some configuration (mostly about naming) can be applied from config json-file. Example of config can be found in tests_data folder. | ||
It's correspondent Elm type representation resides in Config.elm | ||
|
||
### Meta-Comments | ||
Elm-gen supports meta-comments in source code, in form of either `-- //Meta-Comment` or `{-| //Meta-Comment -}`. | ||
For now, there are 3 meta-comments: | ||
For now, there are 4 meta-comments: | ||
|
||
* Ignore -- elm-gen completely ignores next type definition (literally skipping it during parse stage). | ||
|
||
* DefaultValue -- use next pair of (value type def, value expr) to produce default value for `Json.Decode.Pipeline.optional` function. | ||
Supports values of types `defaultValue: UnionType` for union types, and `defaultValue : Record ` or `defaultValue : Record -> Record` for record types. | ||
|
||
* NoDeclaration -- elm-gen won't generates type declaration for next type's decoder (usefull for preserving record structural typing ability for generated decoder ) | ||
|
||
* FieldNameMapping - TODO | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.