mirror of
https://github.com/ryan-haskell/elm-spa.git
synced 2024-11-26 03:08:02 +03:00
recursive dynamic routes work, with a function that doesnt exist 😅
This commit is contained in:
parent
3fccf3dbe1
commit
07baa8d18d
@ -5,8 +5,8 @@ module Generated.Docs.Pages exposing
|
||||
)
|
||||
|
||||
import App.Page
|
||||
import Generated.Docs.Flags as Flags
|
||||
import Generated.Docs.Routes as Routes exposing (Route(..))
|
||||
import Generated.Docs.Params as Params
|
||||
import Generated.Docs.Route as Route exposing (Route(..))
|
||||
import Layouts.Docs as Layout
|
||||
import Pages.Docs.Dynamic
|
||||
import Pages.Docs.Static
|
||||
@ -44,8 +44,8 @@ type alias Recipe flags model msg appMsg =
|
||||
|
||||
|
||||
type alias Recipes msg =
|
||||
{ dynamic : Recipe Flags.Dynamic Pages.Docs.Dynamic.Model Pages.Docs.Dynamic.Msg msg
|
||||
, static : Recipe Flags.Static Pages.Docs.Static.Model Pages.Docs.Static.Msg msg
|
||||
{ dynamic : Recipe Params.Dynamic Pages.Docs.Dynamic.Model Pages.Docs.Dynamic.Msg msg
|
||||
, static : Recipe Params.Static Pages.Docs.Static.Model Pages.Docs.Static.Msg msg
|
||||
}
|
||||
|
||||
|
||||
@ -73,10 +73,10 @@ recipes =
|
||||
init : Route -> Page.Init Model Msg
|
||||
init route =
|
||||
case route of
|
||||
Routes.Dynamic flags ->
|
||||
Route.Dynamic _ flags ->
|
||||
recipes.dynamic.init flags
|
||||
|
||||
Routes.Static flags ->
|
||||
Route.Static flags ->
|
||||
recipes.static.init flags
|
||||
|
||||
|
||||
|
@ -1,12 +1,13 @@
|
||||
module Generated.Docs.Flags exposing
|
||||
module Generated.Docs.Params exposing
|
||||
( Dynamic
|
||||
, Static
|
||||
)
|
||||
|
||||
|
||||
type alias Static =
|
||||
()
|
||||
{}
|
||||
|
||||
|
||||
type alias Dynamic =
|
||||
String
|
||||
{ param1 : String
|
||||
}
|
37
elm-stuff/.elm-spa/Generated/Docs/Route.elm
Normal file
37
elm-stuff/.elm-spa/Generated/Docs/Route.elm
Normal file
@ -0,0 +1,37 @@
|
||||
module Generated.Docs.Route exposing
|
||||
( Route(..)
|
||||
, routes
|
||||
, toPath
|
||||
)
|
||||
|
||||
import App.Router
|
||||
import Generated.Docs.Params as Params
|
||||
import Url.Parser as Parser exposing ((</>), Parser)
|
||||
|
||||
|
||||
type Route
|
||||
= Static Params.Static
|
||||
| Dynamic String Params.Dynamic
|
||||
|
||||
|
||||
toPath : Route -> String
|
||||
toPath route =
|
||||
case route of
|
||||
Static _ ->
|
||||
"/static"
|
||||
|
||||
Dynamic value _ ->
|
||||
"/" ++ value
|
||||
|
||||
|
||||
routes :
|
||||
{}
|
||||
-> List (Parser (Route -> a) a)
|
||||
routes params =
|
||||
let
|
||||
router =
|
||||
App.Router.create params
|
||||
in
|
||||
[ router.path Static "static"
|
||||
, router.dynamic Dynamic (\param1 -> { param1 = param1 })
|
||||
]
|
@ -1,30 +0,0 @@
|
||||
module Generated.Docs.Routes exposing
|
||||
( Route(..)
|
||||
, routes
|
||||
, toPath
|
||||
)
|
||||
|
||||
import App.Route as Route
|
||||
import Generated.Docs.Flags as Flags
|
||||
|
||||
|
||||
type Route
|
||||
= Static Flags.Static
|
||||
| Dynamic Flags.Dynamic
|
||||
|
||||
|
||||
routes : List (Route.Route Route a)
|
||||
routes =
|
||||
[ Route.path "static" Static
|
||||
, Route.dynamic Dynamic
|
||||
]
|
||||
|
||||
|
||||
toPath : Route -> String
|
||||
toPath route =
|
||||
case route of
|
||||
Static _ ->
|
||||
"/static"
|
||||
|
||||
Dynamic string ->
|
||||
"/" ++ string
|
@ -1,5 +0,0 @@
|
||||
module Generated.Guide.Dynamic.Flags exposing (Intro)
|
||||
|
||||
|
||||
type alias Intro =
|
||||
()
|
@ -5,19 +5,22 @@ module Generated.Guide.Dynamic.Pages exposing
|
||||
)
|
||||
|
||||
import App.Page
|
||||
import Generated.Guide.Dynamic.Flags as Flags
|
||||
import Generated.Guide.Dynamic.Routes as Routes exposing (Route(..))
|
||||
import Generated.Guide.Dynamic.Params as Params
|
||||
import Generated.Guide.Dynamic.Route as Route exposing (Route)
|
||||
import Layouts.Guide.Dynamic as Layout
|
||||
import Pages.Guide.Dynamic.Intro
|
||||
import Pages.Guide.Dynamic.Other
|
||||
import Utils.Page as Page exposing (Page)
|
||||
|
||||
|
||||
type Model
|
||||
= IntroModel Pages.Guide.Dynamic.Intro.Model
|
||||
| OtherModel Pages.Guide.Dynamic.Other.Model
|
||||
|
||||
|
||||
type Msg
|
||||
= IntroMsg Pages.Guide.Dynamic.Intro.Msg
|
||||
| OtherMsg Pages.Guide.Dynamic.Other.Msg
|
||||
|
||||
|
||||
page : Page Route Model Msg layoutModel layoutMsg appMsg
|
||||
@ -41,7 +44,8 @@ type alias Recipe flags model msg appMsg =
|
||||
|
||||
|
||||
type alias Recipes msg =
|
||||
{ intro : Recipe Flags.Intro Pages.Guide.Dynamic.Intro.Model Pages.Guide.Dynamic.Intro.Msg msg
|
||||
{ intro : Recipe Params.Intro Pages.Guide.Dynamic.Intro.Model Pages.Guide.Dynamic.Intro.Msg msg
|
||||
, other : Recipe Params.Other Pages.Guide.Dynamic.Other.Model Pages.Guide.Dynamic.Other.Msg msg
|
||||
}
|
||||
|
||||
|
||||
@ -53,6 +57,12 @@ recipes =
|
||||
, toModel = IntroModel
|
||||
, toMsg = IntroMsg
|
||||
}
|
||||
, other =
|
||||
Page.recipe
|
||||
{ page = Pages.Guide.Dynamic.Other.page
|
||||
, toModel = OtherModel
|
||||
, toMsg = OtherMsg
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -63,9 +73,12 @@ recipes =
|
||||
init : Route -> Page.Init Model Msg
|
||||
init route =
|
||||
case route of
|
||||
Routes.Intro flags ->
|
||||
Route.Intro flags ->
|
||||
recipes.intro.init flags
|
||||
|
||||
Route.Other flags ->
|
||||
recipes.other.init flags
|
||||
|
||||
|
||||
|
||||
-- UPDATE
|
||||
@ -77,10 +90,14 @@ update bigMsg bigModel =
|
||||
( IntroMsg msg, IntroModel model ) ->
|
||||
recipes.intro.update msg model
|
||||
|
||||
( OtherMsg msg, OtherModel model ) ->
|
||||
recipes.other.update msg model
|
||||
|
||||
_ ->
|
||||
App.Page.keep bigModel
|
||||
|
||||
|
||||
|
||||
-- _ ->
|
||||
-- App.Page.keep bigModel
|
||||
-- BUNDLE
|
||||
|
||||
|
||||
@ -89,3 +106,6 @@ bundle bigModel =
|
||||
case bigModel of
|
||||
IntroModel model ->
|
||||
recipes.intro.bundle model
|
||||
|
||||
OtherModel model ->
|
||||
recipes.other.bundle model
|
||||
|
14
elm-stuff/.elm-spa/Generated/Guide/Dynamic/Params.elm
Normal file
14
elm-stuff/.elm-spa/Generated/Guide/Dynamic/Params.elm
Normal file
@ -0,0 +1,14 @@
|
||||
module Generated.Guide.Dynamic.Params exposing
|
||||
( Intro
|
||||
, Other
|
||||
)
|
||||
|
||||
|
||||
type alias Intro =
|
||||
{ param1 : String
|
||||
}
|
||||
|
||||
|
||||
type alias Other =
|
||||
{ param1 : String
|
||||
}
|
37
elm-stuff/.elm-spa/Generated/Guide/Dynamic/Route.elm
Normal file
37
elm-stuff/.elm-spa/Generated/Guide/Dynamic/Route.elm
Normal file
@ -0,0 +1,37 @@
|
||||
module Generated.Guide.Dynamic.Route exposing
|
||||
( Route(..)
|
||||
, routes
|
||||
, toPath
|
||||
)
|
||||
|
||||
import App.Router
|
||||
import Generated.Guide.Dynamic.Params as Params
|
||||
import Url.Parser as Parser exposing ((</>), Parser)
|
||||
|
||||
|
||||
type Route
|
||||
= Intro Params.Intro
|
||||
| Other Params.Other
|
||||
|
||||
|
||||
toPath : Route -> String
|
||||
toPath route =
|
||||
case route of
|
||||
Intro _ ->
|
||||
"/intro"
|
||||
|
||||
Other _ ->
|
||||
"/other"
|
||||
|
||||
|
||||
routes :
|
||||
{ param1 : String }
|
||||
-> List (Parser (Route -> a) a)
|
||||
routes params =
|
||||
let
|
||||
router =
|
||||
App.Router.create params
|
||||
in
|
||||
[ router.path Intro "intro"
|
||||
, router.path Other "other"
|
||||
]
|
@ -1,25 +0,0 @@
|
||||
module Generated.Guide.Dynamic.Routes exposing
|
||||
( Route(..)
|
||||
, routes
|
||||
, toPath
|
||||
)
|
||||
|
||||
import App.Route as Route
|
||||
import Generated.Guide.Dynamic.Flags as Flags
|
||||
|
||||
|
||||
type Route
|
||||
= Intro Flags.Intro
|
||||
|
||||
|
||||
routes : List (Route.Route Route a)
|
||||
routes =
|
||||
[ Route.path "intro" Intro
|
||||
]
|
||||
|
||||
|
||||
toPath : Route -> String
|
||||
toPath route =
|
||||
case route of
|
||||
Intro _ ->
|
||||
"/intro"
|
@ -6,9 +6,9 @@ module Generated.Guide.Pages exposing
|
||||
|
||||
import App.Page
|
||||
import Generated.Guide.Dynamic.Pages
|
||||
import Generated.Guide.Dynamic.Routes
|
||||
import Generated.Guide.Flags as Flags
|
||||
import Generated.Guide.Routes as Routes exposing (Route(..))
|
||||
import Generated.Guide.Dynamic.Route
|
||||
import Generated.Guide.Params as Params
|
||||
import Generated.Guide.Route as Route exposing (Route)
|
||||
import Layouts.Guide as Layout
|
||||
import Pages.Guide.Elm
|
||||
import Pages.Guide.ElmSpa
|
||||
@ -51,10 +51,10 @@ type alias Recipe flags model msg appMsg =
|
||||
|
||||
|
||||
type alias Recipes msg =
|
||||
{ elm : Recipe Flags.Elm Pages.Guide.Elm.Model Pages.Guide.Elm.Msg msg
|
||||
, elmApp : Recipe Flags.ElmSpa Pages.Guide.ElmSpa.Model Pages.Guide.ElmSpa.Msg msg
|
||||
, programming : Recipe Flags.Programming Pages.Guide.Programming.Model Pages.Guide.Programming.Msg msg
|
||||
, dynamic_folder : Recipe Generated.Guide.Dynamic.Routes.Route Generated.Guide.Dynamic.Pages.Model Generated.Guide.Dynamic.Pages.Msg msg
|
||||
{ elm : Recipe Params.Elm Pages.Guide.Elm.Model Pages.Guide.Elm.Msg msg
|
||||
, elmApp : Recipe Params.ElmSpa Pages.Guide.ElmSpa.Model Pages.Guide.ElmSpa.Msg msg
|
||||
, programming : Recipe Params.Programming Pages.Guide.Programming.Model Pages.Guide.Programming.Msg msg
|
||||
, dynamic_folder : Recipe Generated.Guide.Dynamic.Route.Route Generated.Guide.Dynamic.Pages.Model Generated.Guide.Dynamic.Pages.Msg msg
|
||||
}
|
||||
|
||||
|
||||
@ -94,16 +94,16 @@ recipes =
|
||||
init : Route -> Page.Init Model Msg
|
||||
init route =
|
||||
case route of
|
||||
Routes.Elm flags ->
|
||||
Route.Elm flags ->
|
||||
recipes.elm.init flags
|
||||
|
||||
Routes.ElmSpa flags ->
|
||||
Route.ElmSpa flags ->
|
||||
recipes.elmApp.init flags
|
||||
|
||||
Routes.Programming flags ->
|
||||
Route.Programming flags ->
|
||||
recipes.programming.init flags
|
||||
|
||||
Routes.Dynamic_Folder flags route_ ->
|
||||
Route.Dynamic_Folder flags route_ ->
|
||||
recipes.dynamic_folder.init route_
|
||||
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
module Generated.Guide.Flags exposing
|
||||
module Generated.Guide.Params exposing
|
||||
( Elm
|
||||
, ElmSpa
|
||||
, Programming
|
||||
@ -6,12 +6,12 @@ module Generated.Guide.Flags exposing
|
||||
|
||||
|
||||
type alias Elm =
|
||||
()
|
||||
{}
|
||||
|
||||
|
||||
type alias ElmSpa =
|
||||
()
|
||||
{}
|
||||
|
||||
|
||||
type alias Programming =
|
||||
()
|
||||
{}
|
50
elm-stuff/.elm-spa/Generated/Guide/Route.elm
Normal file
50
elm-stuff/.elm-spa/Generated/Guide/Route.elm
Normal file
@ -0,0 +1,50 @@
|
||||
module Generated.Guide.Route exposing
|
||||
( Route(..)
|
||||
, routes
|
||||
, toPath
|
||||
)
|
||||
|
||||
import App.Router
|
||||
import Generated.Guide.Dynamic.Route as Dynamic_Routes
|
||||
import Generated.Guide.Params as Params
|
||||
import Url.Parser as Parser exposing ((</>), Parser)
|
||||
|
||||
|
||||
type Route
|
||||
= Elm Params.Elm
|
||||
| ElmSpa Params.ElmSpa
|
||||
| Programming Params.Programming
|
||||
| Dynamic_Folder String Dynamic_Routes.Route
|
||||
|
||||
|
||||
toPath : Route -> String
|
||||
toPath route =
|
||||
case route of
|
||||
Elm _ ->
|
||||
"/elm"
|
||||
|
||||
ElmSpa _ ->
|
||||
"/elm-spa"
|
||||
|
||||
Programming _ ->
|
||||
"/programming"
|
||||
|
||||
Dynamic_Folder value subRoute ->
|
||||
"/" ++ value ++ Dynamic_Routes.toPath subRoute
|
||||
|
||||
|
||||
routes :
|
||||
{}
|
||||
-> List (Parser (Route -> a) a)
|
||||
routes params =
|
||||
let
|
||||
router =
|
||||
App.Router.create params
|
||||
in
|
||||
[ router.path Elm "elm"
|
||||
, router.path ElmSpa "elm-spa"
|
||||
, router.path Programming "programming"
|
||||
, router.dynamicFolder Dynamic_Folder
|
||||
(\param1 -> { param1 = param1 })
|
||||
Dynamic_Routes.routes
|
||||
]
|
@ -1,41 +0,0 @@
|
||||
module Generated.Guide.Routes exposing
|
||||
( Route(..)
|
||||
, routes
|
||||
, toPath
|
||||
)
|
||||
|
||||
import App.Route as Route
|
||||
import Generated.Guide.Dynamic.Routes
|
||||
import Generated.Guide.Flags as Flags
|
||||
|
||||
|
||||
type Route
|
||||
= Elm Flags.Elm
|
||||
| ElmSpa Flags.ElmSpa
|
||||
| Programming Flags.Programming
|
||||
| Dynamic_Folder String Generated.Guide.Dynamic.Routes.Route
|
||||
|
||||
|
||||
routes : List (Route.Route Route a)
|
||||
routes =
|
||||
[ Route.path "elm" Elm
|
||||
, Route.path "elm-spa" ElmSpa
|
||||
, Route.path "programming" Programming
|
||||
, Route.dynamicFolder Dynamic_Folder Generated.Guide.Dynamic.Routes.routes
|
||||
]
|
||||
|
||||
|
||||
toPath : Route -> String
|
||||
toPath route =
|
||||
case route of
|
||||
Elm _ ->
|
||||
"/"
|
||||
|
||||
ElmSpa _ ->
|
||||
"/elm-spa"
|
||||
|
||||
Programming _ ->
|
||||
"/programming"
|
||||
|
||||
Dynamic_Folder string route_ ->
|
||||
"/" ++ string ++ Generated.Guide.Dynamic.Routes.toPath route_
|
@ -6,11 +6,11 @@ module Generated.Pages exposing
|
||||
|
||||
import App.Page
|
||||
import Generated.Docs.Pages
|
||||
import Generated.Docs.Routes
|
||||
import Generated.Flags as Flags
|
||||
import Generated.Docs.Route
|
||||
import Generated.Guide.Pages
|
||||
import Generated.Guide.Routes
|
||||
import Generated.Routes as Routes exposing (Route(..))
|
||||
import Generated.Guide.Route
|
||||
import Generated.Params as Params
|
||||
import Generated.Route as Route exposing (Route(..))
|
||||
import Layout as Layout
|
||||
import Pages.Docs
|
||||
import Pages.Guide
|
||||
@ -61,13 +61,13 @@ type alias Recipe flags model msg appMsg =
|
||||
|
||||
|
||||
type alias Recipes msg =
|
||||
{ top : Recipe Flags.Top Pages.Top.Model Pages.Top.Msg msg
|
||||
, docs : Recipe Flags.Docs Pages.Docs.Model Pages.Docs.Msg msg
|
||||
, notFound : Recipe Flags.NotFound Pages.NotFound.Model Pages.NotFound.Msg msg
|
||||
, signIn : Recipe Flags.SignIn Pages.SignIn.Model Pages.SignIn.Msg msg
|
||||
, guide : Recipe Flags.Guide Pages.Guide.Model Pages.Guide.Msg msg
|
||||
, guide_folder : Recipe Generated.Guide.Routes.Route Generated.Guide.Pages.Model Generated.Guide.Pages.Msg msg
|
||||
, docs_folder : Recipe Generated.Docs.Routes.Route Generated.Docs.Pages.Model Generated.Docs.Pages.Msg msg
|
||||
{ top : Recipe Params.Top Pages.Top.Model Pages.Top.Msg msg
|
||||
, docs : Recipe Params.Docs Pages.Docs.Model Pages.Docs.Msg msg
|
||||
, notFound : Recipe Params.NotFound Pages.NotFound.Model Pages.NotFound.Msg msg
|
||||
, signIn : Recipe Params.SignIn Pages.SignIn.Model Pages.SignIn.Msg msg
|
||||
, guide : Recipe Params.Guide Pages.Guide.Model Pages.Guide.Msg msg
|
||||
, guide_folder : Recipe Generated.Guide.Route.Route Generated.Guide.Pages.Model Generated.Guide.Pages.Msg msg
|
||||
, docs_folder : Recipe Generated.Docs.Route.Route Generated.Docs.Pages.Model Generated.Docs.Pages.Msg msg
|
||||
}
|
||||
|
||||
|
||||
@ -125,25 +125,25 @@ recipes =
|
||||
init : Route -> Page.Init Model Msg
|
||||
init route_ =
|
||||
case route_ of
|
||||
Routes.Top flags ->
|
||||
Route.Top flags ->
|
||||
recipes.top.init flags
|
||||
|
||||
Routes.Docs flags ->
|
||||
Route.Docs flags ->
|
||||
recipes.docs.init flags
|
||||
|
||||
Routes.NotFound flags ->
|
||||
Route.NotFound flags ->
|
||||
recipes.notFound.init flags
|
||||
|
||||
Routes.SignIn flags ->
|
||||
Route.SignIn flags ->
|
||||
recipes.signIn.init flags
|
||||
|
||||
Routes.Guide flags ->
|
||||
Route.Guide flags ->
|
||||
recipes.guide.init flags
|
||||
|
||||
Routes.Guide_Folder route ->
|
||||
Route.Guide_Folder route ->
|
||||
recipes.guide_folder.init route
|
||||
|
||||
Routes.Docs_Folder route ->
|
||||
Route.Docs_Folder route ->
|
||||
recipes.docs_folder.init route
|
||||
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
module Generated.Flags exposing
|
||||
module Generated.Params exposing
|
||||
( Docs
|
||||
, Guide
|
||||
, NotFound
|
||||
@ -8,20 +8,20 @@ module Generated.Flags exposing
|
||||
|
||||
|
||||
type alias Top =
|
||||
()
|
||||
{}
|
||||
|
||||
|
||||
type alias Docs =
|
||||
()
|
||||
{}
|
||||
|
||||
|
||||
type alias NotFound =
|
||||
()
|
||||
{}
|
||||
|
||||
|
||||
type alias SignIn =
|
||||
()
|
||||
{}
|
||||
|
||||
|
||||
type alias Guide =
|
||||
()
|
||||
{}
|
63
elm-stuff/.elm-spa/Generated/Route.elm
Normal file
63
elm-stuff/.elm-spa/Generated/Route.elm
Normal file
@ -0,0 +1,63 @@
|
||||
module Generated.Route exposing
|
||||
( Route(..)
|
||||
, routes
|
||||
, toPath
|
||||
)
|
||||
|
||||
import App.Router
|
||||
import Generated.Docs.Route
|
||||
import Generated.Guide.Dynamic.Route
|
||||
import Generated.Guide.Route
|
||||
import Generated.Params
|
||||
import Url.Parser as Parser exposing ((</>), Parser)
|
||||
|
||||
|
||||
type Route
|
||||
= Top Generated.Params.Top
|
||||
| Docs Generated.Params.Docs
|
||||
| NotFound Generated.Params.NotFound
|
||||
| SignIn Generated.Params.SignIn
|
||||
| Guide Generated.Params.Guide
|
||||
| Guide_Folder Generated.Guide.Route.Route
|
||||
| Docs_Folder Generated.Docs.Route.Route
|
||||
|
||||
|
||||
routes : List (Parser (Route -> a) a)
|
||||
routes =
|
||||
let
|
||||
router =
|
||||
App.Router.create {}
|
||||
in
|
||||
[ router.top Top
|
||||
, router.path Docs "docs"
|
||||
, router.path Guide "guide"
|
||||
, router.path SignIn "sign-in"
|
||||
, router.path NotFound "not-found"
|
||||
, router.folder Guide_Folder "guide" Generated.Guide.Route.routes
|
||||
, router.folder Docs_Folder "docs" Generated.Docs.Route.routes
|
||||
]
|
||||
|
||||
|
||||
toPath : Route -> String
|
||||
toPath route =
|
||||
case route of
|
||||
Top _ ->
|
||||
"/"
|
||||
|
||||
Docs _ ->
|
||||
"/docs"
|
||||
|
||||
NotFound _ ->
|
||||
"/not-found"
|
||||
|
||||
SignIn _ ->
|
||||
"/sign-in"
|
||||
|
||||
Guide _ ->
|
||||
"/guide"
|
||||
|
||||
Guide_Folder subRoute ->
|
||||
"/guide" ++ Generated.Guide.Route.toPath subRoute
|
||||
|
||||
Docs_Folder subRoute ->
|
||||
"/docs" ++ Generated.Docs.Route.toPath subRoute
|
@ -1,57 +0,0 @@
|
||||
module Generated.Routes exposing
|
||||
( Route(..)
|
||||
, routes
|
||||
, toPath
|
||||
)
|
||||
|
||||
import App.Route as Route
|
||||
import Generated.Docs.Routes
|
||||
import Generated.Flags as Flags
|
||||
import Generated.Guide.Routes
|
||||
|
||||
|
||||
type Route
|
||||
= Top Flags.Top
|
||||
| Docs Flags.Docs
|
||||
| NotFound Flags.NotFound
|
||||
| SignIn Flags.SignIn
|
||||
| Guide Flags.Guide
|
||||
| Guide_Folder Generated.Guide.Routes.Route
|
||||
| Docs_Folder Generated.Docs.Routes.Route
|
||||
|
||||
|
||||
routes : List (Route.Route Route a)
|
||||
routes =
|
||||
[ Route.top Top
|
||||
, Route.path "docs" Docs
|
||||
, Route.path "not-found" NotFound
|
||||
, Route.path "sign-in" SignIn
|
||||
, Route.path "guide" Guide
|
||||
, Route.folder "guide" Guide_Folder Generated.Guide.Routes.routes
|
||||
, Route.folder "docs" Docs_Folder Generated.Docs.Routes.routes
|
||||
]
|
||||
|
||||
|
||||
toPath : Route -> String
|
||||
toPath route =
|
||||
case route of
|
||||
Top _ ->
|
||||
"/"
|
||||
|
||||
Docs _ ->
|
||||
"/docs"
|
||||
|
||||
NotFound _ ->
|
||||
"/not-found"
|
||||
|
||||
SignIn _ ->
|
||||
"/sign-in"
|
||||
|
||||
Guide _ ->
|
||||
"/guide"
|
||||
|
||||
Guide_Folder route_ ->
|
||||
"/guide" ++ Generated.Guide.Routes.toPath route_
|
||||
|
||||
Docs_Folder route_ ->
|
||||
"/docs" ++ Generated.Docs.Routes.toPath route_
|
@ -2,5 +2,5 @@
|
||||
> this is where all the generated code goes!
|
||||
|
||||
Normally, this whole directory should be `.gitignore`d,
|
||||
but I'm keeping it around so I can manually practice
|
||||
what `elm-spa build` should be building.
|
||||
but I'm keeping it around so I can better understand
|
||||
what `elm-spa build` should be generating!
|
||||
|
@ -7,7 +7,7 @@ module Global exposing
|
||||
, update
|
||||
)
|
||||
|
||||
import Generated.Routes as Routes exposing (Route)
|
||||
import Generated.Route as Route exposing (Route)
|
||||
|
||||
|
||||
type alias Flags =
|
||||
@ -43,7 +43,8 @@ update commands msg model =
|
||||
SignIn user ->
|
||||
( { model | user = Just user }
|
||||
, Cmd.none
|
||||
, commands.navigate (Routes.Top ())
|
||||
, Cmd.none
|
||||
-- , commands.navigate (Route.Top {})
|
||||
)
|
||||
|
||||
SignOut ->
|
||||
|
@ -1,5 +1,6 @@
|
||||
module Layouts.Guide exposing (view)
|
||||
|
||||
import Components.Styles as Styles
|
||||
import Element exposing (..)
|
||||
import Global
|
||||
|
||||
@ -13,4 +14,11 @@ type alias Context msg =
|
||||
|
||||
view : Context msg -> Element msg
|
||||
view { page } =
|
||||
page
|
||||
column
|
||||
[ width fill
|
||||
, spacing -128
|
||||
]
|
||||
[ page
|
||||
, el [ centerX ] <|
|
||||
link Styles.link { label = text "back to guide", url = "/guide" }
|
||||
]
|
||||
|
@ -3,7 +3,7 @@ module Main exposing (main)
|
||||
import App
|
||||
import Element
|
||||
import Generated.Pages as Pages
|
||||
import Generated.Routes as Routes
|
||||
import Generated.Route as Route
|
||||
import Global
|
||||
import Pages.NotFound
|
||||
|
||||
@ -16,9 +16,9 @@ main =
|
||||
, map = Element.map
|
||||
}
|
||||
, routing =
|
||||
{ routes = Routes.routes
|
||||
, toPath = Routes.toPath
|
||||
, notFound = Routes.NotFound ()
|
||||
{ routes = Route.routes
|
||||
, toPath = Route.toPath
|
||||
, notFound = Route.NotFound {}
|
||||
}
|
||||
, global =
|
||||
{ init = Global.init
|
||||
|
@ -3,7 +3,7 @@ module Pages.Docs exposing (Model, Msg, page)
|
||||
import App.Page
|
||||
import Components.Hero
|
||||
import Element exposing (..)
|
||||
import Generated.Flags as Flags
|
||||
import Generated.Params as Params
|
||||
import Utils.Page exposing (Page)
|
||||
|
||||
|
||||
@ -15,7 +15,7 @@ type alias Msg =
|
||||
Never
|
||||
|
||||
|
||||
page : Page Flags.Docs Model Msg model msg appMsg
|
||||
page : Page Params.Docs Model Msg model msg appMsg
|
||||
page =
|
||||
App.Page.static
|
||||
{ title = always "Docs"
|
||||
|
@ -3,7 +3,7 @@ module Pages.Docs.Dynamic exposing (Model, Msg, page)
|
||||
import App.Page
|
||||
import Components.Hero
|
||||
import Element exposing (..)
|
||||
import Generated.Docs.Flags as Flags
|
||||
import Generated.Docs.Params as Params
|
||||
import Global
|
||||
import Utils.Page exposing (Page)
|
||||
|
||||
@ -17,7 +17,7 @@ type alias Msg =
|
||||
Never
|
||||
|
||||
|
||||
page : Page Flags.Dynamic Model Msg model msg appMsg
|
||||
page : Page Params.Dynamic Model Msg model msg appMsg
|
||||
page =
|
||||
App.Page.sandbox
|
||||
{ title = always "Dynamic"
|
||||
@ -31,9 +31,9 @@ page =
|
||||
-- INIT
|
||||
|
||||
|
||||
init : Flags.Dynamic -> Model
|
||||
init slug =
|
||||
{ slug = slug
|
||||
init : Params.Dynamic -> Model
|
||||
init { param1 } =
|
||||
{ slug = param1
|
||||
}
|
||||
|
||||
|
||||
|
@ -3,7 +3,7 @@ module Pages.Docs.Static exposing (Model, Msg, page)
|
||||
import App.Page
|
||||
import Components.Hero
|
||||
import Element exposing (..)
|
||||
import Generated.Docs.Flags as Flags
|
||||
import Generated.Docs.Params as Params
|
||||
import Utils.Page exposing (Page)
|
||||
|
||||
|
||||
@ -15,7 +15,7 @@ type alias Msg =
|
||||
Never
|
||||
|
||||
|
||||
page : Page Flags.Static Model Msg model msg appMsg
|
||||
page : Page Params.Static Model Msg model msg appMsg
|
||||
page =
|
||||
App.Page.static
|
||||
{ title = always "Static"
|
||||
|
@ -3,7 +3,7 @@ module Pages.Guide exposing (Model, Msg, page)
|
||||
import App.Page
|
||||
import Components.Hero
|
||||
import Element exposing (..)
|
||||
import Generated.Flags as Flags
|
||||
import Generated.Params as Params
|
||||
import Utils.Page exposing (Page)
|
||||
|
||||
|
||||
@ -15,7 +15,7 @@ type alias Msg =
|
||||
Never
|
||||
|
||||
|
||||
page : Page Flags.Guide Model Msg model msg appMsg
|
||||
page : Page Params.Guide Model Msg model msg appMsg
|
||||
page =
|
||||
App.Page.static
|
||||
{ title = always "Guide"
|
||||
|
@ -3,37 +3,50 @@ module Pages.Guide.Dynamic.Intro exposing (Model, Msg, page)
|
||||
import App.Page
|
||||
import Components.Hero
|
||||
import Element exposing (..)
|
||||
import Generated.Guide.Dynamic.Flags as Flags
|
||||
import Generated.Guide.Dynamic.Params as Params
|
||||
import Utils.Page exposing (Page)
|
||||
|
||||
|
||||
type alias Model =
|
||||
()
|
||||
{ slug : String
|
||||
}
|
||||
|
||||
|
||||
type alias Msg =
|
||||
Never
|
||||
|
||||
|
||||
page : Page Flags.Intro Model Msg model msg appMsg
|
||||
page : Page Params.Intro Model Msg model msg appMsg
|
||||
page =
|
||||
App.Page.static
|
||||
App.Page.sandbox
|
||||
{ title = always "Guide.Dynamic.Intro"
|
||||
, init = always init
|
||||
, update = always update
|
||||
, view = always view
|
||||
}
|
||||
|
||||
|
||||
init : Params.Intro -> Model
|
||||
init { param1 } =
|
||||
{ slug = param1
|
||||
}
|
||||
|
||||
|
||||
update msg model =
|
||||
model
|
||||
|
||||
|
||||
|
||||
-- VIEW
|
||||
|
||||
|
||||
view : Element Msg
|
||||
view =
|
||||
view : Model -> Element Msg
|
||||
view model =
|
||||
column
|
||||
[ width fill
|
||||
]
|
||||
[ Components.Hero.view
|
||||
{ title = "intro"
|
||||
{ title = "intro to " ++ model.slug
|
||||
, subtitle = text "\"you're gonna be great.\""
|
||||
, buttons = []
|
||||
}
|
||||
|
53
example/Pages/Guide/Dynamic/Other.elm
Normal file
53
example/Pages/Guide/Dynamic/Other.elm
Normal file
@ -0,0 +1,53 @@
|
||||
module Pages.Guide.Dynamic.Other exposing (Model, Msg, page)
|
||||
|
||||
import App.Page
|
||||
import Components.Hero
|
||||
import Element exposing (..)
|
||||
import Generated.Guide.Dynamic.Params as Params
|
||||
import Utils.Page exposing (Page)
|
||||
|
||||
|
||||
type alias Model =
|
||||
{ slug : String
|
||||
}
|
||||
|
||||
|
||||
type alias Msg =
|
||||
Never
|
||||
|
||||
|
||||
page : Page Params.Other Model Msg model msg appMsg
|
||||
page =
|
||||
App.Page.sandbox
|
||||
{ title = always "Guide.Dynamic.Other"
|
||||
, init = always init
|
||||
, update = always update
|
||||
, view = always view
|
||||
}
|
||||
|
||||
|
||||
init : Params.Other -> Model
|
||||
init { param1 } =
|
||||
{ slug = param1
|
||||
}
|
||||
|
||||
|
||||
update msg model =
|
||||
model
|
||||
|
||||
|
||||
|
||||
-- VIEW
|
||||
|
||||
|
||||
view : Model -> Element Msg
|
||||
view model =
|
||||
column
|
||||
[ width fill
|
||||
]
|
||||
[ Components.Hero.view
|
||||
{ title = "other " ++ model.slug
|
||||
, subtitle = text "\"you're gonna be great.\""
|
||||
, buttons = []
|
||||
}
|
||||
]
|
@ -3,7 +3,7 @@ module Pages.Guide.Elm exposing (Model, Msg, page)
|
||||
import App.Page
|
||||
import Components.Hero
|
||||
import Element exposing (..)
|
||||
import Generated.Guide.Flags as Flags
|
||||
import Generated.Guide.Params as Params
|
||||
import Utils.Page exposing (Page)
|
||||
|
||||
|
||||
@ -15,7 +15,7 @@ type alias Msg =
|
||||
Never
|
||||
|
||||
|
||||
page : Page Flags.Elm Model Msg model msg appMsg
|
||||
page : Page Params.Elm Model Msg model msg appMsg
|
||||
page =
|
||||
App.Page.static
|
||||
{ title = always "Guide.Elm"
|
||||
|
@ -3,7 +3,7 @@ module Pages.Guide.ElmSpa exposing (Model, Msg, page)
|
||||
import App.Page
|
||||
import Components.Hero
|
||||
import Element exposing (..)
|
||||
import Generated.Guide.Flags as Flags
|
||||
import Generated.Guide.Params as Params
|
||||
import Utils.Page exposing (Page)
|
||||
|
||||
|
||||
@ -15,7 +15,7 @@ type alias Msg =
|
||||
Never
|
||||
|
||||
|
||||
page : Page Flags.ElmSpa Model Msg model msg appMsg
|
||||
page : Page Params.ElmSpa Model Msg model msg appMsg
|
||||
page =
|
||||
App.Page.static
|
||||
{ title = always "Guide.ElmSpa"
|
||||
|
@ -3,7 +3,7 @@ module Pages.Guide.Programming exposing (Model, Msg, page)
|
||||
import App.Page
|
||||
import Components.Hero
|
||||
import Element exposing (..)
|
||||
import Generated.Guide.Flags as Flags
|
||||
import Generated.Guide.Params as Params
|
||||
import Utils.Page exposing (Page)
|
||||
|
||||
|
||||
@ -15,7 +15,7 @@ type alias Msg =
|
||||
Never
|
||||
|
||||
|
||||
page : Page Flags.Programming Model Msg model msg appMsg
|
||||
page : Page Params.Programming Model Msg model msg appMsg
|
||||
page =
|
||||
App.Page.static
|
||||
{ title = always "Guide.Programming"
|
||||
|
@ -3,7 +3,7 @@ module Pages.NotFound exposing (Model, Msg, page)
|
||||
import App.Page
|
||||
import Components.Hero
|
||||
import Element exposing (..)
|
||||
import Generated.Flags as Flags
|
||||
import Generated.Params as Params
|
||||
import Utils.Page exposing (Page)
|
||||
|
||||
|
||||
@ -15,7 +15,7 @@ type alias Msg =
|
||||
Never
|
||||
|
||||
|
||||
page : Page Flags.NotFound Model Msg model msg appMsg
|
||||
page : Page Params.NotFound Model Msg model msg appMsg
|
||||
page =
|
||||
App.Page.static
|
||||
{ title = always "NotFound"
|
||||
@ -31,7 +31,7 @@ view : Element Msg
|
||||
view =
|
||||
column [ width fill ]
|
||||
[ Components.Hero.view
|
||||
{ title = "that's not a place."
|
||||
{ title = "page not found"
|
||||
, subtitle = text "but i'm not even mad about it."
|
||||
, buttons =
|
||||
[ { label = text "back home", action = Components.Hero.Link "/" }
|
||||
|
@ -7,7 +7,7 @@ import Element exposing (..)
|
||||
import Element.Border as Border
|
||||
import Element.Font as Font
|
||||
import Element.Input as Input
|
||||
import Generated.Flags as Flags
|
||||
import Generated.Params as Params
|
||||
import Global
|
||||
import Html exposing (Html)
|
||||
import Html.Attributes as Attr
|
||||
@ -31,7 +31,7 @@ type Field
|
||||
| Password
|
||||
|
||||
|
||||
page : Page Flags.SignIn Model Msg model msg appMsg
|
||||
page : Page Params.SignIn Model Msg model msg appMsg
|
||||
page =
|
||||
App.Page.component
|
||||
{ title = always "sign in | elm-spa"
|
||||
@ -46,7 +46,7 @@ page =
|
||||
-- INIT
|
||||
|
||||
|
||||
init : Flags.SignIn -> ( Model, Cmd Msg, Cmd Global.Msg )
|
||||
init : Params.SignIn -> ( Model, Cmd Msg, Cmd Global.Msg )
|
||||
init flags =
|
||||
( { username = ""
|
||||
, password = ""
|
||||
|
@ -5,7 +5,7 @@ import Components.Hero
|
||||
import Components.Section
|
||||
import Components.Styles as Styles
|
||||
import Element exposing (..)
|
||||
import Generated.Flags as Flags
|
||||
import Generated.Params as Params
|
||||
import Html.Attributes as Attr
|
||||
import Ports
|
||||
import Utils.Page exposing (Page)
|
||||
@ -15,7 +15,7 @@ type alias Model =
|
||||
()
|
||||
|
||||
|
||||
page : Page Flags.Top Model Msg model msg appMsg
|
||||
page : Page Params.Top Model Msg model msg appMsg
|
||||
page =
|
||||
App.Page.element
|
||||
{ title = always "elm-spa"
|
||||
@ -30,8 +30,8 @@ page =
|
||||
-- INIT
|
||||
|
||||
|
||||
init : Flags.Top -> ( Model, Cmd Msg )
|
||||
init flags =
|
||||
init : Params.Top -> ( Model, Cmd Msg )
|
||||
init params =
|
||||
( ()
|
||||
, Cmd.none
|
||||
)
|
||||
|
@ -57,14 +57,13 @@ Let `App.create` know about this by passing in your own `Options` like these:
|
||||
|
||||
-}
|
||||
|
||||
import App.Route as Route exposing (Route)
|
||||
import Browser
|
||||
import Browser.Navigation as Nav
|
||||
import Html exposing (Html)
|
||||
import Internals.Page as Page
|
||||
import Internals.Utils as Utils
|
||||
import Url exposing (Url)
|
||||
import Url.Parser as Parser
|
||||
import Url.Parser as Parser exposing (Parser)
|
||||
|
||||
|
||||
|
||||
@ -109,7 +108,7 @@ create :
|
||||
, map : (layoutMsg -> Msg globalMsg layoutMsg) -> uiLayoutMsg -> uiMsg
|
||||
}
|
||||
, routing :
|
||||
{ routes : List (Route route route)
|
||||
{ routes : List (Parser (route -> route) route)
|
||||
, toPath : route -> String
|
||||
, notFound : route
|
||||
}
|
||||
@ -186,7 +185,7 @@ create config =
|
||||
|
||||
|
||||
type alias Routes route a =
|
||||
List (Route.Route route a)
|
||||
List (Parser (route -> a) a)
|
||||
|
||||
|
||||
fromUrl : { a | routes : Routes route route, notFound : route } -> Url -> route
|
||||
|
@ -1,100 +0,0 @@
|
||||
module App.Route exposing
|
||||
( Route
|
||||
, top
|
||||
, path
|
||||
, folder
|
||||
, dynamic, dynamicFolder
|
||||
)
|
||||
|
||||
{-|
|
||||
|
||||
|
||||
# Routing
|
||||
|
||||
The [cli tool](https://github.com/ryannhg/elm-spa/tree/master/cli) is able to generate routes based on the folder
|
||||
structure and files in the `src/Pages` folder.
|
||||
|
||||
If you're choosing to type out the routes manually, these are just
|
||||
convenience functions for creating `Url.Parser` types for your application.
|
||||
|
||||
@docs Route
|
||||
|
||||
@docs top
|
||||
|
||||
@docs path
|
||||
|
||||
@docs slug
|
||||
|
||||
@docs folder
|
||||
|
||||
-}
|
||||
|
||||
import Url exposing (Url)
|
||||
import Url.Parser as Parser exposing ((</>), Parser)
|
||||
|
||||
|
||||
{-| Literally just a Url.Parser under the hood.
|
||||
-}
|
||||
type alias Route route a =
|
||||
Parser (route -> a) a
|
||||
|
||||
|
||||
{-| A route for a path like. These are generated by other file names.
|
||||
|
||||
Route.path "about-us" AboutUs
|
||||
|
||||
-}
|
||||
path : String -> (() -> route) -> Route route a
|
||||
path path_ toRoute =
|
||||
Parser.map toRoute (Parser.s path_ |> Parser.map ())
|
||||
|
||||
|
||||
{-| A top level route.
|
||||
Usually generated by an `Top.elm` file.
|
||||
|
||||
Route.top Top
|
||||
|
||||
-}
|
||||
top : (() -> route) -> Route route a
|
||||
top toRoute =
|
||||
Parser.map toRoute (Parser.top |> Parser.map ())
|
||||
|
||||
|
||||
{-| A dynamic route, that passes the `String` value.
|
||||
Usually generated by an `Dynamic.elm` file.
|
||||
|
||||
Route.dynamic Dynamic
|
||||
|
||||
-}
|
||||
dynamic : (String -> route) -> Route route a
|
||||
dynamic toRoute =
|
||||
Parser.map toRoute Parser.string
|
||||
|
||||
|
||||
{-| A route for nested routes, generated by a folder.
|
||||
|
||||
Route.folder "settings" Settings_ Generated.Settings.Route.routes
|
||||
|
||||
-}
|
||||
folder :
|
||||
String
|
||||
-> (subRoute -> route)
|
||||
-> List (Route subRoute route)
|
||||
-> Route route a
|
||||
folder path_ toRoute children =
|
||||
Parser.map toRoute
|
||||
(Parser.s path_ </> Parser.oneOf children)
|
||||
|
||||
|
||||
{-| A route for nested dynamic routes, generated by a folder.
|
||||
|
||||
Route.dynamicFolder Dynamic_ Dynamic_.routes
|
||||
|
||||
-}
|
||||
dynamicFolder :
|
||||
(String -> subRoute -> route)
|
||||
-> List (Route subRoute route)
|
||||
-> Route route a
|
||||
dynamicFolder toRoute children =
|
||||
Parser.map toRoute
|
||||
(Parser.string </> Parser.oneOf children)
|
83
src/App/Router.elm
Normal file
83
src/App/Router.elm
Normal file
@ -0,0 +1,83 @@
|
||||
module App.Router exposing (Router, create)
|
||||
|
||||
import Url.Parser as Parser exposing ((</>), Parser)
|
||||
|
||||
|
||||
router =
|
||||
{ top =
|
||||
\r -> Parser.map (r {}) <| Parser.top
|
||||
, path =
|
||||
\r p -> Parser.map (r {}) <| Parser.s p
|
||||
, folder =
|
||||
\r p children -> Parser.map r <| Parser.s p </> Parser.oneOf children
|
||||
, dynamicFolder =
|
||||
\folder toParams routes_ ->
|
||||
Parser.string
|
||||
|> andThen
|
||||
(\value ->
|
||||
Parser.oneOf (routes_ (toParams value))
|
||||
|> Parser.map (folder value)
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
andThen :
|
||||
(a -> Parser (b -> c) c)
|
||||
-> Parser (a -> b) b
|
||||
-> Parser (b -> c) c
|
||||
andThen =
|
||||
Debug.todo "Parser.andThen"
|
||||
|
||||
|
||||
type alias Router params subParams route subRoute a =
|
||||
{ top :
|
||||
(params -> route)
|
||||
-> Parser (route -> a) a
|
||||
, path :
|
||||
(params -> route)
|
||||
-> String
|
||||
-> Parser (route -> a) a
|
||||
, dynamic :
|
||||
(String -> subParams -> route)
|
||||
-> (String -> subParams)
|
||||
-> Parser (route -> a) a
|
||||
, folder :
|
||||
(subRoute -> route)
|
||||
-> String
|
||||
-> (params -> List (Parser (subRoute -> route) route))
|
||||
-> Parser (route -> a) a
|
||||
, dynamicFolder :
|
||||
(String -> subRoute -> route)
|
||||
-> (String -> subParams)
|
||||
-> (subParams -> List (Parser (subRoute -> route) route))
|
||||
-> Parser (route -> a) a
|
||||
}
|
||||
|
||||
|
||||
create : params -> Router params subParams route subRoute a
|
||||
create params =
|
||||
{ top =
|
||||
\toRoute ->
|
||||
Parser.map (toRoute params)
|
||||
Parser.top
|
||||
, path =
|
||||
\toRoute path ->
|
||||
Parser.map (toRoute params)
|
||||
(Parser.s path)
|
||||
, dynamic =
|
||||
\toRoute toParams ->
|
||||
Parser.map (\value -> toRoute value (toParams value))
|
||||
Parser.string
|
||||
, folder =
|
||||
\toRoute path children ->
|
||||
Parser.map toRoute
|
||||
(Parser.s path </> Parser.oneOf (children params))
|
||||
, dynamicFolder =
|
||||
\toRoute toParams routes_ ->
|
||||
Parser.string
|
||||
|> andThen
|
||||
(\value ->
|
||||
Parser.oneOf (routes_ (toParams value))
|
||||
|> Parser.map (toRoute value)
|
||||
)
|
||||
}
|
Loading…
Reference in New Issue
Block a user