1
0
mirror of https://codeberg.org/setop/elm-scripting synced 2025-11-08 21:49:57 +00:00
2025-10-05 01:35:45 +02:00
2025-10-05 01:35:45 +02:00
2025-10-05 01:35:45 +02:00
2025-10-02 19:08:12 +02:00
2025-10-05 01:35:45 +02:00
2025-10-02 19:08:12 +02:00
2025-10-02 19:08:12 +02:00
2025-10-02 19:08:12 +02:00
2025-10-05 01:35:45 +02:00
2025-10-05 01:35:45 +02:00

A tool to generate HTML code from Elm source in the terminal using QuickJS.

Requirements

  • depends only on elm compiler, quickjs cli and a posix shell
  • do not alter elm compiler
  • do not alter quickjs cli
  • do not patch elm compiler output
  • provide acceptable performances (500ms for a big script)

Design

QuickJS (Qjs) is a JavaScript runtime, similar to V8 or SpiderMonkey, but lighter and faster.

As any runtime, Qjs can interpret JavaScript code, but it is not a web browser. It has no concept of an HTML document.

To bridge this gap, we add a minimal DOM implementation.

Next, we concatenate this with the Elm JavaScript output and an app launcher snippet, then ask Qjs to interpret all of it.

Limitations

  • No event loop
  • Hence, no TEA; the main function must return a static view
  • Hence, no Time, no Random, no Json Encoder/Decoder (!), no Http
  • Nodes can only have one parent (this should always be the case)
  • Does not scale well : creating thousands of Nodes consumes a lot of RAM

Usage

  1. Clone this repository and navigate into your local copy
  2. Run elm init.
  3. Create src/Hello.elm with the following content:
module Hello exposing(main)

import Html exposing (p, text)

main = p [] [text "Hello World!"]
  1. Run ./build.sh src/Hello.elm; this generates the corresponding HTML code:
<p>
Hello World!
</p>

Performances

Acceptable for small scripts : 250ms on a modest x86_64 CPU and 64MB RAM for a 500 records into a table ; but is does not scale well as everything is loaded before processing ; no streaming contrary to the usual Unix way.

Generate 500k "li" loop took 17s and 900MB RAM.

Prior Work

There are more complete tools for generating static sites with Elm:

You should probably consider using one of them instead of this one. :)

Description
No description provided
Readme 47 KiB
Languages
JavaScript 75.2%
Shell 24.8%