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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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