Created
December 4, 2015 22:09
-
-
Save codedmart/2324b80dcf9b9c641774 to your computer and use it in GitHub Desktop.
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
module Types.AspectRatio where | |
import Prelude | |
import Data.Generic | |
import Data.Argonaut ((~>), (.?), (:=), jsonEmptyObject) | |
import Data.Argonaut.Encode (EncodeJson, encodeJson) | |
import Data.Argonaut.Decode (DecodeJson, decodeJson) | |
type AspectRatio = | |
{ height :: Number | |
, width :: Number | |
} | |
newtype AspectRatioNT = AspectRatioNT | |
{ height :: Number | |
, width :: Number | |
} | |
instance decodeJsonAspectRatioNT :: DecodeJson AspectRatioNT where | |
decodeJson json = do | |
obj <- decodeJson json | |
height <- obj .? "height" | |
width <- obj .? "width" | |
pure $ AspectRatioNT | |
{ height: height | |
, width: width | |
} | |
instance encodeJsonAspectRatioNT :: EncodeJson AspectRatioNT where | |
encodeJson (AspectRatioNT a) | |
= "height" := a.height | |
~> "width" := a.width | |
~> jsonEmptyObject | |
runAspectRatio :: AspectRatioNT -> AspectRatio | |
runAspectRatio (AspectRatioNT a) = a |
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
in module Types.Upload | |
at /Users/bmartin/Work/lumi/lumi-flapjack/./purescript/src/Types/SvgData.purs line 41, column 1 - line 80, column 1 | |
No type class instance was found for | |
Data.Argonaut.Decode.DecodeJson { width :: Number | |
, height :: Number | |
} | |
in value declaration decodeJsonSvgDataNT |
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
module Types.Upload where | |
import Prelude | |
import Data.Maybe | |
import Data.StrMap (lookup) | |
import Data.Argonaut (Json(), (.?), (~>), (:=), jsonEmptyObject) | |
import Data.Argonaut.Encode (EncodeJson, encodeJson) | |
import Data.Argonaut.Decode (DecodeJson, decodeJson) | |
import Types.AspectRatio | |
import Common.Utils ((?.?)) | |
type SvgData = | |
{ aspectRatio :: AspectRatio | |
, mimeType :: String | |
, name :: String | |
, size :: Int | |
, title :: String | |
, uploadType :: String | |
, userId :: Maybe String | |
} | |
newtype SvgDataNT = SvgDataNT | |
{ aspectRatio :: AspectRatio | |
, mimeType :: String | |
, name :: String | |
, size :: Int | |
, title :: String | |
, uploadType :: String | |
, userId :: Maybe String | |
} | |
instance decodeJsonSvgDataNT :: DecodeJson SvgDataNT where | |
decodeJson json = do | |
obj <- decodeJson json | |
aspectRatio <- obj .? "aspectRatio" | |
mimeType <- obj .? "mimeType" | |
name <- obj .? "name" | |
size <- obj .? "size" | |
title <- obj .? "title" | |
uploadType <- obj .? "uploadType" | |
userId <- obj ?.? "userId" | |
pure $ SvgDataNT | |
{ aspectRatio: aspectRatio | |
, mimeType: mimeType | |
, name: name | |
, size: size | |
, title: title | |
, uploadType: uploadType | |
, userId: userId | |
} | |
instance encodeJsonSvgDataNT :: EncodeJson SvgDataNT where | |
encodeJson (SvgDataNT s) | |
= "aspectRatio" := aspectRatio | |
~> "mimeType" := s.mimeType | |
~> "name" := s.name | |
~> "size" := s.size | |
~> "title" := s.title | |
~> "uploadType" := s.uploadType | |
~> "userId" := s.userId | |
~> jsonEmptyObject | |
where | |
aspectRatio = encodeJson $ AspectRatioNT s.aspectRatio | |
runSvgData :: SvgDataNT -> SvgData | |
runSvgData (SvgDataNT s) = s |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment