krop icon indicating copy to clipboard operation
krop copied to clipboard

Template Subsystem

Open noelwelsh opened this issue 10 months ago • 0 comments

What we want from a templating system:

  • Runs on both client and server
  • Allows stand-alone templates or templates embedded in code
  • Provides type safety during construction
  • Allows construction of diffs for LiveView / HTML-on-the-wire style server side rendering
  • Can use standard HTML syntax, so developers can copy-and-paste examples

None of the existing systems achieve this. ScalaTags comes the closest, but it doesn't support standard HTML syntax. Twirl uses standard syntax but is server-side only and has no type safety. It would be useful to experiment with an alternative system.

A viable implementation path is:

  1. Develop a parser for HTML. We can assume a very simple structure and not allow omitting closing tags, CDATA, or other complications. This parser will need to able to splice in computed values, which implies suspending and resuming the parser. Look to see if Parsley can be used for this. If not, reviving Repast may be the way forward. ScalaTags is a reasonable target format for this translation for the first step.
  2. Provide the parser as a StringContext. Now we can write HTML snippets directly in code.
  3. Look at creating a sbt plugin like sbt-twirl to allow stand-alone templates. Sbt source generators is the API to hook into here.

There are a few optional extras:

  • Using scala-dom-types to provide additional type safety
  • Replacing ScalaTags with a more efficient format (e.g. one that streams directly to the response when running server side, instead of building a String in memory.)

If you are interested in applying for this project as a Google Summer of Code, please do not use this issue to discuss your application. The GSoC project description contains contact details.

noelwelsh avatar Feb 04 '25 14:02 noelwelsh