aboutsummaryrefslogtreecommitdiffstats
path: root/style-generator/src/MyElm/Advanced.elm
blob: 7f88ab224eaab5a59bb855ad3495f2e7e8bca01c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
module MyElm.Advanced exposing (aliasedName, exposedName, cheat)

{-| This module allows you to mess with some of the the little things at the cost of a more verbose API.

@docs aliasedName, exposedName, cheat

-}

import MyElm.Types exposing (Expression(..), Ident(..), QualifiedName(..))


{-| Specify a name using a module Alias. If it is a constructor, you must specify the type name as well.
-}
aliasedName :
    { modulePath : List String
    , aliasName : String
    , name : String
    , typeName : Maybe String
    }
    -> QualifiedName
aliasedName opts =
    case opts.typeName of
        Just tpn ->
            Aliased opts.modulePath opts.aliasName (Constructor tpn opts.name)

        Nothing ->
            Aliased opts.modulePath opts.aliasName (ValueOrType opts.name)


{-| Import a name and expose it.
-}
exposedName : List String -> String -> QualifiedName
exposedName modulePath name =
    Bare modulePath (ValueOrType name)


{-| Sometimes it is easier to just include a string of Elm code rather than build it up.

This function will allow you to do that. However, using this breaks the guarantee that the
generated Elm code will be valid. You should be careful to take into consideration things like
brackets in the context where you will use this expression.

-}
cheat : String -> Expression
cheat =
    Literal