Remove toMsg and toGlobalMsg and change msg type for rendered document.

This commit is contained in:
Dillon Kearns 2020-09-01 22:38:57 -07:00
parent bddcd02141
commit 9e8659b305
10 changed files with 76 additions and 80 deletions

View File

@ -27,14 +27,27 @@ type alias Model =
}
type alias View =
( MarkdownRenderer.TableOfContents, List (Element Never) )
map : (msg1 -> msg2) -> PageView msg1 -> PageView msg2
map fn doc =
{ title = doc.title
, body = Element.map fn doc.body
}
type alias RenderedBody msg =
--mapRendered : (msg1 -> msg2) -> RenderedBody msg1 -> RenderedBody msg2
--mapRendered fn ( first, second ) =
-- ( first, second |> List.map (Element.map fn) )
type alias View msg =
( MarkdownRenderer.TableOfContents, List (Element msg) )
type alias RenderedBody =
( MarkdownRenderer.TableOfContents, List (Element Never) )
type alias PageView msg =
{ title : String, body : Element msg }
@ -84,7 +97,7 @@ view :
-> { a | path : PagePath Pages.PathKey }
-> Model
-> (Msg -> msg)
-> PageView Never
-> PageView msg
-> { body : Html msg, title : String }
view stars page model toMsg pageView =
{ body =
@ -106,7 +119,7 @@ view stars page model toMsg pageView =
Element.column [ Element.width Element.fill ]
[ header stars page.path |> Element.map toMsg
, incrementView model |> Element.map toMsg
, pageView.body |> Element.map never
, pageView.body
]
)
|> Element.layout

View File

@ -48,11 +48,7 @@ manifest =
}
type alias View =
( MarkdownRenderer.TableOfContents, List (Element Msg) )
main : Pages.Platform.Program TemplateDemultiplexer.Model TemplateDemultiplexer.Msg GlobalMetadata.Metadata Global.View
main : Pages.Platform.Program TemplateDemultiplexer.Model TemplateDemultiplexer.Msg GlobalMetadata.Metadata Global.RenderedBody
main =
TemplateDemultiplexer.mainTemplate
{ documents =

View File

@ -8,9 +8,7 @@ import Pages.StaticHttp as StaticHttp
simplest :
{ view :
(templateMsg -> msg)
-> (Global.Msg -> msg)
-> List ( PagePath pathKey, globalMetadata )
List ( PagePath pathKey, globalMetadata )
-> ()
-> templateMetadata
-> renderedTemplate
@ -20,12 +18,12 @@ simplest :
-> templateMetadata
-> List (Head.Tag pathKey)
}
-> Template pathKey templateMetadata renderedTemplate () () templateView templateMsg globalMetadata msg
-> Template pathKey templateMetadata renderedTemplate () () templateView templateMsg globalMetadata
simplest config =
template
{ view =
\toMsg toGlobalMsg allMetadata () model blogPost rendered ->
config.view toMsg toGlobalMsg allMetadata model blogPost rendered
\allMetadata () model blogPost rendered ->
config.view allMetadata model blogPost rendered
, head = \() -> config.head
, staticData = \_ -> StaticHttp.succeed ()
, init = \_ -> ( (), Cmd.none )
@ -37,9 +35,7 @@ simplest config =
simpler :
{ view :
(templateMsg -> msg)
-> (Global.Msg -> msg)
-> List ( PagePath pathKey, globalMetadata )
List ( PagePath pathKey, globalMetadata )
-> templateModel
-> templateMetadata
-> renderedTemplate
@ -51,12 +47,12 @@ simpler :
, init : templateMetadata -> ( templateModel, Cmd templateMsg )
, update : templateMetadata -> templateMsg -> templateModel -> ( templateModel, Cmd templateMsg )
}
-> Template pathKey templateMetadata renderedTemplate () templateModel templateView templateMsg globalMetadata msg
-> Template pathKey templateMetadata renderedTemplate () templateModel templateView templateMsg globalMetadata
simpler config =
template
{ view =
\toMsg toGlobalMsg allMetadata () model blogPost rendered ->
config.view toMsg toGlobalMsg allMetadata model blogPost rendered
\allMetadata () model blogPost rendered ->
config.view allMetadata model blogPost rendered
, head = \() -> config.head
, staticData = \_ -> StaticHttp.succeed ()
, init = config.init
@ -71,9 +67,7 @@ stateless :
List ( PagePath pathKey, globalMetadata )
-> StaticHttp.Request templateStaticData
, view :
(templateMsg -> msg)
-> (Global.Msg -> msg)
-> List ( PagePath pathKey, globalMetadata )
List ( PagePath pathKey, globalMetadata )
-> templateStaticData
-> templateMetadata
-> renderedTemplate
@ -84,12 +78,12 @@ stateless :
-> templateMetadata
-> List (Head.Tag pathKey)
}
-> Template pathKey templateMetadata renderedTemplate templateStaticData () templateView templateMsg globalMetadata msg
-> Template pathKey templateMetadata renderedTemplate templateStaticData () templateView templateMsg globalMetadata
stateless config =
template
{ view =
\toMsg toGlobalMsg allMetadata staticData () blogPost rendered ->
config.view toMsg toGlobalMsg allMetadata staticData blogPost rendered
\allMetadata staticData () blogPost rendered ->
config.view allMetadata staticData blogPost rendered
, head = config.head
, staticData = config.staticData
, init = \_ -> ( (), Cmd.none )
@ -104,9 +98,7 @@ template :
List ( PagePath pathKey, globalMetadata )
-> StaticHttp.Request templateStaticData
, view :
(templateMsg -> msg)
-> (Global.Msg -> msg)
-> List ( PagePath pathKey, globalMetadata )
List ( PagePath pathKey, globalMetadata )
-> templateStaticData
-> templateModel
-> templateMetadata
@ -122,19 +114,17 @@ template :
, save : templateModel -> Global.Model -> Global.Model
, load : Global.Model -> templateModel -> ( templateModel, Cmd templateMsg )
}
-> Template pathKey templateMetadata renderedTemplate templateStaticData templateModel templateView templateMsg globalMetadata msg
-> Template pathKey templateMetadata renderedTemplate templateStaticData templateModel templateView templateMsg globalMetadata
template config =
config
type alias Template pathKey templateMetadata renderedTemplate templateStaticData templateModel templateView templateMsg globalMetadata msg =
type alias Template pathKey templateMetadata renderedTemplate templateStaticData templateModel templateView templateMsg globalMetadata =
{ staticData :
List ( PagePath pathKey, globalMetadata )
-> StaticHttp.Request templateStaticData
, view :
(templateMsg -> msg)
-> (Global.Msg -> msg)
-> List ( PagePath pathKey, globalMetadata )
List ( PagePath pathKey, globalMetadata )
-> templateStaticData
-> templateModel
-> templateMetadata

View File

@ -21,7 +21,7 @@ type Msg
= Msg
template : TemplateDocument BlogIndex StaticData Model Msg msg
template : TemplateDocument BlogIndex StaticData Model Msg
template =
Template.template
{ view = view
@ -77,15 +77,13 @@ type alias View msg =
view :
(Msg -> msg)
-> (Global.Msg -> msg)
-> List ( PagePath Pages.PathKey, GlobalMetadata.Metadata )
List ( PagePath Pages.PathKey, GlobalMetadata.Metadata )
-> StaticData
-> Model
-> BlogIndex
-> Global.RenderedBody Never
-> { title : String, body : Element Never }
view toMsg toGlobalMsg allMetadata static model metadata rendered =
-> Global.RenderedBody
-> { title : String, body : Element Msg }
view allMetadata static model metadata rendered =
{ title = "elm-pages blog"
, body =
Element.column [ Element.width Element.fill ]

View File

@ -30,7 +30,7 @@ type Msg
= Msg
template : TemplateDocument BlogPost () Model Msg msg
template : TemplateDocument BlogPost () Model Msg
template =
Template.simpler
{ view = view
@ -98,14 +98,12 @@ update metadata msg model =
view :
(Msg -> msg)
-> (Global.Msg -> msg)
-> List ( PagePath Pages.PathKey, GlobalMetadata.Metadata )
List ( PagePath Pages.PathKey, GlobalMetadata.Metadata )
-> Model
-> BlogPost
-> Global.RenderedBody Never
-> { title : String, body : Element Never }
view toMsg toGlobalMsg allMetadata model blogPost rendered =
-> Global.RenderedBody
-> { title : String, body : Element Msg }
view allMetadata model blogPost rendered =
{ title = blogPost.title
, body =
Element.column [ Element.width Element.fill ]
@ -132,6 +130,7 @@ view toMsg toGlobalMsg allMetadata model blogPost rendered =
:: Palette.blogHeading blogPost.title
:: articleImageView blogPost.image
:: Tuple.second rendered
|> List.map (Element.map never)
)
]
}

View File

@ -32,7 +32,7 @@ type Msg
= Msg
template : TemplateDocument Documentation StaticData Model Msg msg
template : TemplateDocument Documentation StaticData Model Msg
template =
Template.template
{ view = view
@ -95,19 +95,18 @@ head static currentPath meta =
view :
(Msg -> msg)
-> (Global.Msg -> msg)
-> List ( PagePath Pages.PathKey, GlobalMetadata.Metadata )
List ( PagePath Pages.PathKey, GlobalMetadata.Metadata )
-> StaticData
-> Model
-> Documentation
-> Global.RenderedBody Never
-> { title : String, body : Element Never }
view toMsg toGlobalMsg allMetadata static model metadata rendered =
-> Global.RenderedBody
-> { title : String, body : Element Msg }
view allMetadata static model metadata rendered =
{ title = metadata.title
, body =
[ Element.row []
[ DocSidebar.view
[ counterView model
, DocSidebar.view
Pages.pages.index
allMetadata
|> Element.el [ Element.width (Element.fillPortion 2), Element.alignTop, Element.height Element.fill ]
@ -120,7 +119,7 @@ view toMsg toGlobalMsg allMetadata static model metadata rendered =
, Element.spacing 30
, Element.Region.mainContent
]
(Tuple.second rendered)
(Tuple.second rendered |> List.map (Element.map never))
]
]
]
@ -132,6 +131,11 @@ view toMsg toGlobalMsg allMetadata static model metadata rendered =
}
counterView : Model -> Element Msg
counterView model =
Element.text ""
tocView : MarkdownRenderer.TableOfContents -> Element msg
tocView toc =
Element.column [ Element.alignTop, Element.spacing 20 ]

View File

@ -28,7 +28,7 @@ type Msg
= Msg
template : TemplateDocument Page StaticData Model Msg msg
template : TemplateDocument Page StaticData Model Msg
template =
Template.simplest
{ view = view
@ -76,14 +76,12 @@ head currentPath meta =
view :
(Msg -> msg)
-> (Global.Msg -> msg)
-> List ( PagePath Pages.PathKey, GlobalMetadata.Metadata )
List ( PagePath Pages.PathKey, GlobalMetadata.Metadata )
-> Model
-> Page
-> Global.RenderedBody Never
-> { title : String, body : Element Never }
view toMsg toGlobalMsg allMetadata model metadata rendered =
-> Global.RenderedBody
-> { title : String, body : Element Msg }
view allMetadata model metadata rendered =
{ title = metadata.title
, body =
[ Element.column
@ -91,7 +89,7 @@ view toMsg toGlobalMsg allMetadata model metadata rendered =
, Element.spacing 60
, Element.Region.mainContent
]
(Tuple.second rendered)
(Tuple.second rendered |> List.map (Element.map never))
]
|> Element.textColumn
[ Element.width Element.fill

View File

@ -23,7 +23,7 @@ type Msg
= Msg
template : TemplateDocument Showcase StaticData Model Msg msg
template : TemplateDocument Showcase StaticData Model Msg
template =
Template.stateless
{ view = view
@ -47,14 +47,12 @@ type alias StaticData =
view :
(Msg -> msg)
-> (Global.Msg -> msg)
-> List ( PagePath Pages.PathKey, GlobalMetadata.Metadata )
List ( PagePath Pages.PathKey, GlobalMetadata.Metadata )
-> StaticData
-> Showcase
-> Global.RenderedBody Never
-> { title : String, body : Element Never }
view toMsg toGlobalMsg allMetadata static metadata rendered =
-> Global.RenderedBody
-> { title : String, body : Element Msg }
view allMetadata static metadata rendered =
{ title = "elm-pages blog"
, body =
Element.column [ Element.width Element.fill ]

View File

@ -18,5 +18,5 @@ type alias RenderedBody msg =
( MarkdownRenderer.TableOfContents, List (Element msg) )
type alias TemplateDocument templateMetadata templateStaticData templateModel templateMsg internalMsg =
Template Pages.PathKey templateMetadata (RenderedBody Never) templateStaticData templateModel (View Never) templateMsg GlobalMetadata.Metadata internalMsg
type alias TemplateDocument templateMetadata templateStaticData templateModel templateMsg =
Template Pages.PathKey templateMetadata Global.RenderedBody templateStaticData templateModel (View templateMsg) templateMsg GlobalMetadata.Metadata

View File

@ -60,7 +60,7 @@ view :
}
->
StaticHttp.Request
{ view : Model -> Global.View -> { title : String, body : Html Msg }
{ view : Model -> Global.RenderedBody -> { title : String, body : Html Msg }
, head : List (Head.Tag Pages.PathKey)
}
view siteMetadata page =
@ -74,8 +74,6 @@ view siteMetadata page =
case model.page of
Model${name} subModel ->
Template.${name}.template.view
Msg${name}
MsgGlobal
siteMetadata
data
subModel
@ -87,7 +85,9 @@ view siteMetadata page =
page
model.global
MsgGlobal
{ title = title, body = body }
({ title = title, body = body }
|> Global.map Msg${name}
)
)
_ ->