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
Will scaffold using RouteBuilder.preRender
if there are any dynamic segments (as in Company.Team.Name_
),
or using RouteBuilder.single
if there are no dynamic segments (as in Company.AboutUs
).
When there are no dynamic segments, the pages
field will be ignored as it is only relevant for Routes with dynamic segments.
For dynamic segments, the routeParams
parameter in the data
function will be an Elm.Expression
with the RouteParams
parameter in the data
function.
For static segments, it will be a hardcoded empty record ({}
).
single : { data : ( Type, Elm.Expression ), head : Elm.Expression -> Elm.Expression, moduleName : List String } -> Builder
@depreacted. This is obsolete and will be removed in a future release. Use preRender
instead.
If you pass in only static route segments as the moduleName
to preRender
it will yield the same result as single
.
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.