packages feed

elm-bridge 0.2.2.1 → 0.3.0.0

raw patch · 5 files changed

+74/−17 lines, 5 files

Files

CHANGELOG.md view
@@ -1,3 +1,7 @@+# v0.3.0+## New features+ * Support for Elm 0.17+ # v0.2.2  ## New features
elm-bridge.cabal view
@@ -1,5 +1,5 @@ name:                elm-bridge-version:             0.2.2.1+version:             0.3.0.0 synopsis:            Derive Elm types from Haskell types description:         Building the bridge from Haskell to Elm and back. Define types once,                      use on both sides and enjoy easy (de)serialisation. Cheers!@@ -28,6 +28,7 @@                        Elm.Module                        Elm.TyRender                        Elm.TyRep+                       Elm.Versions   other-modules:       Elm.Utils   build-depends:       base >= 4.7 && < 5,                        template-haskell,
src/Elm/Module.hs view
@@ -13,18 +13,28 @@ import Elm.TyRep import Elm.TyRender import Elm.Json+import Elm.Versions  -- | Existential quantification wrapper for lists of type definitions data DefineElm    = forall a. IsElmDefinition a => DefineElm (Proxy a) --- | Creates an Elm module. This will use the default type conversion rules (to--- convert @Vector@ to @List@, @HashMap a b@ to @List (a,b)@, etc.).-makeElmModule :: String -- ^ Module name-              -> [DefineElm] -- ^ List of definitions to be included in the module-              -> String-makeElmModule moduleName defs = unlines (-    [ "module " ++ moduleName ++ " where"+-- | The module header line for this version of Elm+moduleHeader :: ElmVersion+             -> String+             -> String+moduleHeader Elm0p16 moduleName = "module " ++ moduleName ++ " where"+moduleHeader Elm0p17 moduleName = "module " ++ moduleName ++ " exposing(..)"++-- | Creates an Elm module for the given version. This will use the default+-- type conversion rules (to -- convert @Vector@ to @List@, @HashMap a b@+-- to @List (a,b)@, etc.).+makeElmModuleWithVersion :: ElmVersion +                         -> String  -- ^ Module name+                         -> [DefineElm]  -- ^ List of definitions to be included in the module+                         -> String+makeElmModuleWithVersion elmVersion moduleName defs = unlines (+    [ moduleHeader elmVersion moduleName     , ""     , "import Json.Decode"     , "import Json.Decode exposing ((:=))"@@ -37,6 +47,12 @@     , ""     ]) ++ makeModuleContent defs +-- | Creates an Elm module. This will use the default type conversion rules (to+-- convert @Vector@ to @List@, @HashMap a b@ to @List (a,b)@, etc.).+makeElmModule :: String -- ^ Module name+              -> [DefineElm] -- ^ List of definitions to be included in the module+              -> String+makeElmModule = makeElmModuleWithVersion Elm0p16  -- | Generates the content of a module. You will be responsible for -- including the required Elm headers. This uses the default type
+ src/Elm/Versions.hs view
@@ -0,0 +1,7 @@+{-| A type to represent versions of Elm for produced code to work against+-}+module Elm.Versions where++data ElmVersion+  = Elm0p16+  | Elm0p17
test/Elm/ModuleSpec.hs view
@@ -3,6 +3,7 @@  import Elm.Derive import Elm.Module+import Elm.Versions   import Data.Map (Map)@@ -25,9 +26,13 @@ $(deriveElmDef (defaultOptionsDropLower 2) ''Bar) $(deriveElmDef (defaultOptionsDropLower 5) ''Qux) -moduleCode :: String-moduleCode = unlines-    [ "module Foo where"+moduleHeader' :: ElmVersion -> String -> String+moduleHeader' Elm0p16 name = "module " ++ name ++ " where"+moduleHeader' Elm0p17 name = "module " ++ name ++ " exposing(..)"++moduleCode :: ElmVersion -> String+moduleCode elmVersion = unlines+    [ moduleHeader' elmVersion "Foo"     , ""     , "import Json.Decode"     , "import Json.Decode exposing ((:=))"@@ -67,9 +72,9 @@     , ""     ] -moduleCode' :: String-moduleCode' = unlines-    [ "module Qux where"+moduleCode' :: ElmVersion -> String+moduleCode' elmVersion = unlines+    [ moduleHeader' elmVersion "Qux"     , ""     , "import Json.Decode"     , "import Json.Decode exposing ((:=))"@@ -102,10 +107,34 @@     ]  spec :: Spec-spec =+spec = do+  makeElmModuleSpec+  version0p16Spec+  version0p17Spec++makeElmModuleSpec :: Spec+makeElmModuleSpec =     describe "makeElmModule" $     it "should produce the correct code" $        do let modu = makeElmModule "Foo" [DefineElm (Proxy :: Proxy (Bar a))]           let modu' = makeElmModule "Qux" [DefineElm (Proxy :: Proxy (Qux a))]-          modu `shouldBe` moduleCode-          modu' `shouldBe` moduleCode'+          modu `shouldBe` (moduleCode Elm0p16)+          modu' `shouldBe` (moduleCode' Elm0p16)++version0p16Spec :: Spec+version0p16Spec =+  describe "makeElmModuleWithVersion Elm0p16" $+    it "should produce the correct code" $+       do let modu = makeElmModuleWithVersion Elm0p16 "Foo" [DefineElm (Proxy :: Proxy (Bar a))]+          let modu' = makeElmModuleWithVersion Elm0p16 "Qux" [DefineElm (Proxy :: Proxy (Qux a))]+          modu `shouldBe` (moduleCode Elm0p16)+          modu' `shouldBe` (moduleCode' Elm0p16)++version0p17Spec :: Spec+version0p17Spec =+  describe "makeElmModuleWithVersion Elm0p17" $+    it "should produce the correct code" $+       do let modu = makeElmModuleWithVersion Elm0p17 "Foo" [DefineElm (Proxy :: Proxy (Bar a))]+          let modu' = makeElmModuleWithVersion Elm0p17 "Qux" [DefineElm (Proxy :: Proxy (Qux a))]+          modu `shouldBe` (moduleCode Elm0p17)+          modu' `shouldBe` (moduleCode' Elm0p17)