Sign inSign up

julianbrendl/html-scala

By julianbrendl

•Updated over 7 years ago

Convert scala objects to HTML.

Image
0

100K+

julianbrendl/html-scala repository overview

⁠html-scala

Build Status

A simple, light-weight server that transpiles Scala code to HTML.

This project arose from the need to build React components using Scala. Under the hood, html-scala uses scalatags⁠. Look at scalatags to see what Scala code you can write and how it is transformed to HTML.

⁠Example:

Scala code:

new ReactComponent {
  def messageOfTheDay() = "Hello World!"
  
  override def render(): Text.TypedTag[String] = {
    div(
      h1("Amazing Title"),
      div(
       p("Message of the day: " + messageOfTheDay()),
       p("This is the first paragraph."),
       p("This is the second paragraph.")
      )
    )
  }
}

Resulting HTML:

<div>
  <h1>Amazing Title</h1>
  <div>
    <p>Message of the day: Hello World!</p>
    <p>This is the first paragraph.</p>
    <p>This is the second paragraph.</p>
  </div>
</div>

⁠API

⁠/transpile

Make a POST request to /transpile with the following payload as JSON:

{
  code: "code to transpile"
}

Important: The code has to be formatted as shown in the example above, using ReactComponent.

⁠/status

You can check the status of the service with a simple GET request to /status. If everything is okay, 200 should be returned.

⁠Docker

You can find this server as a docker image under julianbrendl/html-scala⁠.

Tag summary

Content type

Image

Digest

Size

765.4 MB

Last updated

over 7 years ago

docker pull julianbrendl/html-scala