mirror of
https://codeberg.org/setop/elm-scripting
synced 2025-11-08 21:49:57 +00:00
feat: can pass content as flags
This commit is contained in:
70
README.md
70
README.md
@@ -22,8 +22,8 @@ Next, we concatenate this with the Elm JavaScript output and an app launcher sni
|
||||
## Limitations
|
||||
|
||||
* No event loop
|
||||
* Hence, no [TEA](https://guide.elm-lang.org/architecture/); the `main` function must return a static view
|
||||
* Hence, no Time, no Random, no Json Encoder/Decoder (!), no Http
|
||||
* Hence, no [TEA](https://guide.elm-lang.org/architecture/); no `update` can be triggered
|
||||
* Hence, no Time, no Random, 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](#Performances)
|
||||
|
||||
@@ -37,19 +37,73 @@ Next, we concatenate this with the Elm JavaScript output and an app launcher sni
|
||||
```elm
|
||||
module Hello exposing(main)
|
||||
|
||||
import Html exposing (p, text)
|
||||
import Html exposing (text)
|
||||
|
||||
main = p [] [text "Hello World!"]
|
||||
main = text "Hello World!"
|
||||
```
|
||||
|
||||
4. Run `./build.sh src/Hello.elm`; this generates the corresponding HTML code:
|
||||
4. Run `./elmscript.sh src/Hello.elm`
|
||||
|
||||
```html
|
||||
<p>
|
||||
This produces the expected output:
|
||||
|
||||
```text
|
||||
Hello World!
|
||||
</p>
|
||||
```
|
||||
|
||||
## passing input
|
||||
|
||||
Input content can be passed to the script via the standard input. The content is then passed to the Elm script as "flags". The script must then use `Browser.element` and implement `init flags` function.
|
||||
|
||||
|
||||
Create `src/Greet.elm` with the following content:
|
||||
|
||||
```elm
|
||||
module Greet exposing (main)
|
||||
|
||||
import Browser
|
||||
import Html exposing (text)
|
||||
|
||||
|
||||
main =
|
||||
Browser.element
|
||||
{ init = \f -> (f, Cmd.none)
|
||||
, update = \m _ -> (m, Cmd.none)
|
||||
, view = \m -> text ("hello " ++ m)
|
||||
, subscriptions = always Sub.none
|
||||
}
|
||||
```
|
||||
|
||||
Run `./elmscript.sh src/Greet.elm <<< 'Elm'`
|
||||
|
||||
This produces the expected output: `hello Elm`.
|
||||
|
||||
|
||||
I's even more natural when passing file :
|
||||
|
||||
* run `elm install elm-explorations/markdown`
|
||||
* create `src/MdRender.elm` with the following content:
|
||||
|
||||
```elm
|
||||
module MdRender exposing (main)
|
||||
|
||||
import Browser
|
||||
import Html.Attributes exposing (class)
|
||||
import Markdown
|
||||
|
||||
main =
|
||||
Browser.element
|
||||
{ init = \s -> (s, Cmd.none)
|
||||
, update = \m c -> (m, Cmd.none)
|
||||
, view = \m -> Markdown.toHtml [class "content"] m
|
||||
, subscriptions = always Sub.none
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
* run `./elmscript.sh src/MdRender.elm < README.md > README.html`
|
||||
|
||||
|
||||
|
||||
## 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.
|
||||
|
||||
Reference in New Issue
Block a user