lettenj61 / elm-simple-template / Template.Params

Params is some "newtype" wrapper of Dict String String, designed to be used especially for rendering templates.

You usually don't need to use functions defined here directly except when getting Params value with fromDict or fromList.

Params


type Params

A set of parameters for template function.

Construction

fromDict : Dict String String -> Params

Wrap a Dict into Params.

params =
    fromDict <|
        Dict.fromList
            [ ( "css", "Cascading Style Sheet" )
            , ( "html", "Hyper Text Markup Language" )
            ]

fromList : List ( String, String ) -> Params

Create Params by converting given List.

params =
    fromList
        [ ( "domain", "web development" )
        , ( "type", "static" )
        ]

Interpolate

interpolate : String -> String -> Params -> String

Takes key and default value, returns associated value if one is found. Otherwise returns default value.

params =
    fromList
        [ ( "database", "MySQL" )
        , ( "protocol", "HTTPS" )
        ]

params |> interpolate "protocol" "???"      -- => "HTTPS"
params |> interpolate "size" "NOT FOUND"    -- => "NOT FOUND"

Query

get : String -> Params -> Maybe String

Try to get a value associated with given key from Params.