compiles Handlebars templates.
Possible error are either syntactical or semantical.
parses the template and then evaluates it.
compile config string json =
parse string
|> Result.mapError SyntaxError
|> Result.andThen
(\expressions ->
eval config expressions json
|> Result.mapError SemanticError
)Tests:
import Parser
import Handlebars.Expression as Expression exposing (Expression(..), SubExp(..))
import Result.Extra as Result
import Handlebars
import Json.Decode as D
compile : String -> String -> (Result Error String)
compile template value =
case value |> D.decodeString D.value of
Ok v ->
v
|> Handlebars.compile Handlebars.defaultConfig
template
Err err -> Ok (D.errorToString err)
"{ \"valid\":true }"
|> compile "Hello There"
--> (Ok "Hello There")the default config.
Print the error in a nice and readable way.
parse a string into a template
Template