Pass in static http no-op request as a prototype.

This commit is contained in:
Dillon Kearns 2019-10-13 17:35:34 -07:00
parent 130fe8c3ad
commit 8037ed33f5
6 changed files with 87 additions and 11 deletions

View File

@ -15,6 +15,8 @@ import Pages.ContentCache as ContentCache exposing (ContentCache)
import Pages.Document
import Pages.Manifest as Manifest
import Pages.PagePath as PagePath exposing (PagePath)
import Pages.StaticHttp as StaticHttp
import Pages.StaticHttpRequest as StaticHttpRequest
import Result.Extra
import Task exposing (Task)
import Url exposing (Url)
@ -53,13 +55,15 @@ mainView :
}
->
{ view :
userModel
staticData
-> userModel
-> view
->
{ title : String
, body : Html userMsg
}
, head : List (Head.Tag pathKey)
, staticRequest : StaticHttp.Request staticData
}
)
-> ModelDetails userModel metadata view
@ -95,13 +99,15 @@ pageViewOrError :
}
->
{ view :
userModel
staticData
-> userModel
-> view
->
{ title : String
, body : Html userMsg
}
, head : List (Head.Tag pathKey)
, staticRequest : StaticHttp.Request staticData
}
)
-> ModelDetails userModel metadata view
@ -113,6 +119,22 @@ pageViewOrError pathKey viewFn model cache =
case entry of
ContentCache.Parsed metadata viewResult ->
let
dummyInputString =
"TODO"
staticData =
(viewFn
(cache
|> Result.map (ContentCache.extractMetadata pathKey)
|> Result.withDefault []
-- TODO handle error better
)
{ path = pagePath, frontmatter = metadata }
|> .staticRequest
|> StaticHttpRequest.parser
)
dummyInputString
pageView =
viewFn
(cache
@ -125,7 +147,7 @@ pageViewOrError pathKey viewFn model cache =
in
case viewResult of
Ok viewList ->
pageView model.userModel viewList
pageView staticData model.userModel viewList
Err error ->
{ title = "Parsing error"
@ -162,13 +184,15 @@ view :
}
->
{ view :
userModel
staticData
-> userModel
-> view
->
{ title : String
, body : Html userMsg
}
, head : List (Head.Tag pathKey)
, staticRequest : StaticHttp.Request staticData
}
)
-> ModelDetails userModel metadata view
@ -233,13 +257,15 @@ init :
}
->
{ view :
userModel
staticData
-> userModel
-> view
->
{ title : String
, body : Html userMsg
}
, head : List (Head.Tag pathKey)
, staticRequest : StaticHttp.Request staticData
}
)
-> Content
@ -435,13 +461,15 @@ application :
}
->
{ view :
userModel
staticData
-> userModel
-> view
->
{ title : String
, body : Html userMsg
}
, head : List (Head.Tag pathKey)
, staticRequest : StaticHttp.Request staticData
}
, document : Pages.Document.Document metadata view
, content : Content
@ -502,13 +530,15 @@ cliApplication :
}
->
{ view :
userModel
staticData
-> userModel
-> view
->
{ title : String
, body : Html userMsg
}
, head : List (Head.Tag pathKey)
, staticRequest : StaticHttp.Request staticData
}
, document : Pages.Document.Document metadata view
, content : Content

View File

View File

@ -26,6 +26,7 @@ import Pages.Manifest as Manifest
import Pages.Manifest.Category
import Pages.PagePath as PagePath exposing (PagePath)
import Pages.Platform exposing (Page)
import Pages.StaticHttp as StaticHttp
import Palette
@ -110,18 +111,20 @@ view :
}
->
{ view :
Model
()
-> Model
-> View
->
{ title : String
, body : Html Msg
}
, head : List (Head.Tag Pages.PathKey)
, staticRequest : StaticHttp.Request ()
}
view siteMetadata page =
let
viewFn =
\model viewForPage ->
\() model viewForPage ->
pageView model
siteMetadata
{ path = page.path
@ -135,6 +138,7 @@ view siteMetadata page =
viewFn
, head =
head page.frontmatter
, staticRequest = StaticHttp.none
-- title = title
-- , body =

View File

@ -58,6 +58,8 @@ import Pages.Document as Document
import Pages.ImagePath as ImagePath exposing (ImagePath)
import Pages.PagePath as PagePath exposing (PagePath)
import Pages.Directory as Directory exposing (Directory)
import Pages.StaticHttp as StaticHttp
type PathKey
@ -100,13 +102,15 @@ application :
}
->
{ view :
userModel
staticData
-> userModel
-> view
->
{ title : String
, body : Html userMsg
}
, head : List (Head.Tag PathKey)
, staticRequest : StaticHttp.Request staticData
}
, documents : List ( String, Document.DocumentHandler metadata view )
, manifest : Pages.Manifest.Config PathKey
@ -193,13 +197,15 @@ application :
}
->
{ view :
userModel
staticData
-> userModel
-> view
->
{ title : String
, body : Html userMsg
}
, head : List (Head.Tag PathKey)
, staticRequest : StaticHttp.Request staticData
}
, documents : List ( String, Document.DocumentHandler metadata view )
, manifest : Pages.Manifest.Config PathKey

23
src/Pages/StaticHttp.elm Normal file
View File

@ -0,0 +1,23 @@
module Pages.StaticHttp exposing (Request, get, none)
import Pages.StaticHttpRequest exposing (Request(..))
get : String -> (String -> value) -> Request value
get url parser =
Request
{ parser = parser
, url = url
}
none : Request ()
none =
Request
{ parser = \_ -> ()
, url = "TODO"
}
type alias Request value =
Pages.StaticHttpRequest.Request value

View File

@ -0,0 +1,13 @@
module Pages.StaticHttpRequest exposing (Request(..), parser)
type Request value
= Request
{ parser : String -> value
, url : String
}
parser : Request value -> (String -> value)
parser (Request request) =
request.parser