Orasund/elm-handlebars/1.0.1

NOTE: the latest version is 1.0.2

Handlebars.Path

Paths let you navigate through values.

type alias Path =
List String

A Path is list of strings

type alias RelativePath =
( Int, List String )

Relative paths can go backwards.

First argument states how many layers to go back.

relativeToString : RelativePath -> String
(0,[])
    |> relativeToString
    --> "."


(1,[])
    |> relativeToString
    --> "../."


(0,["a"])
    |> relativeToString
    --> "a"


(-1,["a"])
    |> relativeToString
    --> "a"


(1,["a"])
    |> relativeToString
    --> "../a"


(2,[])
    |> relativeToString
    --> "../../."


(0,["a", "b"])
    |> relativeToString
    --> "a.b"


(1,["a", "b"])
    |> relativeToString
    --> "../a.b"
toString : Path -> String
list : List String
list =
    ["people","Jack"]


list
    |> toString
    --> relativeToString (0,list)
withRelativePath : RelativePath -> Path -> Maybe Path

Turns relative path to path

[ "people", "jack"]
    |> withRelativePath (-1,[])
    --> Nothing


[ "people", "jack"]
    |> withRelativePath (0,[])
    --> Just ["people","jack"]


[ "people","jack"]
    |> withRelativePath (1,[ "gill"])
    --> Just ["people","gill"]


[ "people","jack" ]
    |> withRelativePath (2,[ "cities" ])
    --> Just [ "cities"]




[ "people","jack"]
    |> withRelativePath (3,[])
    --> Nothing