Skip to content

Commit

Permalink
add an example and a test to prevent regressions
Browse files Browse the repository at this point in the history
  • Loading branch information
ryan-haskell committed Jun 22, 2023
1 parent 4097dca commit e6789f5
Show file tree
Hide file tree
Showing 11 changed files with 237 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/.vitepress/theme/components/ExampleGallery.vue
Expand Up @@ -20,6 +20,7 @@ export default {
{ kind: "official", title: "📊 Query Parameters", id: "06-query-parameters", src: "/images/guide/query-parameters.gif" },
{ kind: "official", title: "🧱 Working with JS", id: "07-working-with-js", src: "/images/examples/working-with-js.gif" },
{ kind: "official", title: "🪆 Nested Layouts", id: "08-nested-layouts", src: "/images/examples/nested-layouts.gif" },
{ kind: "official", title: "🪄 Catch-all Routes", id: "09-catch-all-routes", src: "/images/examples/catch-all-routes.jpg" },
{ kind: "official", title: "🧩 TypeScript Interop", id: "10-typescript-interop", src: "/images/examples/typescript.gif" },
{ kind: "official", title: "🚨 Error Reporting", id: "11-error-reporting", src: "/images/examples/sentry.gif" },
{ kind: "official", title: "🎨 Using Elm UI", id: "12-elm-ui", src: "/images/examples/elm-ui.jpg" },
Expand Down
Binary file added docs/public/images/examples/catch-all-routes.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions examples/09-catch-all-routes/.gitignore
@@ -0,0 +1,7 @@
/dist
/.elm-land
/.env
/elm-stuff
/node_modules
.DS_Store
*.pem
28 changes: 28 additions & 0 deletions examples/09-catch-all-routes/elm-land.json
@@ -0,0 +1,28 @@
{
"app": {
"elm": {
"development": { "debugger": true },
"production": { "debugger": false }
},
"env": [],
"html": {
"attributes": {
"html": { "lang": "en" },
"head": {}
},
"title": "Elm Land",
"meta": [
{ "charset": "UTF-8" },
{ "http-equiv": "X-UA-Compatible", "content": "IE=edge" },
{ "name": "viewport", "content": "width=device-width, initial-scale=1.0" }
],
"link": [
{ "rel": "stylesheet", "href": "/main.css" }
],
"script": []
},
"router": {
"useHashRouting": false
}
}
}
25 changes: 25 additions & 0 deletions examples/09-catch-all-routes/elm.json
@@ -0,0 +1,25 @@
{
"type": "application",
"source-directories": [
"src",
".elm-land/src"
],
"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"
},
"indirect": {
"elm/time": "1.0.0",
"elm/virtual-dom": "1.0.3"
}
},
"test-dependencies": {
"direct": {},
"indirect": {}
}
}
106 changes: 106 additions & 0 deletions examples/09-catch-all-routes/src/Pages/Home_.elm
@@ -0,0 +1,106 @@
module Pages.Home_ exposing (page)

import Html exposing (..)
import Html.Attributes exposing (..)
import Route.Path
import View exposing (View)


type alias Link =
{ label : String
, path : Route.Path.Path
}


page : View msg
page =
{ title = "Homepage"
, body =
[ h1 [] [ text "🏡 Homepage" ]
, p [] [ text "Click a link below to learn how URLs work in Elm Land" ]
, section []
[ h3 [] [ text "🧑\u{200D}💻 Users" ]
, viewLinks
[ { label = "@elm-land"
, path = Route.Path.User_ { user = "elm-land" }
}
, { label = "@ryannhg"
, path = Route.Path.User_ { user = "ryannhg" }
}
, { label = "@elm"
, path = Route.Path.User_ { user = "elm" }
}
]
]
, section []
[ h3 [] [ text "📦 Repos" ]
, viewLinks
[ { label = "@elm-land/vscode"
, path =
Route.Path.User__Repo_
{ user = "elm-land"
, repo = "vscode"
}
}
, { label = "@ryannhg/graphql"
, path =
Route.Path.User__Repo_
{ user = "ryannhg"
, repo = "graphql"
}
}
, { label = "@elm/compiler"
, path =
Route.Path.User__Repo_
{ user = "elm"
, repo = "compiler"
}
}
]
]
, section []
[ h3 [] [ text "🗃 File Explorer" ]
, viewLinks
[ { label = "README from @elm-land/vscode"
, path =
Route.Path.User__Repo__Tree_Branch__ALL_
{ user = "elm-land"
, repo = "vscode"
, branch = "main"
, all_ = [ "README.md" ]
}
}
, { label = "`Decode.elm` from @ryannhg/graphql"
, path =
Route.Path.User__Repo__Tree_Branch__ALL_
{ user = "ryannhg"
, repo = "graphql"
, branch = "main"
, all_ = [ "src", "GraphQL", "Decode.elm" ]
}
}
, { label = "`Compile.hs` from @elm/compiler"
, path =
Route.Path.User__Repo__Tree_Branch__ALL_
{ user = "elm"
, repo = "compiler"
, branch = "master"
, all_ = [ "compiler", "src", "Compile.hs" ]
}
}
]
]
]
}


viewLinks : List Link -> Html msg
viewLinks links =
ul [] (List.map viewLink links)


viewLink : Link -> Html msg
viewLink link =
li []
[ a [ Route.Path.href link.path ] [ text link.label ]
]
16 changes: 16 additions & 0 deletions examples/09-catch-all-routes/src/Pages/User_.elm
@@ -0,0 +1,16 @@
module Pages.User_ exposing (page)

import Html exposing (..)
import Route.Path
import View exposing (View)


page : { user : String } -> View msg
page params =
{ title = "@" ++ params.user ++ " | Users"
, body =
[ h1 [] [ text ("🧑\u{200D}💻 @" ++ params.user) ]
, p [] [ text "Hello from `src/Pages/User_.elm 👋" ]
, a [ Route.Path.href Route.Path.Home_ ] [ text "Back to homepage" ]
]
}
16 changes: 16 additions & 0 deletions examples/09-catch-all-routes/src/Pages/User_/Repo_.elm
@@ -0,0 +1,16 @@
module Pages.User_.Repo_ exposing (page)

import Html exposing (..)
import Route.Path
import View exposing (View)


page : { user : String, repo : String } -> View msg
page params =
{ title = "@" ++ params.user ++ "/" ++ params.repo ++ " | Repos"
, body =
[ h1 [] [ text ("📦 @" ++ params.user ++ "/" ++ params.repo) ]
, p [] [ text "Hello from `src/Pages/User_/Repo_.elm 👋" ]
, a [ Route.Path.href Route.Path.Home_ ] [ text "Back to homepage" ]
]
}
@@ -0,0 +1,22 @@
module Pages.User_.Repo_.Tree.Branch_.ALL_ exposing (page)

import Html exposing (..)
import Route.Path
import View exposing (View)


page :
{ user : String
, repo : String
, branch : String
, all_ : List String
}
-> View msg
page params =
{ title = "@" ++ params.user ++ "/" ++ params.repo ++ " | File Explorer"
, body =
[ h1 [] [ text ("🗃 ~/" ++ String.join "/" params.all_) ]
, p [] [ text "Hello from `src/Pages/User_/Repo_/Tree/Branch_/ALL_.elm 👋" ]
, a [ Route.Path.href Route.Path.Home_ ] [ text "Back to homepage" ]
]
}
10 changes: 10 additions & 0 deletions examples/09-catch-all-routes/static/main.css
@@ -0,0 +1,10 @@
body {
margin: 2rem auto;
padding: 0 2rem;
font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
max-width: 40em;
}

p {
color: #555;
}
6 changes: 6 additions & 0 deletions projects/cli/tests/08-examples.bats
Expand Up @@ -42,6 +42,12 @@ load helpers
expectElmExampleBuilds
}

@test "'09-catch-all-routes' example builds successfully" {
cd ../../examples/09-catch-all-routes
run npm install
expectElmExampleBuilds
}

@test "'10-typescript-interop' example builds successfully" {
cd ../../examples/10-typescript-interop
expectElmExampleBuilds
Expand Down

0 comments on commit e6789f5

Please sign in to comment.