Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rethinking Html Rendering, a la SSR #235

Merged
merged 3 commits into from
Dec 18, 2023

Conversation

davesmith00000
Copy link
Member

This is in response to issue #231, which calls for a nicer way to declare the doctype.

The old way of rendering HTML directly, which is to say not via the virtual dom, for the purposes of SSR or another JVM html use case, was to do something like this:

val includeDocType = true
val model = Int
val view = (i: Int) => html(p("count was " + i))

TyrianSSR.render(includeDocType, model, view)

Mostly ok, kinda, except that includeDocType is just a boolean, and I was quite taken by ScalaTags approach of just letting you prefix a string so that the doctype could be whatever you wanted.

So I took out includeDocType, and while wondering what do do next, I organised the render extensions methods, then I realised that asking someone to supply the view and the model, just so that I could call view(model).render for them in a clunky way via TyrianSSR.render was daft.

So now you just do any of these, and you're done:

view(model).render
p("Hello there!").render
p("Hello there!").toString

What about the doctype?! Well... it's just a string you prefix to your rendered HTML. Do you need me for that? 🤔

I have provided a constant for the default...

DOCTYPE +
  html(
    head(
      title("My Page")
    ),
    body(
      p(text("Hello, world!"))
    )
  )
// String: <!DOCTYPE HTML><html><head><title>My Page</title></head><body><p>Hello, world!</p></body></html>

@davesmith00000 davesmith00000 requested review from hobnob and a team December 16, 2023 22:15
@davesmith00000 davesmith00000 self-assigned this Dec 16, 2023
@davesmith00000 davesmith00000 merged commit cffee68 into main Dec 18, 2023
2 checks passed
@davesmith00000 davesmith00000 deleted the issue/231/ssr-doctype-rendering branch December 18, 2023 09:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant