Safe Haskell | None |
---|
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 <- setElmBuildPath "/tmp/elm" <$> setElmVerbose True <$> defaultElmOptions ... addRoutes $ routes opts ...
The FilePath
s supplied to setElm{Source,Build,Cache}Path can be
relative or absolute.
- data ElmOptions = ElmOptions {}
- defaultElmOptions :: MonadIO m => m ElmOptions
- setElmVerbose :: Bool -> ElmOptions -> ElmOptions
- setElmRuntimeURI :: ByteString -> ElmOptions -> ElmOptions
- setElmRuntimePath :: FilePath -> ElmOptions -> ElmOptions
- setElmSourcePath :: FilePath -> ElmOptions -> ElmOptions
- setElmBuildPath :: FilePath -> ElmOptions -> ElmOptions
- setElmCachePath :: FilePath -> ElmOptions -> ElmOptions
- serveElm :: MonadSnap m => ElmOptions -> FilePath -> m ()
- serveElmDirectory :: MonadSnap m => ElmOptions -> ByteString -> m ()
- serveElmDirectory' :: MonadSnap m => ElmOptions -> ByteString -> (ByteString, m ())
- serveElmRuntime :: MonadSnap m => ElmOptions -> (ByteString, m ())
Documentation
data ElmOptions Source
A set of options to coordinate the serving of Elm files and runtime.
defaultElmOptions :: MonadIO m => m ElmOptionsSource
The default set of options for serving Elm files. The values are as follows (IO aside):
ElmOptions { elmIsVerbose = False , elmRuntimeURI = "/static/js/elm-runtime.js" , elmRuntimePath = <Language.Elm.runtime> , elmSourcePath = "." , elmBuildPath = "elm-build" , elmCachePath = "elm-cache" }
setElmVerbose :: Bool -> ElmOptions -> ElmOptionsSource
Tell Elm to be verbose (print all executed commands and their output to stdout), or quiet (print nothing).
setElmRuntimeURI :: ByteString -> ElmOptions -> ElmOptionsSource
Set the URI at which to serve the Elm runtime JS file.
setElmRuntimePath :: FilePath -> ElmOptions -> ElmOptionsSource
Set the FilePath
to some custom Elm runtime.
setElmSourcePath :: FilePath -> ElmOptions -> ElmOptionsSource
Set the directory to look for .elm files.
This allows for the elm
binary to properly find
local Elm modules.
setElmBuildPath :: FilePath -> ElmOptions -> ElmOptionsSource
Set the directory to use for storing the compiled .html
that elm
produces.
setElmCachePath :: FilePath -> ElmOptions -> ElmOptionsSource
Set the directory to use for storing the .elmi and .elmo
files that elm
produces.
serveElm :: MonadSnap m => ElmOptions -> FilePath -> m ()Source
Compile and serve an Elm file.
:: MonadSnap m | |
=> ElmOptions | |
-> ByteString | Route parameter name by which to identify files |
-> m () |
Serve a directory of Elm files, using a route parameter.
For example, a list of routes could contain:
routes opts = [ ... , ("elm/:file", jerveElmDirectory opts "file") ]
Then, following the example, if the ElmOptions contained static/elm
as the sourcePath, the route elm/file.elm
would
be handled by serveElm file.elm
, run with the working directory
static/elm
.
serveElmDirectory' :: MonadSnap m => ElmOptions -> ByteString -> (ByteString, m ())Source
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.