Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/orasund/elm-tracery
Interpreter for the Tracery language
https://github.com/orasund/elm-tracery
Last synced: about 1 month ago
JSON representation
Interpreter for the Tracery language
- Host: GitHub
- URL: https://github.com/orasund/elm-tracery
- Owner: Orasund
- License: bsd-3-clause
- Created: 2022-09-12T19:06:21.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2022-10-24T17:34:16.000Z (about 2 years ago)
- Last Synced: 2023-12-13T08:40:43.626Z (about 1 year ago)
- Language: HTML
- Homepage: https://orasund.github.io/elm-tracery/
- Size: 337 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# elm-tracery
Interpreter for the Tracery language.
See [Tracery.io](www.tracery.io) for more information.
## Installation
```
elm install Orasund/elm-tracery
```## How to use
```elm
import Tracery
import Random
import Json.Decodeseed : Random.Seed
seed =
Random.initialSeed 41"""
{ "origin":["I have a #favoriteAnimal# named #favoriteAnimalName# and a #animal# named #name#. I love #favoriteAnimalName# the most. It's the best #favoriteAnimal# in the world."]
, "favoriteAnimal" : "#color# #animal#"
, "color": ["white","black","brown"]
, "favoriteAnimalName" : "#name#"
, "animal":["cat","dog","parrot"]
, "name": ["Johnny","Charlie","Twinkle","Charles"]
}
"""
|> Tracery.fromJson
|> (\result ->
case result of
Err err -> Json.Decode.errorToString err
Ok grammar ->
Random.step (Tracery.run grammar) seed
|> Tuple.first
)
--> "I have a black cat named Charles and a parrot named Charlie. I love Charles the most. It's the best black cat in the world."
```## Differences to the original Tracery
* No support of "saving" values. Instead values can be constant.
* Entry point is always `"origin"`.
* Supporting sub-grammars in favor of the more experimental features of the original.