2015-08-09 19:43:46 +03:00
Elm Bridge
=====
[![Build Status ](https://travis-ci.org/agrafix/elm-bridge.svg )](https://travis-ci.org/agrafix/elm-bridge)
[![Hackage Deps ](https://img.shields.io/hackage-deps/v/elm-bridge.svg )](http://packdeps.haskellers.com/reverse/elm-bridge)
## Intro
Hackage: [elm-bridge ](http://hackage.haskell.org/package/elm-bridge )
Building the bridge from [Haskell ](http://haskell.org ) to [Elm ](http://elm-lang.org ) and back. Define types once, use on both sides and enjoy easy (de)serialisation. Cheers!
## Usage
```haskell
{-# LANGUAGE TemplateHaskell #-}
import Elm.Derive
2015-08-09 23:46:02 +03:00
import Elm.Module
2015-08-09 19:43:46 +03:00
import Data.Proxy
data Foo
= Foo
{ f_name :: String
, f_blablub :: Int
} deriving (Show, Eq)
2015-08-09 23:46:02 +03:00
deriveElmDef defaultOpts ''Foo
2015-08-09 19:43:46 +03:00
main :: IO ()
main =
2015-08-09 23:46:02 +03:00
putStrLn $ makeElmModule "Foo"
[ DefineElm (Proxy :: Proxy Foo)
]
2015-08-09 19:43:46 +03:00
```
Output will be:
```elm
2015-08-09 23:46:02 +03:00
module Foo where
import Json.Decode
import Json.Decode exposing ((:=))
import Json.Encode
type alias Foo =
{ f_name: String
, f_blablub: Int
}
jsonDecFoo =
("f_name" := Json.Decode.string) `Json.Decode.andThen` \pf_name ->
("f_blablub" := Json.Decode.int) `Json.Decode.andThen` \pf_blablub ->
Json.Decode.succeed {f_name = pf_name, f_blablub = pf_blablub}
jsonEncFoo val =
Json.Encode.object
[ ("f_name", Json.Encode.string val.f_name)
, ("f_blablub", Json.Encode.int val.f_blablub)
]
2015-08-09 19:43:46 +03:00
```
For more usage examples check the tests.
## Install
* Using cabal: `cabal install elm-bridge`
* From Source: `git clone https://github.com/agrafix/elm-bridge.git && cd elm-bridge && cabal install`