This module provides some functions for scaffolding code for a new Route Module. It uses elm-codegen
's API for generating code.
Typically you'll want to use this via the elm-pages run
CLI command. The default starter template includes a Script that uses these functions, which you can tweak to customize your scaffolding commands.
Learn more about writing and running elm-pages Scripts for scaffolding.
It's typically easiest to modify the AddRoute
script from the starter template and adjust it to your needs rather than writing one from scratch.
These functions mirror the RouteBuilder
API that you use in your Route modules to define your route. The difference is that
instead of defining a route, this is defining a code generator for a Route module.
buildWithLocalState : { view : { shared : Elm.Expression, model : Elm.Expression, app : Elm.Expression } -> Elm.Expression, update : { shared : Elm.Expression, app : Elm.Expression, msg : Elm.Expression, model : Elm.Expression } -> Elm.Expression, init : { shared : Elm.Expression, app : Elm.Expression } -> Elm.Expression, subscriptions : { routeParams : Elm.Expression, path : Elm.Expression, shared : Elm.Expression, model : Elm.Expression } -> Elm.Expression, msg : Type, model : Type } -> Builder -> { path : String, body : String }
buildWithSharedState : { view : { shared : Elm.Expression, model : Elm.Expression, app : Elm.Expression } -> Elm.Expression, update : { shared : Elm.Expression, app : Elm.Expression, msg : Elm.Expression, model : Elm.Expression } -> Elm.Expression, init : { shared : Elm.Expression, app : Elm.Expression } -> Elm.Expression, subscriptions : { routeParams : Elm.Expression, path : Elm.Expression, shared : Elm.Expression, model : Elm.Expression } -> Elm.Expression, msg : Type, model : Type } -> Builder -> { path : String, body : String }
buildNoState : { view : { shared : Elm.Expression, app : Elm.Expression } -> Elm.Expression } -> Builder -> { path : String, body : String }
serverRender : { data : ( Type, Elm.Expression -> Elm.Expression -> Elm.Expression ), action : ( Type, Elm.Expression -> Elm.Expression -> Elm.Expression ), head : Elm.Expression -> Elm.Expression, moduleName : List String } -> Builder
preRender : { data : ( Type, Elm.Expression -> Elm.Expression ), pages : Elm.Expression, head : Elm.Expression -> Elm.Expression, moduleName : List String } -> Builder
single : { data : ( Type, Elm.Expression ), head : Elm.Expression -> Elm.Expression, moduleName : List String } -> Builder
addDeclarations : List Elm.Declaration -> Builder -> Builder
The helpers in this module help you generate a Route module file with the core boilerplate abstracted away.
You can also define additional top-level declarations in the generated Route module using this helper.
moduleNameCliArg : Cli.Option.Option from String builderState -> Cli.Option.Option from (List String) builderState
A positional argument for elm-cli-options-parser that does a Regex validation to check that the module name is a valid Elm Route module name.