Skip to content

Commit

Permalink
Improve Haddock documentation (#60)
Browse files Browse the repository at this point in the history
  • Loading branch information
chshersh authored and vrom911 committed Feb 26, 2019
1 parent 4d28c98 commit 05d0c23
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 10 deletions.
6 changes: 5 additions & 1 deletion elm-street.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ cabal-version: 2.0
name: elm-street
version: 0.0.0
synopsis: Crossing the road between Haskell and Elm
description: Crossing the road between Haskell and Elm
description:
`Elm-street` allows you to generate automatically derived from Haskell types
definitions of Elm data types, JSON encoders and decoders. This helps to avoid
writing and maintaining huge chunk of boilerplate code when developing full-stack
applications.
homepage: https://github.com/Holmusk/elm-street
bug-reports: https://github.com/Holmusk/elm-street/issues
license: MPL-2.0
Expand Down
2 changes: 1 addition & 1 deletion src/Elm/Aeson.hs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ elmStreetJsonOptions = defaultOptions
In order to use it with your type @MyType@ add the following deriving to your type:
@
deriving (Elm, ToJSON, FromJSON) via ElmStreet MyType
__deriving__ (Elm, ToJSON, FromJSON) __via__ ElmStreet MyType
@
-}
newtype ElmStreet a = ElmStreet
Expand Down
6 changes: 6 additions & 0 deletions src/Elm/Ast.hs
Original file line number Diff line number Diff line change
Expand Up @@ -23,34 +23,40 @@ import Data.List.NonEmpty (NonEmpty, toList)
import Data.Text (Text)


-- | Elm data type definition.
data ElmDefinition
= DefAlias !ElmAlias
| DefType !ElmType
| DefPrim !ElmPrim
deriving (Show)

-- | AST for @type alias@ in Elm.
data ElmAlias = ElmAlias
{ elmAliasName :: !Text -- ^ Name of the alias
, elmAliasFields :: !(NonEmpty ElmRecordField) -- ^ List of fields
, elmAliasIsNewtype :: !Bool -- ^ 'True' if Haskell type is a @newtype@
} deriving (Show)

-- | Single file of @type alias@.
data ElmRecordField = ElmRecordField
{ elmRecordFieldType :: !TypeRef
, elmRecordFieldName :: !Text
} deriving (Show)

-- | Wrapper for name of the type.
newtype TypeName = TypeName
{ unTypeName :: Text
} deriving (Show)

-- | AST for @type@ in Elm.
data ElmType = ElmType
{ elmTypeName :: !Text -- ^ Name of the data type
, elmTypeVars :: ![Text] -- ^ List of type variables; currently only phantom variables
, elmTypeIsNewtype :: !Bool -- ^ 'True' if Haskell type is a @newtype@
, elmTypeConstructors :: !(NonEmpty ElmConstructor) -- ^ List of constructors
} deriving (Show)

-- | Constructor of @type@.
data ElmConstructor = ElmConstructor
{ elmConstructorName :: !Text -- ^ Name of the constructor
, elmConstructorFields :: ![TypeRef] -- ^ Fields of the constructor
Expand Down
9 changes: 6 additions & 3 deletions src/Elm/Generate.hs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ module Elm.Generate
( Settings (..)
, defaultSettings
, generateElm

-- * Internal helpers
, RenderElm (..)
) where

import Data.Kind (Type)
Expand All @@ -28,7 +31,7 @@ import qualified Data.Text.IO as TIO

-- | Settings for outputting generated Elm code.
data Settings = Settings
{ settingsDirectory :: !FilePath -- ^ Directory to put generated files, e.g. @frontend/src@
{ settingsDirectory :: !FilePath -- ^ Directory to put generated files, e.g. @frontend\/src@
, settingsModule :: ![FilePath] -- ^ List of module parts, like @["ABC", "Core"]@
, settingsTypesFile :: !FilePath -- ^ File name for module with types, e.g. @Types@
, settingsEncoderFile :: !FilePath -- ^ File name for module with JSON encoders, e.g. @Encoder@
Expand Down Expand Up @@ -79,14 +82,14 @@ toElmDecoderSource = prettyShowDecoder $ toElmDefinition $ Proxy @a
to be called like this:
@
type Types =
__type__ Types =
'[ User
, UserStatus
, Measure
]
main :: IO ()
main = generateElm @Types $ defaultSettings "frontend/src/" ["ABC", "Core"]
main = generateElm @Types $ defaultSettings "frontend\/src\/" ["ABC", "Core"]
@
-}
generateElm :: forall (ts :: [Type]) . RenderElm ts => Settings -> IO ()
Expand Down
18 changes: 14 additions & 4 deletions src/Elm/Generic.hs
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,21 @@ module Elm.Generic
, GenericConstructor (..)
, toElmConstructor

-- * Internals
-- * Type families for compile-time checks
, HasNoTypeVars
, TypeVarsError

, HasLessThanEightUnnamedFields
, FieldsError
, CheckFields
, Max

, HasNoNamedSum
, TypeVarsError
, NamedSumError
, CheckNamedSum
, CheckConst

-- * Internals
, stripTypeNamePrefix
) where

Expand Down Expand Up @@ -141,9 +151,9 @@ instance Elm a => Elm (NonEmpty a) where
this:
@
newtype Id a = Id { unId :: Text }
__newtype__ Id a = Id { unId :: Text }
instance Elm (Id a) where
__instance__ Elm (Id a) __where__
toElmDefinition _ = elmNewtype @Text "Id" "unId"
@
-}
Expand Down
7 changes: 6 additions & 1 deletion src/Elm/Print.hs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ module Elm.Print
, decodeChar
, decodeEither
, decodePair

-- * Internal functions
, elmAliasDoc
, elmTypeDoc
) where

import Data.List.NonEmpty (NonEmpty ((:|)), toList)
Expand All @@ -36,7 +40,8 @@ import qualified Data.Text as T

{- | Pretty shows Elm types.
TODO: more docs later
* See 'elmAliasDoc' for examples of generated @type alias@.
* See 'elmTypeDoc' for examples of generated @type@.
-}
prettyShowDefinition :: ElmDefinition -> Text
prettyShowDefinition = showDoc . elmDoc
Expand Down

0 comments on commit 05d0c23

Please sign in to comment.