Skip to content

Commit f812b67

Browse files
committed
Setup elm-pages scenario, test path, and failing example
1 parent aff958f commit f812b67

File tree

19 files changed

+391
-4
lines changed

19 files changed

+391
-4
lines changed

compiler/src/Compile.hs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import qualified Lamdera.Wire3.Helpers as Lamdera.Wire
3939
import Lamdera
4040
import qualified CanSer.CanSer as ToSource
4141
import qualified Data.Text as T
42+
import qualified Ext.ElmPages.Check
4243

4344
-- import StandaloneInstances
4445

@@ -67,6 +68,8 @@ compile pkg ifaces modul = do
6768
canonical0 <- canonicalize pkg ifaces modul_
6869
-- () <- debugPassText "starting canonical2" "" (pure ())
6970

71+
onlyWhen (Src.getName modul == "Main") $ Ext.ElmPages.Check.isWireCompatible canonical0 ifaces
72+
7073
-- Add Canonical Wire gens, i.e. the `w2_[en|de]code_TYPENAME` functions
7174
canonical1 <- Lamdera.Wire3.Core.addWireGenerations canonical0 pkg ifaces modul_
7275
canonical2 <- Lamdera.Wire2.Core.addWireGenerations canonical1 pkg ifaces modul_

elm.cabal

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ Executable lamdera
5353
-- Elmx
5454
ext-common
5555
ext-sentry
56+
ext-elm-pages
5657

5758
Main-Is:
5859
Main.hs
@@ -293,17 +294,19 @@ Executable lamdera
293294
Wire.PrettyPrint
294295

295296
-- Elmx extensions
296-
-- Ext Common --
297+
-- ext-common
297298
Ext.Common
298299
Ext.ElmFormat
299300
Ext.Query.Canonical
300301
Ext.Query.Interfaces
301302

302-
303-
-- Ext-sentry
303+
-- ext-sentry
304304
Ext.Sentry
305305
Ext.Filewatch
306306

307+
-- ext-elm-pages
308+
Ext.ElmPages.Check
309+
307310
Build-depends:
308311
ansi-terminal,
309312
-- >= 0.8 && < 0.9,

test/Test.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,8 @@ For more information on how to use the GHCi debugger, see the GHC User's Guide.
8686

8787
-- target = buildTestHarnessToProductionJs
8888
-- target = checkProjectCompiles
89-
target = liveReloadLive
89+
-- target = liveReloadLive
90+
target = Lamdera.Compile.makeDev_ "/Users/mario/dev/projects/lamdera-compiler/test/scenario-elm-pages-incompatible-wire/.elm-pages/Main.elm"
9091

9192
-- target = do
9293
-- Dir.withCurrentDirectory "/Users/mario/dev/projects/lamdera-dashboard" $ Lamdera.CLI.Check.run () ()
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
node_modules/
2+
elm-stuff/
3+
dist/
4+
.elm-pages/
5+
functions/render/elm-pages-cli.js
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# README
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
module Api exposing (routes)
2+
3+
import ApiRoute exposing (ApiRoute)
4+
import DataSource exposing (DataSource)
5+
import Html exposing (Html)
6+
import Pages.Manifest as Manifest
7+
import Route exposing (Route)
8+
9+
10+
routes :
11+
DataSource (List Route)
12+
-> (Html Never -> String)
13+
-> List (ApiRoute ApiRoute.Response)
14+
routes getStaticRoutes htmlToString =
15+
[]
16+
17+
18+
manifest : Manifest.Config
19+
manifest =
20+
Manifest.init
21+
{ name = "Site Name"
22+
, description = "Description"
23+
, startUrl = Route.Index |> Route.toPath
24+
, icons = []
25+
}
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
module Route.Index exposing (Data, Model, Msg, route)
2+
3+
import DataSource exposing (DataSource)
4+
import Head
5+
import Head.Seo as Seo
6+
import Html
7+
import Html.Attributes as Attr
8+
import Pages.PageUrl exposing (PageUrl)
9+
import Pages.Url
10+
import RouteBuilder exposing (StatelessRoute, StaticPayload)
11+
import Shared
12+
import View exposing (View)
13+
14+
15+
type alias Model =
16+
{}
17+
18+
19+
type alias Msg =
20+
()
21+
22+
23+
type alias RouteParams =
24+
{}
25+
26+
27+
type alias Data =
28+
{}
29+
30+
31+
route : StatelessRoute RouteParams Data
32+
route =
33+
RouteBuilder.single
34+
{ head = head
35+
, data = data
36+
}
37+
|> RouteBuilder.buildNoState { view = view }
38+
39+
40+
data : DataSource Data
41+
data =
42+
DataSource.succeed Data
43+
44+
45+
head :
46+
StaticPayload Data RouteParams
47+
-> List Head.Tag
48+
head static =
49+
Seo.summary
50+
{ canonicalUrlOverride = Nothing
51+
, siteName = "elm-pages"
52+
, image =
53+
{ url = Pages.Url.external "TODO"
54+
, alt = "elm-pages logo"
55+
, dimensions = Nothing
56+
, mimeType = Nothing
57+
}
58+
, description = "Welcome to elm-pages!"
59+
, locale = Nothing
60+
, title = "elm-pages is running"
61+
}
62+
|> Seo.website
63+
64+
65+
view :
66+
Maybe PageUrl
67+
-> Shared.Model
68+
-> StaticPayload Data RouteParams
69+
-> View Msg
70+
view maybeUrl sharedModel static =
71+
{ title = "elm-pages is running"
72+
, body =
73+
[ Html.h1 [] [ Html.text "elm-pages is up and running!" ]
74+
, Html.h2 [] [ Html.text "Learn more" ]
75+
, Html.ul
76+
[]
77+
[ Html.li []
78+
[ Html.a [ Attr.href "https://elm-pages.com/docs/" ] [ Html.text "Framework documentation" ]
79+
]
80+
, Html.li
81+
[]
82+
[ Html.a [ Attr.href "https://package.elm-lang.org/packages/dillonkearns/elm-pages/latest/" ] [ Html.text "Elm package documentation" ]
83+
]
84+
]
85+
]
86+
}
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
module Shared exposing (Data, Model, Msg(..), SharedMsg(..), template)
2+
3+
import Browser.Navigation
4+
import DataSource
5+
import Html exposing (Html)
6+
import Pages.Flags
7+
import Pages.PageUrl exposing (PageUrl)
8+
import Path exposing (Path)
9+
import Route exposing (Route)
10+
import SharedTemplate exposing (SharedTemplate)
11+
import View exposing (View)
12+
13+
14+
template : SharedTemplate Msg Model Data msg
15+
template =
16+
{ init = init
17+
, update = update
18+
, view = view
19+
, data = data
20+
, subscriptions = subscriptions
21+
, onPageChange = Just OnPageChange
22+
}
23+
24+
25+
type Msg
26+
= OnPageChange
27+
{ path : Path
28+
, query : Maybe String
29+
, fragment : Maybe String
30+
}
31+
| SharedMsg SharedMsg
32+
33+
34+
type alias Data =
35+
()
36+
37+
38+
type SharedMsg
39+
= NoOp
40+
41+
42+
type alias Model =
43+
{ showMobileMenu : Bool
44+
}
45+
46+
47+
init :
48+
Maybe Browser.Navigation.Key
49+
-> Pages.Flags.Flags
50+
->
51+
Maybe
52+
{ path :
53+
{ path : Path
54+
, query : Maybe String
55+
, fragment : Maybe String
56+
}
57+
, metadata : route
58+
, pageUrl : Maybe PageUrl
59+
}
60+
-> ( Model, Cmd Msg )
61+
init navigationKey flags maybePagePath =
62+
( { showMobileMenu = False }
63+
, Cmd.none
64+
)
65+
66+
67+
update : Msg -> Model -> ( Model, Cmd Msg )
68+
update msg model =
69+
case msg of
70+
OnPageChange _ ->
71+
( { model | showMobileMenu = False }, Cmd.none )
72+
73+
SharedMsg globalMsg ->
74+
( model, Cmd.none )
75+
76+
77+
subscriptions : Path -> Model -> Sub Msg
78+
subscriptions _ _ =
79+
Sub.none
80+
81+
82+
data : DataSource.DataSource Data
83+
data =
84+
DataSource.succeed ()
85+
86+
87+
view :
88+
Data
89+
->
90+
{ path : Path
91+
, route : Maybe Route
92+
}
93+
-> Model
94+
-> (Msg -> msg)
95+
-> View msg
96+
-> { body : Html msg, title : String }
97+
view sharedData page model toMsg pageView =
98+
{ body = Html.div [] pageView.body
99+
, title = pageView.title
100+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
module Site exposing (config)
2+
3+
import DataSource exposing (DataSource)
4+
import Head
5+
import SiteConfig exposing (SiteConfig)
6+
7+
8+
config : SiteConfig
9+
config =
10+
{ canonicalUrl = "https://elm-pages.com"
11+
, head = head
12+
}
13+
14+
15+
head : DataSource (List Head.Tag)
16+
head =
17+
[ Head.sitemapLink "/sitemap.xml"
18+
]
19+
|> DataSource.succeed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
module View exposing (View, map, placeholder)
2+
3+
import Html exposing (Html)
4+
5+
6+
type alias View msg =
7+
{ title : String
8+
, body : List (Html msg)
9+
}
10+
11+
12+
map : (msg1 -> msg2) -> View msg1 -> View msg2
13+
map fn doc =
14+
{ title = doc.title
15+
, body = List.map (Html.map fn) doc.body
16+
}
17+
18+
19+
placeholder : String -> View msg
20+
placeholder moduleName =
21+
{ title = "Placeholder - " ++ moduleName
22+
, body = [ Html.text moduleName ]
23+
}

0 commit comments

Comments
 (0)