Include optional parameter for htmlToString configuration.

This commit is contained in:
Dillon Kearns 2022-10-29 19:38:19 +05:30
parent 7c9fb152c8
commit 6a06767120
18 changed files with 43 additions and 24 deletions

View File

@ -1687,7 +1687,7 @@ otherFile routes phaseString =
(Elm.Op.cons apiPatterns.reference
(Elm.apply (Elm.value { name = "routes", importFrom = [ "Api" ], annotation = Nothing })
[ getStaticRoutes.reference
, fnIgnore (Elm.string "")
, Elm.fn2 ( "a", Nothing ) ( "b", Nothing ) (\_ _ -> Elm.string "")
]
)
)
@ -1713,7 +1713,7 @@ otherFile routes phaseString =
(Elm.apply
(Elm.value { name = "routes", importFrom = [ "Api" ], annotation = Nothing })
[ getStaticRoutes.reference
, fnIgnore (Elm.string "")
, Elm.fn2 ( "a", Nothing ) ( "b", Nothing ) (\_ _ -> Elm.string "")
]
|> Gen.List.call_.map Gen.ApiRoute.values_.toJson
)
@ -1822,7 +1822,19 @@ otherFile routes phaseString =
}
globalHeadTags =
Elm.Declare.fn "globalHeadTags"
( "htmlToString", Type.function [ Gen.Html.annotation_.html Gen.Basics.annotation_.never ] Type.string |> Just )
( "htmlToString"
, Type.function
[ Type.maybe
(Type.record
[ ( "indent", Type.int )
, ( "newLines", Type.bool )
]
)
, Gen.Html.annotation_.html Gen.Basics.annotation_.never
]
Type.string
|> Just
)
(\htmlToString ->
Elm.Op.cons
(Elm.value

View File

@ -8,7 +8,7 @@ import Route exposing (Route)
routes :
DataSource (List Route)
-> (Html Never -> String)
-> (Maybe { indent : Int, newLines : Bool } -> Html Never -> String)
-> List (ApiRoute.ApiRoute ApiRoute.Response)
routes getStaticRoutes htmlToString =
[]

View File

@ -21,7 +21,7 @@ import Time
routes :
DataSource (List Route)
-> (Html Never -> String)
-> (Maybe { indent : Int, newLines : Bool } -> Html Never -> String)
-> List (ApiRoute.ApiRoute ApiRoute.Response)
routes getStaticRoutes htmlToString =
[ ApiRoute.succeed

View File

@ -22,7 +22,7 @@ import Xml.Decode
routes :
DataSource (List Route)
-> (Html Never -> String)
-> (Maybe { indent : Int, newLines : Bool } -> Html Never -> String)
-> List (ApiRoute.ApiRoute ApiRoute.Response)
routes getStaticRoutes htmlToString =
let

View File

@ -8,7 +8,7 @@ import Route exposing (Route)
routes :
DataSource (List Route)
-> (Html Never -> String)
-> (Maybe { indent : Int, newLines : Bool } -> Html Never -> String)
-> List (ApiRoute.ApiRoute ApiRoute.Response)
routes getStaticRoutes htmlToString =
[]

View File

@ -10,7 +10,7 @@ import Site
routes :
DataSource (List Route)
-> (Html Never -> String)
-> (Maybe { indent : Int, newLines : Bool } -> Html Never -> String)
-> List (ApiRoute.ApiRoute ApiRoute.Response)
routes getStaticRoutes htmlToString =
[ DataSource.succeed manifest |> Manifest.generator Site.canonicalUrl

View File

@ -9,7 +9,7 @@ import Route exposing (Route)
routes :
DataSource (List Route)
-> (Html Never -> String)
-> (Maybe { indent : Int, newLines : Bool } -> Html Never -> String)
-> List (ApiRoute ApiRoute.Response)
routes getStaticRoutes htmlToString =
[]

View File

@ -17,7 +17,7 @@ import Site
routes :
DataSource (List Route)
-> (Html Never -> String)
-> (Maybe { indent : Int, newLines : Bool } -> Html Never -> String)
-> List (ApiRoute.ApiRoute ApiRoute.Response)
routes getStaticRoutes htmlToString =
[ --nonHybridRoute

View File

@ -8,7 +8,7 @@ import Route exposing (Route)
routes :
DataSource (List Route)
-> (Html Never -> String)
-> (Maybe { indent : Int, newLines : Bool } -> Html Never -> String)
-> List (ApiRoute.ApiRoute ApiRoute.Response)
routes getStaticRoutes htmlToString =
[]

View File

@ -8,7 +8,7 @@ import Route exposing (Route)
routes :
DataSource (List Route)
-> (Html Never -> String)
-> (Maybe { indent : Int, newLines : Bool } -> Html Never -> String)
-> List (ApiRoute.ApiRoute ApiRoute.Response)
routes getStaticRoutes htmlToString =
[]

View File

@ -8,7 +8,7 @@ import Route exposing (Route)
routes :
DataSource (List Route)
-> (Html Never -> String)
-> (Maybe { indent : Int, newLines : Bool } -> Html Never -> String)
-> List (ApiRoute.ApiRoute ApiRoute.Response)
routes getStaticRoutes htmlToString =
[]

View File

@ -17,7 +17,7 @@ import Site
routes :
DataSource (List Route)
-> (Html Never -> String)
-> (Maybe { indent : Int, newLines : Bool } -> Html Never -> String)
-> List (ApiRoute.ApiRoute ApiRoute.Response)
routes getStaticRoutes htmlToString =
[ --nonHybridRoute

View File

@ -10,7 +10,7 @@ import Site
routes :
DataSource (List Route)
-> (Html Never -> String)
-> (Maybe { indent : Int, newLines : Bool } -> Html Never -> String)
-> List (ApiRoute.ApiRoute ApiRoute.Response)
routes getStaticRoutes htmlToString =
[ DataSource.succeed manifest |> Manifest.generator Site.canonicalUrl

View File

@ -17,7 +17,7 @@ import Site
routes :
DataSource (List Route)
-> (Html Never -> String)
-> (Maybe { indent : Int, newLines : Bool } -> Html Never -> String)
-> List (ApiRoute.ApiRoute ApiRoute.Response)
routes getStaticRoutes htmlToString =
[ --nonHybridRoute

View File

@ -9,7 +9,7 @@ import Route exposing (Route)
routes :
DataSource (List Route)
-> (Html Never -> String)
-> (Maybe { indent : Int, newLines : Bool } -> Html Never -> String)
-> List (ApiRoute ApiRoute.Response)
routes getStaticRoutes htmlToString =
[]

View File

@ -8,15 +8,19 @@ import Test.Html.Internal.ElmHtml.ToString exposing (defaultFormatOptions, nodeT
import VirtualDom
htmlToString : Html msg -> String
htmlToString viewHtml =
htmlToString : Maybe { indent : Int, newLines : Bool } -> Html msg -> String
htmlToString formatOptions viewHtml =
case
Decode.decodeValue
(decodeElmHtml (\_ _ -> VirtualDom.Normal (Decode.succeed ())))
(asJsonView viewHtml)
of
Ok str ->
nodeToStringWithOptions defaultFormatOptions str
nodeToStringWithOptions
(formatOptions
|> Maybe.withDefault defaultFormatOptions
)
str
Err err ->
"Error pre-rendering HTML in HtmlPrinter.elm: " ++ Decode.errorToString err

View File

@ -880,7 +880,7 @@ sendSinglePageProgress site contentJson config model info =
, headers = record.headers
}
{ head = config.view Dict.empty Dict.empty Nothing currentPage Nothing sharedData pageData Nothing |> .head
, view = viewValue.body |> List.map HtmlPrinter.htmlToString |> String.join "\n"
, view = viewValue.body |> List.map (HtmlPrinter.htmlToString Nothing) |> String.join "\n"
, title = viewValue.title
}
)
@ -1221,7 +1221,7 @@ render404Page config sharedData model path notFoundReason =
bodyToString : List (Html msg) -> String
bodyToString body =
body |> List.map HtmlPrinter.htmlToString |> String.join "\n"
body |> List.map (HtmlPrinter.htmlToString Nothing) |> String.join "\n"
urlToRoute : ProgramConfig userMsg userModel route pageData actionData sharedData effect mappedMsg errorPage -> Url -> route

View File

@ -88,7 +88,10 @@ type alias ProgramConfig userMsg userModel route pageData actionData sharedData
}
-> userMsg
, apiRoutes :
(Html Never -> String)
(Maybe { indent : Int, newLines : Bool }
-> Html Never
-> String
)
-> List (ApiRoute.ApiRoute ApiRoute.Response)
, pathPatterns : List RoutePattern
, basePath : List String
@ -98,7 +101,7 @@ type alias ProgramConfig userMsg userModel route pageData actionData sharedData
, encodeResponse : ResponseSketch pageData actionData sharedData -> Bytes.Encode.Encoder
, encodeAction : actionData -> Bytes.Encode.Encoder
, decodeResponse : Bytes.Decode.Decoder (ResponseSketch pageData actionData sharedData)
, globalHeadTags : Maybe ((Html Never -> String) -> DataSource (List Head.Tag))
, globalHeadTags : Maybe ((Maybe { indent : Int, newLines : Bool } -> Html Never -> String) -> DataSource (List Head.Tag))
, cmdToEffect : Cmd userMsg -> effect
, perform :
{ fetchRouteData :