elm-pages-v3-beta/tests/__snapshots__/generated-files.test.js.snap
2020-09-12 09:16:56 -07:00

627 lines
21 KiB
Plaintext

// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`generate UI file 1`] = `
"port module Pages exposing (PathKey, allPages, allImages, internals, images, isValidRoute, pages, builtAt)
import Color exposing (Color)
import Pages.Internal
import Head
import Html exposing (Html)
import Json.Decode
import Json.Encode
import Pages.Platform
import Pages.Manifest exposing (DisplayMode, Orientation)
import Pages.Manifest.Category as Category exposing (Category)
import Url.Parser as Url exposing ((</>), s)
import Pages.ImagePath as ImagePath exposing (ImagePath)
import Pages.PagePath as PagePath exposing (PagePath)
import Pages.Directory as Directory exposing (Directory)
import Time
builtAt : Time.Posix
builtAt =
Time.millisToPosix 1589734402000
type PathKey
= PathKey
buildImage : List String -> ImagePath.Dimensions -> ImagePath PathKey
buildImage path dimensions =
ImagePath.build PathKey (\\"images\\" :: path) dimensions
buildPage : List String -> PagePath PathKey
buildPage path =
PagePath.build PathKey path
directoryWithIndex : List String -> Directory PathKey Directory.WithIndex
directoryWithIndex path =
Directory.withIndex PathKey allPages path
directoryWithoutIndex : List String -> Directory PathKey Directory.WithoutIndex
directoryWithoutIndex path =
Directory.withoutIndex PathKey allPages path
port toJsPort : Json.Encode.Value -> Cmd msg
port fromJsPort : (Json.Decode.Value -> msg) -> Sub msg
internals : Pages.Internal.Internal PathKey
internals =
{ applicationType = Pages.Internal.Browser
, toJsPort = toJsPort
, fromJsPort = fromJsPort identity
, content = content
, pathKey = PathKey
}
allPages : List (PagePath PathKey)
allPages =
[
]
pages =
{ directory = directoryWithoutIndex []
}
images =
{ staticHttpError = (buildImage [ \\"static-http-error.png\\" ] { width = 919, height = 105 })
, directory = directoryWithoutIndex []
}
allImages : List (ImagePath PathKey)
allImages =
[(buildImage [ \\"static-http-error.png\\" ] { width = 919, height = 105 })
]
isValidRoute : String -> Result String ()
isValidRoute route =
let
validRoutes =
List.map PagePath.toString allPages
in
if
(route |> String.startsWith \\"http://\\")
|| (route |> String.startsWith \\"https://\\")
|| (route |> String.startsWith \\"#\\")
|| (validRoutes |> List.member route)
then
Ok ()
else
(\\"Valid routes:\\\\n\\"
++ String.join \\"\\\\n\\\\n\\" validRoutes
)
|> Err
content : List ( List String, { extension: String, frontMatter : String, body : Maybe String } )
content =
[
]
"
`;
exports[`generate template module connector 1`] = `
"module TemplateDemultiplexer exposing (..)
import Browser
import Shared
import GlobalMetadata as M exposing (Metadata)
import Head
import Html exposing (Html)
import Pages
import Pages.PagePath exposing (PagePath)
import Pages.Platform
import Pages.StaticHttp as StaticHttp
import Site
import Template.BlogIndex
import Template.BlogPost
import Template.Documentation
import Template.Page
import Template.Showcase
type alias Model =
{ global : Shared.Model
, page : TemplateModel
, current :
Maybe
{ path :
{ path : PagePath Pages.PathKey
, query : Maybe String
, fragment : Maybe String
}
, metadata : Metadata
}
}
type TemplateModel
= ModelBlogIndex Template.BlogIndex.Model
| ModelBlogPost Template.BlogPost.Model
| ModelDocumentation Template.Documentation.Model
| ModelPage Template.Page.Model
| ModelShowcase Template.Showcase.Model
| NotFound
type Msg
= MsgGlobal Shared.Msg
| OnPageChange
{ path : PagePath Pages.PathKey
, query : Maybe String
, fragment : Maybe String
, metadata : Metadata
}
| MsgBlogIndex Template.BlogIndex.Msg
| MsgBlogPost Template.BlogPost.Msg
| MsgDocumentation Template.Documentation.Msg
| MsgPage Template.Page.Msg
| MsgShowcase Template.Showcase.Msg
view :
List ( PagePath Pages.PathKey, Metadata )
->
{ path : PagePath Pages.PathKey
, frontmatter : Metadata
}
->
StaticHttp.Request
{ view : Model -> Shared.RenderedBody -> { title : String, body : Html Msg }
, head : List (Head.Tag Pages.PathKey)
}
view siteMetadata page =
case page.frontmatter of
M.MetadataBlogIndex metadata ->
StaticHttp.map2
(\\\\data globalData ->
{ view =
\\\\model rendered ->
case model.page of
ModelBlogIndex subModel ->
Template.BlogIndex.template.view
siteMetadata
data
subModel
metadata
rendered
|> (\\\\{ title, body } ->
Shared.view
globalData
page
model.global
MsgGlobal
({ title = title, body = body }
|> Shared.map MsgBlogIndex
)
)
_ ->
{ title = \\"\\", body = Html.text \\"\\" }
, head = Template.BlogIndex.template.head data page.path metadata
}
)
(Template.BlogIndex.template.staticData siteMetadata)
(Shared.staticData siteMetadata)
M.MetadataBlogPost metadata ->
StaticHttp.map2
(\\\\data globalData ->
{ view =
\\\\model rendered ->
case model.page of
ModelBlogPost subModel ->
Template.BlogPost.template.view
siteMetadata
data
subModel
metadata
rendered
|> (\\\\{ title, body } ->
Shared.view
globalData
page
model.global
MsgGlobal
({ title = title, body = body }
|> Shared.map MsgBlogPost
)
)
_ ->
{ title = \\"\\", body = Html.text \\"\\" }
, head = Template.BlogPost.template.head data page.path metadata
}
)
(Template.BlogPost.template.staticData siteMetadata)
(Shared.staticData siteMetadata)
M.MetadataDocumentation metadata ->
StaticHttp.map2
(\\\\data globalData ->
{ view =
\\\\model rendered ->
case model.page of
ModelDocumentation subModel ->
Template.Documentation.template.view
siteMetadata
data
subModel
metadata
rendered
|> (\\\\{ title, body } ->
Shared.view
globalData
page
model.global
MsgGlobal
({ title = title, body = body }
|> Shared.map MsgDocumentation
)
)
_ ->
{ title = \\"\\", body = Html.text \\"\\" }
, head = Template.Documentation.template.head data page.path metadata
}
)
(Template.Documentation.template.staticData siteMetadata)
(Shared.staticData siteMetadata)
M.MetadataPage metadata ->
StaticHttp.map2
(\\\\data globalData ->
{ view =
\\\\model rendered ->
case model.page of
ModelPage subModel ->
Template.Page.template.view
siteMetadata
data
subModel
metadata
rendered
|> (\\\\{ title, body } ->
Shared.view
globalData
page
model.global
MsgGlobal
({ title = title, body = body }
|> Shared.map MsgPage
)
)
_ ->
{ title = \\"\\", body = Html.text \\"\\" }
, head = Template.Page.template.head data page.path metadata
}
)
(Template.Page.template.staticData siteMetadata)
(Shared.staticData siteMetadata)
M.MetadataShowcase metadata ->
StaticHttp.map2
(\\\\data globalData ->
{ view =
\\\\model rendered ->
case model.page of
ModelShowcase subModel ->
Template.Showcase.template.view
siteMetadata
data
subModel
metadata
rendered
|> (\\\\{ title, body } ->
Shared.view
globalData
page
model.global
MsgGlobal
({ title = title, body = body }
|> Shared.map MsgShowcase
)
)
_ ->
{ title = \\"\\", body = Html.text \\"\\" }
, head = Template.Showcase.template.head data page.path metadata
}
)
(Template.Showcase.template.staticData siteMetadata)
(Shared.staticData siteMetadata)
init :
Maybe Shared.Model
->
Maybe
{ path :
{ path : PagePath Pages.PathKey
, query : Maybe String
, fragment : Maybe String
}
, metadata : Metadata
}
-> ( Model, Cmd Msg )
init currentGlobalModel maybePagePath =
let
( sharedModel, globalCmd ) =
currentGlobalModel |> Maybe.map (\\\\m -> ( m, Cmd.none )) |> Maybe.withDefault (Shared.init maybePagePath)
page =
case maybePagePath |> Maybe.map .metadata of
Nothing ->
NotFound
Just meta ->
case meta of
M.MetadataBlogIndex metadata ->
Template.BlogIndex.template.init metadata
|> Tuple.first
|> ModelBlogIndex
M.MetadataBlogPost metadata ->
Template.BlogPost.template.init metadata
|> Tuple.first
|> ModelBlogPost
M.MetadataDocumentation metadata ->
Template.Documentation.template.init metadata
|> Tuple.first
|> ModelDocumentation
M.MetadataPage metadata ->
Template.Page.template.init metadata
|> Tuple.first
|> ModelPage
M.MetadataShowcase metadata ->
Template.Showcase.template.init metadata
|> Tuple.first
|> ModelShowcase
( templateModel, templateCmd ) =
load sharedModel page
in
( { global = sharedModel
, page = templateModel
, current = maybePagePath
}
, Cmd.batch
[ templateCmd
, globalCmd |> Cmd.map MsgGlobal
]
)
update : Msg -> Model -> ( Model, Cmd Msg )
update msg model =
case msg of
MsgGlobal msg_ ->
let
( sharedModel, globalCmd ) =
Shared.update msg_ model.global
( templateModel, templateCmd ) =
load sharedModel model.page
in
( { model
| global = sharedModel
, page = templateModel
}
, Cmd.batch
[ templateCmd
, globalCmd |> Cmd.map MsgGlobal
]
)
OnPageChange record ->
init (Just model.global) <|
Just
{ path =
{ path = record.path
, query = record.query
, fragment = record.fragment
}
, metadata = record.metadata
}
MsgBlogIndex msg_ ->
let
( updatedPageModel, pageCmd ) =
case ( model.page, model.current |> Maybe.map .metadata ) of
( ModelBlogIndex pageModel, Just (M.MetadataBlogIndex metadata) ) ->
Template.BlogIndex.template.update
metadata
msg_
pageModel
|> Tuple.mapBoth ModelBlogIndex (Cmd.map MsgBlogIndex)
_ ->
( model.page, Cmd.none )
in
( { model | page = updatedPageModel, global = save updatedPageModel model.global }, pageCmd )
MsgBlogPost msg_ ->
let
( updatedPageModel, pageCmd ) =
case ( model.page, model.current |> Maybe.map .metadata ) of
( ModelBlogPost pageModel, Just (M.MetadataBlogPost metadata) ) ->
Template.BlogPost.template.update
metadata
msg_
pageModel
|> Tuple.mapBoth ModelBlogPost (Cmd.map MsgBlogPost)
_ ->
( model.page, Cmd.none )
in
( { model | page = updatedPageModel, global = save updatedPageModel model.global }, pageCmd )
MsgDocumentation msg_ ->
let
( updatedPageModel, pageCmd ) =
case ( model.page, model.current |> Maybe.map .metadata ) of
( ModelDocumentation pageModel, Just (M.MetadataDocumentation metadata) ) ->
Template.Documentation.template.update
metadata
msg_
pageModel
|> Tuple.mapBoth ModelDocumentation (Cmd.map MsgDocumentation)
_ ->
( model.page, Cmd.none )
in
( { model | page = updatedPageModel, global = save updatedPageModel model.global }, pageCmd )
MsgPage msg_ ->
let
( updatedPageModel, pageCmd ) =
case ( model.page, model.current |> Maybe.map .metadata ) of
( ModelPage pageModel, Just (M.MetadataPage metadata) ) ->
Template.Page.template.update
metadata
msg_
pageModel
|> Tuple.mapBoth ModelPage (Cmd.map MsgPage)
_ ->
( model.page, Cmd.none )
in
( { model | page = updatedPageModel, global = save updatedPageModel model.global }, pageCmd )
MsgShowcase msg_ ->
let
( updatedPageModel, pageCmd ) =
case ( model.page, model.current |> Maybe.map .metadata ) of
( ModelShowcase pageModel, Just (M.MetadataShowcase metadata) ) ->
Template.Showcase.template.update
metadata
msg_
pageModel
|> Tuple.mapBoth ModelShowcase (Cmd.map MsgShowcase)
_ ->
( model.page, Cmd.none )
in
( { model | page = updatedPageModel, global = save updatedPageModel model.global }, pageCmd )
load : Shared.Model -> TemplateModel -> ( TemplateModel, Cmd Msg )
load sharedModel model =
case model of
ModelBlogIndex m ->
Template.BlogIndex.template.load sharedModel m
|> Tuple.mapFirst (ModelBlogIndex)
|> Tuple.mapSecond (Cmd.map MsgBlogIndex)
ModelBlogPost m ->
Template.BlogPost.template.load sharedModel m
|> Tuple.mapFirst (ModelBlogPost)
|> Tuple.mapSecond (Cmd.map MsgBlogPost)
ModelDocumentation m ->
Template.Documentation.template.load sharedModel m
|> Tuple.mapFirst (ModelDocumentation)
|> Tuple.mapSecond (Cmd.map MsgDocumentation)
ModelPage m ->
Template.Page.template.load sharedModel m
|> Tuple.mapFirst (ModelPage)
|> Tuple.mapSecond (Cmd.map MsgPage)
ModelShowcase m ->
Template.Showcase.template.load sharedModel m
|> Tuple.mapFirst (ModelShowcase)
|> Tuple.mapSecond (Cmd.map MsgShowcase)
NotFound ->
( model, Cmd.none )
save : TemplateModel -> Shared.Model -> Shared.Model
save model sharedModel=
case model of
ModelBlogIndex m ->
Template.BlogIndex.template.save m sharedModel
ModelBlogPost m ->
Template.BlogPost.template.save m sharedModel
ModelDocumentation m ->
Template.Documentation.template.save m sharedModel
ModelPage m ->
Template.Page.template.save m sharedModel
ModelShowcase m ->
Template.Showcase.template.save m sharedModel
NotFound ->
sharedModel
mainTemplate { documents, manifest, canonicalSiteUrl, subscriptions } =
Pages.Platform.init
{ init = init Nothing
, view = view
, update = update
, subscriptions = subscriptions
, documents = documents
, onPageChange = Just OnPageChange
, manifest = manifest -- Site.manifest
, canonicalSiteUrl = canonicalSiteUrl -- Site.canonicalUrl
, internals = Pages.internals
}
mapDocument : Browser.Document Never -> Browser.Document mapped
mapDocument document =
{ title = document.title
, body = document.body |> List.map (Html.map never)
}
"
`;