mirror of
https://github.com/ryan-haskell/elm-spa.git
synced 2024-11-22 03:12:01 +03:00
update examples for 6.0.7--beta
This commit is contained in:
parent
29dbd364b0
commit
19df55bd85
@ -1,9 +1,9 @@
|
||||
module Pages.Home_ exposing (page)
|
||||
module Pages.Home_ exposing (view)
|
||||
|
||||
import Html
|
||||
|
||||
|
||||
page =
|
||||
view =
|
||||
{ title = "Homepage"
|
||||
, body =
|
||||
[ Html.text "Hello, world!"
|
||||
|
5
examples/02-pages/.gitignore
vendored
Normal file
5
examples/02-pages/.gitignore
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
.DS_Store
|
||||
.elm-spa
|
||||
elm-stuff
|
||||
node_modules
|
||||
dist
|
28
examples/02-pages/README.md
Normal file
28
examples/02-pages/README.md
Normal file
@ -0,0 +1,28 @@
|
||||
# my new project
|
||||
> 🌳 built with [elm-spa](https://elm-spa.dev)
|
||||
|
||||
## dependencies
|
||||
|
||||
This project requires the latest LTS version of [Node.js](https://nodejs.org/)
|
||||
|
||||
```bash
|
||||
npm install -g elm elm-spa
|
||||
```
|
||||
|
||||
## running locally
|
||||
|
||||
```bash
|
||||
elm-spa server # starts this app at http:/localhost:1234
|
||||
```
|
||||
|
||||
### other commands
|
||||
|
||||
```bash
|
||||
elm-spa add # add a new page to the application
|
||||
elm-spa build # production build
|
||||
elm-spa watch # runs build as you code (without the server)
|
||||
```
|
||||
|
||||
## learn more
|
||||
|
||||
You can learn more at [elm-spa.dev](https://elm-spa.dev)
|
27
examples/02-pages/elm.json
Normal file
27
examples/02-pages/elm.json
Normal file
@ -0,0 +1,27 @@
|
||||
{
|
||||
"type": "application",
|
||||
"source-directories": [
|
||||
"src",
|
||||
".elm-spa/defaults",
|
||||
".elm-spa/generated"
|
||||
],
|
||||
"elm-version": "0.19.1",
|
||||
"dependencies": {
|
||||
"direct": {
|
||||
"elm/browser": "1.0.2",
|
||||
"elm/core": "1.0.5",
|
||||
"elm/html": "1.0.0",
|
||||
"elm/json": "1.1.3",
|
||||
"elm/url": "1.0.0",
|
||||
"ryannhg/elm-spa": "5.2.0"
|
||||
},
|
||||
"indirect": {
|
||||
"elm/time": "1.0.0",
|
||||
"elm/virtual-dom": "1.0.2"
|
||||
}
|
||||
},
|
||||
"test-dependencies": {
|
||||
"direct": {},
|
||||
"indirect": {}
|
||||
}
|
||||
}
|
11
examples/02-pages/public/index.html
Normal file
11
examples/02-pages/public/index.html
Normal file
@ -0,0 +1,11 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
</head>
|
||||
<body>
|
||||
<script src="/dist/elm.js"></script>
|
||||
<script> Elm.Main.init() </script>
|
||||
</body>
|
||||
</html>
|
63
examples/02-pages/src/Pages/Element.elm
Normal file
63
examples/02-pages/src/Pages/Element.elm
Normal file
@ -0,0 +1,63 @@
|
||||
module Pages.Element exposing (Model, Msg, page)
|
||||
|
||||
import Gen.Params.Element exposing (Params)
|
||||
import Page exposing (Page)
|
||||
import Request exposing (Request)
|
||||
import Shared
|
||||
import View exposing (View)
|
||||
|
||||
|
||||
page : Shared.Model -> Request Params -> Page Model Msg
|
||||
page shared req =
|
||||
Page.element
|
||||
{ init = init
|
||||
, update = update
|
||||
, view = view
|
||||
, subscriptions = subscriptions
|
||||
}
|
||||
|
||||
|
||||
|
||||
-- INIT
|
||||
|
||||
|
||||
type alias Model =
|
||||
{}
|
||||
|
||||
|
||||
init : ( Model, Cmd Msg )
|
||||
init =
|
||||
( {}, Cmd.none )
|
||||
|
||||
|
||||
|
||||
-- UPDATE
|
||||
|
||||
|
||||
type Msg
|
||||
= ReplaceMe
|
||||
|
||||
|
||||
update : Msg -> Model -> ( Model, Cmd Msg )
|
||||
update msg model =
|
||||
case msg of
|
||||
ReplaceMe ->
|
||||
( model, Cmd.none )
|
||||
|
||||
|
||||
|
||||
-- SUBSCRIPTIONS
|
||||
|
||||
|
||||
subscriptions : Model -> Sub Msg
|
||||
subscriptions model =
|
||||
Sub.none
|
||||
|
||||
|
||||
|
||||
-- VIEW
|
||||
|
||||
|
||||
view : Model -> View Msg
|
||||
view model =
|
||||
View.placeholder "Element"
|
11
examples/02-pages/src/Pages/Home_.elm
Normal file
11
examples/02-pages/src/Pages/Home_.elm
Normal file
@ -0,0 +1,11 @@
|
||||
module Pages.Home_ exposing (view)
|
||||
|
||||
import Html
|
||||
import View exposing (View)
|
||||
|
||||
|
||||
view : View Never
|
||||
view =
|
||||
{ title = "Homepage"
|
||||
, body = [ Html.text "Hello, world!" ]
|
||||
}
|
14
examples/02-pages/src/Pages/Static.elm
Normal file
14
examples/02-pages/src/Pages/Static.elm
Normal file
@ -0,0 +1,14 @@
|
||||
module Pages.Static exposing (page)
|
||||
|
||||
import Page
|
||||
import View
|
||||
|
||||
|
||||
page shared req =
|
||||
Page.static
|
||||
{ view = view
|
||||
}
|
||||
|
||||
|
||||
view =
|
||||
View.placeholder "Static"
|
5
examples/03-user-auth/.gitignore
vendored
Normal file
5
examples/03-user-auth/.gitignore
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
.DS_Store
|
||||
.elm-spa
|
||||
elm-stuff
|
||||
node_modules
|
||||
dist
|
28
examples/03-user-auth/README.md
Normal file
28
examples/03-user-auth/README.md
Normal file
@ -0,0 +1,28 @@
|
||||
# my new project
|
||||
> 🌳 built with [elm-spa](https://elm-spa.dev)
|
||||
|
||||
## dependencies
|
||||
|
||||
This project requires the latest LTS version of [Node.js](https://nodejs.org/)
|
||||
|
||||
```bash
|
||||
npm install -g elm elm-spa
|
||||
```
|
||||
|
||||
## running locally
|
||||
|
||||
```bash
|
||||
elm-spa server # starts this app at http:/localhost:1234
|
||||
```
|
||||
|
||||
### other commands
|
||||
|
||||
```bash
|
||||
elm-spa add # add a new page to the application
|
||||
elm-spa build # production build
|
||||
elm-spa watch # runs build as you code (without the server)
|
||||
```
|
||||
|
||||
## learn more
|
||||
|
||||
You can learn more at [elm-spa.dev](https://elm-spa.dev)
|
27
examples/03-user-auth/elm.json
Normal file
27
examples/03-user-auth/elm.json
Normal file
@ -0,0 +1,27 @@
|
||||
{
|
||||
"type": "application",
|
||||
"source-directories": [
|
||||
"src",
|
||||
".elm-spa/defaults",
|
||||
".elm-spa/generated"
|
||||
],
|
||||
"elm-version": "0.19.1",
|
||||
"dependencies": {
|
||||
"direct": {
|
||||
"elm/browser": "1.0.2",
|
||||
"elm/core": "1.0.5",
|
||||
"elm/html": "1.0.0",
|
||||
"elm/json": "1.1.3",
|
||||
"elm/url": "1.0.0",
|
||||
"ryannhg/elm-spa": "5.2.0"
|
||||
},
|
||||
"indirect": {
|
||||
"elm/time": "1.0.0",
|
||||
"elm/virtual-dom": "1.0.2"
|
||||
}
|
||||
},
|
||||
"test-dependencies": {
|
||||
"direct": {},
|
||||
"indirect": {}
|
||||
}
|
||||
}
|
11
examples/03-user-auth/public/index.html
Normal file
11
examples/03-user-auth/public/index.html
Normal file
@ -0,0 +1,11 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
</head>
|
||||
<body>
|
||||
<script src="/dist/elm.js"></script>
|
||||
<script> Elm.Main.init() </script>
|
||||
</body>
|
||||
</html>
|
57
examples/03-user-auth/src/Pages/Dashboard.elm
Normal file
57
examples/03-user-auth/src/Pages/Dashboard.elm
Normal file
@ -0,0 +1,57 @@
|
||||
module Pages.Dashboard exposing (Model, Msg, page)
|
||||
|
||||
import Gen.Params.Dashboard exposing (Params)
|
||||
import Page exposing (Page)
|
||||
import Request exposing (Request)
|
||||
import Shared
|
||||
import View exposing (View)
|
||||
|
||||
|
||||
type alias User =
|
||||
()
|
||||
|
||||
|
||||
page : Shared.Model -> Request Params -> Page Model Msg
|
||||
page shared req =
|
||||
Page.protected.sandbox
|
||||
{ init = init
|
||||
, update = update
|
||||
, view = view
|
||||
}
|
||||
|
||||
|
||||
|
||||
-- INIT
|
||||
|
||||
|
||||
type alias Model =
|
||||
{}
|
||||
|
||||
|
||||
init : User -> Model
|
||||
init user =
|
||||
{}
|
||||
|
||||
|
||||
|
||||
-- UPDATE
|
||||
|
||||
|
||||
type Msg
|
||||
= ReplaceMe
|
||||
|
||||
|
||||
update : User -> Msg -> Model -> Model
|
||||
update user msg model =
|
||||
case msg of
|
||||
ReplaceMe ->
|
||||
model
|
||||
|
||||
|
||||
|
||||
-- VIEW
|
||||
|
||||
|
||||
view : User -> Model -> View Msg
|
||||
view user model =
|
||||
View.placeholder "Dashboard"
|
8
examples/03-user-auth/src/Pages/Home_.elm
Normal file
8
examples/03-user-auth/src/Pages/Home_.elm
Normal file
@ -0,0 +1,8 @@
|
||||
module Pages.Home_ exposing (view)
|
||||
|
||||
import View exposing (View)
|
||||
|
||||
|
||||
view : View Never
|
||||
view =
|
||||
View.placeholder "Home_"
|
9
examples/03-user-auth/src/Pages/SignIn.elm
Normal file
9
examples/03-user-auth/src/Pages/SignIn.elm
Normal file
@ -0,0 +1,9 @@
|
||||
module Pages.SignIn exposing (view)
|
||||
|
||||
import View exposing (View)
|
||||
|
||||
|
||||
view : View Never
|
||||
view =
|
||||
View.placeholder "SignIn"
|
||||
|
4
src/cli/package-lock.json
generated
4
src/cli/package-lock.json
generated
@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "elm-spa",
|
||||
"version": "6.0.6--beta",
|
||||
"version": "6.0.7--beta",
|
||||
"lockfileVersion": 2,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "elm-spa",
|
||||
"version": "6.0.6--beta",
|
||||
"version": "6.0.7--beta",
|
||||
"license": "BSD-3-Clause",
|
||||
"dependencies": {
|
||||
"chokidar": "3.4.2",
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "elm-spa",
|
||||
"version": "6.0.6--beta",
|
||||
"version": "6.0.7--beta",
|
||||
"description": "single page apps made easy",
|
||||
"bin": "dist/src/index.js",
|
||||
"scripts": {
|
||||
|
@ -20,27 +20,30 @@ import View exposing (View)
|
||||
|
||||
|
||||
|
||||
-- PROTECTED OPTIONS
|
||||
-- PROTECTED PAGES
|
||||
|
||||
|
||||
{-| Replace "()" with your User type
|
||||
{-| Replace "()" with your actual User type
|
||||
-}
|
||||
type alias User =
|
||||
()
|
||||
|
||||
|
||||
{-| This function attempts to get your user from shared state.
|
||||
-}
|
||||
getUser : Shared.Model -> Request () -> Maybe User
|
||||
getUser _ _ =
|
||||
Nothing
|
||||
{-| This function will run before any `protected` pages.
|
||||
|
||||
Here, you can provide logic on where to redirect if a user is not signed in. Here's an example:
|
||||
|
||||
case shared.user of
|
||||
Just user ->
|
||||
ElmSpa.Provide user
|
||||
|
||||
Nothing ->
|
||||
ElmSpa.RedirectTo Gen.Route.SignIn
|
||||
|
||||
{-| This is the route elm-spa redirects to when a user is not signed in on a protected page.
|
||||
-}
|
||||
unauthorizedRoute : Route
|
||||
unauthorizedRoute =
|
||||
Gen.Route.NotFound
|
||||
beforeProtectedInit : Shared.Model -> Request () -> ElmSpa.Protected User Route
|
||||
beforeProtectedInit shared req =
|
||||
ElmSpa.RedirectTo Gen.Route.NotFound
|
||||
|
||||
|
||||
|
||||
@ -48,7 +51,7 @@ unauthorizedRoute =
|
||||
|
||||
|
||||
type alias Page model msg =
|
||||
ElmSpa.Page Shared.Model Gen.Route.Route (Effect msg) (View msg) model msg
|
||||
ElmSpa.Page Shared.Model Route (Effect msg) (View msg) model msg
|
||||
|
||||
|
||||
static :
|
||||
@ -118,9 +121,8 @@ protected :
|
||||
-> Page model msg
|
||||
}
|
||||
protected =
|
||||
ElmSpa.protected
|
||||
ElmSpa.protected2
|
||||
{ effectNone = Effect.none
|
||||
, fromCmd = Effect.fromCmd
|
||||
, user = getUser
|
||||
, route = unauthorizedRoute
|
||||
, beforeInit = beforeProtectedInit
|
||||
}
|
||||
|
@ -13,7 +13,7 @@
|
||||
"elm/html": "1.0.0",
|
||||
"elm/json": "1.1.3",
|
||||
"elm/url": "1.0.0",
|
||||
"ryannhg/elm-spa": "5.1.0"
|
||||
"ryannhg/elm-spa": "5.2.0"
|
||||
},
|
||||
"indirect": {
|
||||
"elm/time": "1.0.0",
|
||||
|
@ -1,11 +1,11 @@
|
||||
export default (page : string[]) : string => `
|
||||
module Pages.${page.join('.')} exposing (page)
|
||||
module Pages.${page.join('.')} exposing (view)
|
||||
|
||||
import View exposing (View)
|
||||
|
||||
|
||||
page : View Never
|
||||
page =
|
||||
view : View Never
|
||||
view =
|
||||
View.placeholder "${page.join('.')}"
|
||||
|
||||
`.trimLeft()
|
Loading…
Reference in New Issue
Block a user