gampleman / elm-example-publisher

Make a beautiful website from your Elm examples
MIT License
18 stars 2 forks source link
elm static-site-generator

elm-example-publisher

This is a small script that generates a static website for showcasing visual examples of small Elm programs. An example in the wild is elm-visualization examples.

How it works?

This program will process stuff in stages:

1. Gathering all elligible examples

Generally you will want to make a directory (usually this is called /examples) full of little Elm programs that you will want to showcase. This script will read every Elm file in the directory and provided that it explicitely exports main it will consider it an example and process it.

Customized with:

2. Compiling examples

These programs should render some output that should all fit into some dimensions (the default is 990x504, but you can adjust the size as long as all examples have the same one). The script will compile each program (for this to work, you will also want to have an elm.json in the examples directory), compress and optimize it, and write it to a file.

Customized with:

3. Taking screenshots

For each program a Chromium instance will navigate to it and take a screenshot of the output. These screenshots are then made into a series of responsive images - the full size screenshot is the 3x version, and a smaller 2x and 1x version is made. These are then written to disk.

Customized with:

4. Publishing Ellies

Optionally, these programs will be automatically uploaded to Elllie, where users can play with them.

Customized with:

5. Building website

Then, the script will load a template Elm program (by default this program resides in /docs/Docs.elm) and run it to produce the relevant HTML. It will then compress and optimize this. It will copy any files from /docs/assets and write this all to the output dir.

Customized with:

Installation

npm i -g elm-example-publisher

Customizing the behavior

elm-example-publisher --help will show options that can be configured at runtime.

You can most easily modify the output by changing the /docs/Docs.elm template file. We provide a default template for you (used if /docs/Docs.elm isn't found), but we recommend you copy this to your project and customize as you see fit. You can find it here.

Finally, you can add @tags to your examples in the module comment. There are a few built in tags, but you also get access to the tags in your template. You can use that to implement categories for example.

Built in tags

@delay <seconds>

This will cause the screenshot to wait the specifified number of seconds. Useful if you need some time (for example to load some resources) before you want the screenshot taken.

@requires <relative file path>

Sometimes example depend on some asset being available - a texture, data file, etc. This attribute ensures that the build time server correctly serves this asset when screenshotting as well as copying the asset to the correct directory. It will also prefix this path with --base-url when uploading to Ellie.

@screenshot <string>

If the example is an app that can respond to fragment URLs you might want to take screenshots of every screen. You can repeat this tag and a screenshot will be created. For example

{-|
@screenshot foo
@screenshot bar
-}

Will create:

License

MIT