snap-elm-0.1.0.1: Serve Elm files through the Snap web framework.

Safe HaskellNone

Snap.Elm

Description

This module provides a few functions for conveniently serving Elm files through the Snap web framework. Any changes made to the served files will be reflected in the browser upon a refresh.

The easiest way to get started is to use the default ElmOptions:

 app = makeSnaplet ... $ do
     opts <- defaultElmOptions
     ...
     addRoutes $ routes opts
     ...

Then, provide routes to the Elm runtime, and to any Elm files you wish to serve.

 routes opts =
     [ ("/elm", serveElm opts "static/elm/test.elm")
     , ...
     , serveElmRuntime opts
     ]

Additionally, you can customize the URI of the Elm runtime, the file path to the Elm runtime, or the paths to the directores that Elm will use to build and cache the compiled files.

 app = makeSnaplet ... $ do
     opts <- mkElmOptions
               "route/to/use/for/runtime.js"
               (Just "/my/own/local/file/for/the/actual/runtime.js")
               (Just "/tmp/location/for/build/dir")
               (Just "/tmp/location/for/cache/dir")
     ...
     addRoutes $ routes opts
     ...

Synopsis

Documentation

data ElmOptions Source

A set of options to coordinate the serving of Elm files and runtime.

mkElmOptionsSource

Arguments

:: MonadIO m 
=> ByteString

Route at which to serve Elm runtime

-> Maybe FilePath

FilePath to custom Elm runtime

-> Maybe FilePath

FilePath to custom build directory

-> Maybe FilePath

FilePath to custom cache directory

-> m ElmOptions 

Construct a custom set of options.

serveElm :: MonadSnap m => ElmOptions -> FilePath -> m ()Source

Serve an Elm file. The ElmOptions argument can be constructed at the initialization of your app.

serveElmRuntime :: MonadSnap m => ElmOptions -> (ByteString, m ())Source

A route handler for the Elm runtime. If given the ElmOptions used by serveElm, it will place the runtime at the route the Elm file will expect, as per the src=".../runtime.js" element included in the compiled file's head section.