Rename Document -> View.

This commit is contained in:
Dillon Kearns 2021-05-23 09:00:20 -07:00
parent e9d42d8a59
commit d908d8d01c
34 changed files with 221 additions and 241 deletions

View File

@ -92,7 +92,7 @@ You build the `template` using a builder chain, adding complexity as needed. You
module Template.Hello.Name_ exposing (Model, Msg, StaticData, template)
import DataSource
import Document exposing (Document)
import View exposing (View)
import Head
import Head.Seo as Seo
import Html exposing (text)

View File

@ -8,7 +8,7 @@ You build the `template` using a builder chain, adding complexity as needed. You
module Template.Hello.Name_ exposing (Model, Msg, StaticData, template)
import DataSource
import Document exposing (Document)
import View exposing (View)
import Head
import Head.Seo as Seo
import Html exposing (text)

View File

@ -1,35 +0,0 @@
module Document exposing (Document, View(..), map, placeholder)
import Html.Styled as Html exposing (Html)
type alias Document msg =
{ title : String
, body : View msg
}
map : (msg1 -> msg2) -> Document msg1 -> Document msg2
map fn doc =
{ title = doc.title
, body = mapView fn doc.body
}
type View msg
= ElmCssView (List (Html msg))
mapView : (msg1 -> msg2) -> View msg1 -> View msg2
mapView fn view =
case view of
ElmCssView elements ->
List.map (Html.map fn) elements
|> ElmCssView
placeholder : String -> Document msg
placeholder moduleName =
{ title = "Placeholder"
, body = ElmCssView [ Html.text moduleName ]
}

View File

@ -3,7 +3,6 @@ module Page.Blog exposing (Data, Model, Msg, page)
import Article
import DataSource
import Date
import Document exposing (Document)
import Head
import Head.Seo as Seo
import Html.Styled exposing (..)
@ -15,6 +14,7 @@ import Shared
import SiteOld
import Tailwind.Breakpoints as Bp
import Tailwind.Utilities as Tw
import View exposing (View)
type Msg
@ -73,7 +73,7 @@ view :
Model
-> Shared.Model
-> StaticPayload Data {}
-> Document Msg
-> View Msg
view thing model staticPayload =
{ title = "elm-pages blog"
, body =
@ -171,7 +171,6 @@ view thing model staticPayload =
]
]
]
|> Document.ElmCssView
}

View File

@ -8,7 +8,6 @@ import DataSource
import DataSource.File as StaticFile
import DataSource.Glob as Glob
import Date exposing (Date)
import Document exposing (Document)
import Head
import Head.Seo as Seo
import Html.Styled exposing (..)
@ -25,6 +24,7 @@ import StructuredData
import Tailwind.Breakpoints as Bp
import Tailwind.Utilities as Tw
import TailwindMarkdownRenderer
import View exposing (View)
type alias Model =
@ -72,7 +72,7 @@ routes =
view :
StaticPayload Data RouteParams
-> Document Msg
-> View Msg
view static =
{ title = static.data.metadata.title
, body =
@ -80,7 +80,6 @@ view static =
author =
Author.dillon
in
Document.ElmCssView
[ div
[ css
[ Tw.min_h_screen

View File

@ -6,7 +6,6 @@ import DataSource exposing (DataSource)
import DataSource.File
import DataSource.Glob as Glob exposing (Glob)
import DocsSection exposing (Section)
import Document exposing (Document)
import Head
import Head.Seo as Seo
import Heroicon
@ -25,6 +24,7 @@ import TableOfContents
import Tailwind.Breakpoints as Bp
import Tailwind.Utilities as Tw
import TailwindMarkdownRenderer
import View exposing (View)
type alias Model =
@ -193,11 +193,10 @@ view :
Model
-> Shared.Model
-> StaticPayload Data RouteParams
-> Document Msg
-> View Msg
view model sharedModel static =
{ title = static.data.titles.title ++ " - elm-pages docs"
, body =
Document.ElmCssView
[ Css.Global.global
[ Css.Global.selector ".anchor-icon"
[ Css.opacity Css.zero

View File

@ -2,7 +2,6 @@ module Page.Index exposing (Data, Model, Msg, page)
import Css
import DataSource exposing (DataSource)
import Document exposing (Document)
import Head
import Head.Seo as Seo
import Html.Styled exposing (..)
@ -16,6 +15,7 @@ import Svg.Styled exposing (path, svg)
import Svg.Styled.Attributes as SvgAttr
import Tailwind.Breakpoints as Bp
import Tailwind.Utilities as Tw
import View exposing (View)
import View.CodeTab as CodeTab
@ -86,14 +86,13 @@ head static =
view :
StaticPayload Data RouteParams
-> Document Msg
-> View Msg
view static =
{ title = "elm-pages - a statically typed site generator" -- metadata.title -- TODO
, body =
[ landingView
, gradientFeatures
]
|> Document.ElmCssView
}
@ -158,7 +157,7 @@ data routeParams =
view :
StaticPayload Data RouteParams
-> Document Msg
-> View Msg
view static =
{ title = static.routeParams.name
, body =

View File

@ -4,7 +4,6 @@ import DataSource exposing (DataSource)
import DataSource.File
import DataSource.Glob as Glob
import DataSource.Http
import Document exposing (Document)
import Head
import Head.Seo as Seo
import Html.Styled exposing (div, text)
@ -14,6 +13,7 @@ import Page exposing (Page, PageWithState, StaticPayload)
import Pages.ImagePath as ImagePath
import Secrets
import Tailwind.Utilities as Tw
import View exposing (View)
type alias Model =
@ -134,11 +134,10 @@ type alias Data =
view :
StaticPayload Data RouteParams
-> Document Msg
-> View Msg
view static =
{ title = "Projects"
, body =
Document.ElmCssView
[ div
[ css
[ Tw.pt_32

View File

@ -2,7 +2,6 @@ module Page.Showcase exposing (Data, Model, Msg, page)
import Css
import DataSource
import Document exposing (Document)
import Head
import Head.Seo as Seo
import Html.Styled exposing (..)
@ -13,6 +12,7 @@ import Showcase
import Tailwind.Breakpoints as Bp
import Tailwind.Utilities as Tw
import Url
import View exposing (View)
type alias Model =
@ -47,7 +47,7 @@ type alias Data =
view :
StaticPayload Data {}
-> Document Msg
-> View Msg
view static =
{ title = "elm-pages blog"
, body =
@ -77,7 +77,6 @@ view static =
[ showcaseEntries static.data ]
]
]
|> Document.ElmCssView
}

View File

@ -2,7 +2,6 @@ module Page.Time exposing (Data, Model, Msg, page)
import DataSource
import DataSource.Http
import Document exposing (Document)
import Head
import Head.Seo as Seo
import Html.Styled as Html
@ -11,6 +10,7 @@ import Page exposing (Page, PageWithState, StaticPayload)
import Pages.ImagePath as ImagePath
import Secrets
import Shared
import View exposing (View)
type alias Model =
@ -67,11 +67,10 @@ head static =
view :
StaticPayload Data {}
-> Document msg
-> View msg
view static =
{ title = "TODO title"
, body =
[ Html.text static.data
]
|> Document.ElmCssView
}

View File

@ -3,7 +3,6 @@ module Shared exposing (Data, Model, Msg, SharedMsg(..), template)
import Browser.Navigation
import DataSource
import DocsSection
import Document exposing (Document)
import Html exposing (Html)
import Html.Styled
import Json.Decode
@ -11,6 +10,7 @@ import Pages.Flags
import Pages.PagePath exposing (PagePath)
import SharedTemplate exposing (SharedTemplate)
import TableOfContents
import View exposing (View)
import View.Header
@ -119,17 +119,15 @@ view :
}
-> Model
-> (Msg -> msg)
-> Document msg
-> View msg
-> { body : Html msg, title : String }
view tableOfContents page model toMsg pageView =
{ body =
case pageView.body of
Document.ElmCssView elements ->
((View.Header.view ToggleMobileMenu 123 page.path
|> Html.Styled.map toMsg
)
:: TableOfContents.view model.showMobileMenu False Nothing tableOfContents
:: elements
:: pageView.body
)
|> Html.Styled.div []
|> Html.Styled.toUnstyled

View File

@ -0,0 +1,23 @@
module View exposing (View, map, placeholder)
import Html.Styled as Html exposing (Html)
type alias View msg =
{ title : String
, body : List (Html msg)
}
map : (msg1 -> msg2) -> View msg1 -> View msg2
map fn view =
{ title = view.title
, body = List.map (Html.map fn) view.body
}
placeholder : String -> View msg
placeholder moduleName =
{ title = "Placeholder"
, body = [ Html.text moduleName ]
}

View File

@ -1,13 +1,13 @@
module Page.Index exposing (Model, Msg, Data, page)
module Page.Index exposing (Data, Model, Msg, page)
import DataSource exposing (DataSource)
import Element exposing (Element)
import Document exposing (Document)
import Pages.ImagePath as ImagePath
import Head
import Head.Seo as Seo
import DataSource exposing (DataSource)
import Page exposing (Page, PageWithState, StaticPayload)
import Pages.ImagePath as ImagePath
import Shared
import Page exposing (StaticPayload, Page, PageWithState)
import View exposing (View)
type alias Model =
@ -17,9 +17,11 @@ type alias Model =
type alias Msg =
Never
type alias RouteParams =
{}
page : Page RouteParams Data
page =
Page.singleRoute
@ -34,7 +36,6 @@ data =
DataSource.succeed ()
head :
StaticPayload Data RouteParams
-> List Head.Tag
@ -61,6 +62,6 @@ type alias Data =
view :
StaticPayload Data RouteParams
-> Document Msg
-> View Msg
view static =
Document.placeholder "Index"

View File

@ -2,11 +2,11 @@ module Shared exposing (Data, Model, Msg(..), SharedMsg(..), template)
import Browser.Navigation
import DataSource
import Document exposing (Document)
import Html exposing (Html)
import Pages.Flags
import Pages.PagePath exposing (PagePath)
import SharedTemplate exposing (SharedTemplate)
import View exposing (View)
template : SharedTemplate Msg Model Data SharedMsg msg
@ -90,7 +90,7 @@ view :
}
-> Model
-> (Msg -> msg)
-> Document msg
-> View Msg
-> { body : Html msg, title : String }
view sharedData page model toMsg pageView =
{ body = Html.div [] pageView.body

View File

@ -1,22 +1,22 @@
module Document exposing (Document, map, placeholder)
module View exposing (View, map, placeholder)
import Html exposing (Html)
type alias Document msg =
type alias View msg =
{ title : String
, body : List (Html msg)
}
map : (msg1 -> msg2) -> Document msg1 -> Document msg2
map : (msg1 -> msg2) -> View msg1 -> View msg2
map fn doc =
{ title = doc.title
, body = List.map (Html.map fn) doc.body
}
placeholder : String -> Document msg
placeholder : String -> View msg
placeholder moduleName =
{ title = "Placeholder - " ++ moduleName
, body = [ Html.text moduleName ]

View File

@ -1,7 +1,6 @@
module Page.Cats.Name__ exposing (Data, Model, Msg, page)
import DataSource
import Document exposing (Document)
import Element exposing (Element)
import Head
import Head.Seo as Seo
@ -9,6 +8,7 @@ import Html.Styled exposing (text)
import Page exposing (Page, PageWithState, StaticPayload)
import Pages.ImagePath as ImagePath
import Shared
import View exposing (View)
type alias Model =
@ -74,7 +74,7 @@ type alias Data =
view :
StaticPayload Data RouteParams
-> Document Msg
-> View Msg
view static =
{ body =
[ text (static.routeParams.name |> Maybe.withDefault "NOTHING")

View File

@ -1,7 +1,6 @@
module Page.Date.SPLAT_ exposing (Data, Model, Msg, page)
import DataSource
import Document exposing (Document)
import Element exposing (Element)
import Head
import Head.Seo as Seo
@ -9,6 +8,7 @@ import Html.Styled exposing (text)
import Page exposing (Page, PageWithState, StaticPayload)
import Pages.ImagePath as ImagePath
import Shared
import View exposing (View)
type alias Model =
@ -63,7 +63,7 @@ type alias Data =
view :
StaticPayload Data RouteParams
-> Document Msg
-> View Msg
view static =
{ body =
[ Debug.toString static.routeParams |> text

View File

@ -1,7 +1,6 @@
module Page.SPLAT__ exposing (Data, Model, Msg, page)
import DataSource
import Document exposing (Document)
import Element exposing (Element)
import Head
import Head.Seo as Seo
@ -9,6 +8,7 @@ import Html.Styled exposing (text)
import Page exposing (Page, PageWithState, StaticPayload)
import Pages.ImagePath as ImagePath
import Shared
import View exposing (View)
type alias Model =
@ -53,7 +53,7 @@ type alias Data =
view :
StaticPayload Data RouteParams
-> Document Msg
-> View Msg
view static =
{ body =
[ Debug.toString static.routeParams |> text

View File

@ -1,12 +1,12 @@
module Page.Slide exposing (Data, Model, Msg, page)
import DataSource
import Document exposing (Document)
import Head
import Head.Seo as Seo
import Page exposing (Page, PageWithState, StaticPayload)
import Pages.ImagePath as ImagePath
import Shared
import View exposing (View)
type alias Model =
@ -56,7 +56,7 @@ type alias Data =
view :
StaticPayload Data RouteParams
-> Document Msg
-> View Msg
view static =
{ title = "TODO title"
, body = []

View File

@ -4,7 +4,6 @@ import Browser.Events
import Browser.Navigation
import DataSource
import DataSource.File
import Document exposing (Document)
import Head
import Head.Seo as Seo
import Html.Styled as Html
@ -19,6 +18,7 @@ import Page exposing (Page, StaticPayload)
import Pages.ImagePath as ImagePath
import Shared
import Tailwind.Utilities as Tw
import View exposing (View)
type alias Model =
@ -237,7 +237,7 @@ view :
Model
-> Shared.Model
-> StaticPayload Data RouteParams
-> Document Msg
-> View Msg
view model sharedModel static =
{ title = "TODO title"
, body =

View File

@ -4,7 +4,6 @@ import Browser.Navigation
import Css.Global
import DataSource
import DataSource.Http
import Document exposing (Document)
import Html exposing (Html)
import Html.Styled
import OptimizedDecoder as D
@ -13,6 +12,7 @@ import Pages.PagePath exposing (PagePath)
import Secrets
import SharedTemplate exposing (SharedTemplate)
import Tailwind.Utilities
import View exposing (View)
template : SharedTemplate Msg Model Data SharedMsg msg
@ -97,7 +97,7 @@ view :
}
-> Model
-> (Msg -> msg)
-> Document msg
-> View msg
-> { body : Html msg, title : String }
view stars page model toMsg pageView =
{ body =

View File

@ -1,22 +1,22 @@
module Document exposing (Document, map, placeholder)
module View exposing (View, map, placeholder)
import Html.Styled exposing (text)
type alias Document msg =
type alias View msg =
{ title : String
, body : List (Html.Styled.Html msg)
}
map : (msg1 -> msg2) -> Document msg1 -> Document msg2
map : (msg1 -> msg2) -> View msg1 -> View msg2
map fn doc =
{ title = doc.title
, body = List.map (Html.Styled.map fn) doc.body
}
placeholder : String -> Document msg
placeholder : String -> View msg
placeholder moduleName =
{ title = "Placeholder - " ++ moduleName
, body = [ text moduleName ]

View File

@ -1,7 +1,6 @@
module Page.Cats.Name__ exposing (Data, Model, Msg, page)
import DataSource
import Document exposing (Document)
import Element exposing (Element)
import Head
import Head.Seo as Seo
@ -9,6 +8,7 @@ import Html.Styled exposing (text)
import Page exposing (Page, PageWithState, StaticPayload)
import Pages.ImagePath as ImagePath
import Shared
import View exposing (View)
type alias Model =
@ -74,7 +74,7 @@ type alias Data =
view :
StaticPayload Data RouteParams
-> Document Msg
-> View Msg
view static =
{ body =
[ text (static.routeParams.name |> Maybe.withDefault "NOTHING")

View File

@ -1,12 +1,12 @@
module Page.Slide exposing (Data, Model, Msg, page)
import DataSource
import Document exposing (Document)
import Head
import Head.Seo as Seo
import Page exposing (Page, PageWithState, StaticPayload)
import Pages.ImagePath as ImagePath
import Shared
import View exposing (View)
type alias Model =
@ -56,7 +56,7 @@ type alias Data =
view :
StaticPayload Data RouteParams
-> Document Msg
-> View Msg
view static =
{ title = "TODO title"
, body = []

View File

@ -4,7 +4,6 @@ import Browser.Events
import Browser.Navigation
import DataSource
import DataSource.File
import Document exposing (Document)
import Head
import Head.Seo as Seo
import Html.Styled as Html
@ -19,6 +18,7 @@ import Page exposing (Page, StaticPayload)
import Pages.ImagePath as ImagePath
import Shared
import Tailwind.Utilities as Tw
import View exposing (View)
type alias Model =
@ -237,7 +237,7 @@ view :
Model
-> Shared.Model
-> StaticPayload Data RouteParams
-> Document Msg
-> View Msg
view model sharedModel static =
{ title = "TODO title"
, body =

View File

@ -3,13 +3,13 @@ module Shared exposing (Data, Model, Msg(..), SharedMsg(..), template)
import Browser.Navigation
import Css.Global
import DataSource
import Document exposing (Document)
import Html exposing (Html)
import Html.Styled
import Pages.Flags
import Pages.PagePath exposing (PagePath)
import SharedTemplate exposing (SharedTemplate)
import Tailwind.Utilities
import View exposing (View)
template : SharedTemplate Msg Model Data SharedMsg msg
@ -93,7 +93,7 @@ view :
}
-> Model
-> (Msg -> msg)
-> Document msg
-> View Msg
-> { body : Html msg, title : String }
view stars page model toMsg pageView =
{ body =

View File

@ -1,22 +1,22 @@
module Document exposing (Document, map, placeholder)
module View exposing (View, map, placeholder)
import Html.Styled exposing (text)
type alias Document msg =
type alias View msg =
{ title : String
, body : List (Html.Styled.Html msg)
}
map : (msg1 -> msg2) -> Document msg1 -> Document msg2
map : (msg1 -> msg2) -> View msg1 -> View msg2
map fn doc =
{ title = doc.title
, body = List.map (Html.Styled.map fn) doc.body
}
placeholder : String -> Document msg
placeholder : String -> View msg
placeholder moduleName =
{ title = "Placeholder - " ++ moduleName
, body = [ text moduleName ]

View File

@ -46,7 +46,7 @@ But before the user even requests the page, we have the following data:
import Browser.Navigation
import DataSource exposing (DataSource)
import Document exposing (Document)
import View exposing (View)
import Head
import Pages.PagePath exposing (PagePath)
import ServerRequest exposing (ServerRequest)
@ -61,7 +61,7 @@ type alias PageWithState routeParams templateData templateModel templateMsg =
templateModel
-> Shared.Model
-> StaticPayload templateData routeParams
-> Document templateMsg
-> View templateMsg
, head :
StaticPayload templateData routeParams
-> List Head.Tag
@ -103,7 +103,7 @@ type Builder routeParams templateData
buildNoState :
{ view :
StaticPayload templateData routeParams
-> Document Never
-> View Never
}
-> Builder routeParams templateData
-> PageWithState routeParams templateData () Never
@ -127,7 +127,7 @@ buildWithLocalState :
templateModel
-> Shared.Model
-> StaticPayload templateData routeParams
-> Document templateMsg
-> View templateMsg
, init : StaticPayload templateData routeParams -> ( templateModel, Cmd templateMsg )
, update : DynamicContext Shared.Model -> StaticPayload templateData routeParams -> templateMsg -> templateModel -> ( templateModel, Cmd templateMsg )
, subscriptions : routeParams -> PagePath -> templateModel -> Sub templateMsg
@ -177,7 +177,7 @@ buildWithSharedState :
templateModel
-> Shared.Model
-> StaticPayload templateData routeParams
-> Document templateMsg
-> View templateMsg
, init : StaticPayload templateData routeParams -> ( templateModel, Cmd templateMsg )
, update : DynamicContext Shared.Model -> StaticPayload templateData routeParams -> templateMsg -> templateModel -> ( templateModel, Cmd templateMsg, Maybe Shared.SharedMsg )
, subscriptions : routeParams -> PagePath -> templateModel -> Shared.Model -> Sub templateMsg

View File

@ -2,7 +2,7 @@ module SharedTemplate exposing (SharedTemplate)
import Browser.Navigation
import DataSource
import Document exposing (Document)
import View exposing (View)
import Html exposing (Html)
import Pages.Flags exposing (Flags)
import Pages.PagePath exposing (PagePath)
@ -32,7 +32,7 @@ type alias SharedTemplate msg sharedModel sharedData sharedMsg mappedMsg =
}
-> sharedModel
-> (msg -> mappedMsg)
-> Document mappedMsg
-> View mappedMsg
-> { body : Html mappedMsg, title : String }
, data : DataSource.DataSource sharedData
, subscriptions : PagePath -> sharedModel -> Sub msg

View File

@ -31,7 +31,7 @@ function fileContent(pageModuleName) {
function fileContentWithParams(pageModuleName) {
return `module Page.${pageModuleName} exposing (Model, Msg, Data, page)
import Document exposing (Document)
import View exposing (View)
import Pages.ImagePath as ImagePath
import Head
import Head.Seo as Seo
@ -109,7 +109,7 @@ view static =
function fileContentWithoutParams(pageModuleName) {
return `module Page.${pageModuleName} exposing (Model, Msg, Data, page)
import Document exposing (Document)
import View exposing (View)
import Pages.ImagePath as ImagePath
import Head
import Head.Seo as Seo

View File

@ -43,7 +43,7 @@ import Api
import ApiRoute
import Browser.Navigation
import Route exposing (Route)
import Document
import View
import Json.Decode
import Json.Encode
import Pages.Flags
@ -154,7 +154,7 @@ view page globalData pageData =
model.global
MsgGlobal
({ title = title, body = body }
|> Document.map Msg${pathNormalizedName(
|> View.map Msg${pathNormalizedName(
name
)}
)

View File

@ -3,20 +3,20 @@ module Document exposing (Document, map, placeholder)
import Html exposing (Html)
type alias Document msg =
type alias View Msg =
{ title : String
, body : List (Html msg)
}
map : (msg1 -> msg2) -> Document msg1 -> Document msg2
map : (msg1 -> msg2) -> View Msg1 -> View Msg2
map fn doc =
{ title = doc.title
, body = List.map (Html.map fn) doc.body
}
placeholder : String -> Document msg
placeholder : String -> View Msg
placeholder moduleName =
{ title = "Placeholder - " ++ moduleName
, body = [ Html.text moduleName ]

View File

@ -1,7 +1,7 @@
module Page.Index exposing (Data, Model, Msg, page)
import DataSource exposing (DataSource)
import Document exposing (Document)
import View exposing (View)
import Head
import Head.Seo as Seo
import Page exposing (Page, StaticPayload)
@ -60,6 +60,6 @@ type alias Data =
view :
StaticPayload Data RouteParams
-> Document Msg
-> View Msg
view static =
Document.placeholder "Index"

View File

@ -2,7 +2,7 @@ module Shared exposing (Data, Model, Msg(..), SharedMsg(..), template)
import Browser.Navigation
import DataSource
import Document exposing (Document)
import View exposing (View)
import Html exposing (Html)
import Pages.Flags
import Pages.PagePath exposing (PagePath)
@ -90,7 +90,7 @@ view :
}
-> Model
-> (Msg -> msg)
-> Document msg
-> View Msg
-> { body : Html msg, title : String }
view sharedData page model toMsg pageView =
{ body = Html.div [] pageView.body