Copyright | (c) Joey Eremondi 2014 |
---|---|
License | BSD3 |
Maintainer | joey@eremondi.com |
Stability | experimental |
Safe Haskell | None |
Language | Haskell98 |
This library provides both runtime and Template Haskell functions which let you take multi-module Elm Programs and compile them to JavaScript. The main goal of this is to allow Elm to be used as a frontend for Haskell servers or Web apps. The library is independent of any specific framework, so it should work with Yesod, Snap, Happstack, Scotty, etc.
- compileAll :: [String] -> Either String (Map Name String)
- standalone :: Map Name String -> String
- addHeader :: String -> String
- deriveElmJS :: [String] -> ExpQ
- elmQuasi :: QuasiQuoter
- compileAndLinkAll :: [String] -> Either String String
Documentation
compileAll :: [String] -> Either String (Map Name String) Source
Given a list of strings containing the source code for elm modules, return a dictionary mapping names to their compiled JavaScript source. (This allows you to staticaly serve commonly used modules, such as the runtime). The runtime is included in this dictionary, with the key "Elm.Native.Runtime". Gives a string error in the event of failure.
standalone :: Map Name String -> String Source
Bundle the result of compilation into a single, standalone, JavaScript source file, including the Elm-runtime and the Elm header
addHeader :: String -> String Source
Add the JavaScript header which initializes the Elm object and allows sources to work together.
deriveElmJS :: [String] -> ExpQ Source
Derives the Template Haskell String literal correspondeing to the compiled and linked JavaScript from compiling the given modules. For example:
{-# LANGUAGE TemplateHaskell #-} myElmJS :: String myElmJS = $(deriveElmJS [myElmMain, someElmHelperLib])
The main use of this is to ensure that your Elm code is compiled into JavaScript at the same time your Haskell code is compiled.
elmQuasi :: QuasiQuoter Source
Derives the Template Haskell String literal correspondeing to the compiled and linked JavaScript for a given module For example:
{-#Language QuasiQuotes#-} myElmJS :: String myElmJS = [elmQuasi| module Main where x = 3 |]
This function is useful for small code snippets, but when dealing with multi-module Elm projects, deriveElmJS should be used. Note that the elm code is compiled to JS at when your Haskell code is compiled.
compileAndLinkAll :: [String] -> Either String String Source
Given a list of strings containing the source code for elm modules, compile the modules and bundle the result of compilation into a single, standalone, JavaScript source file, including the Elm-runtime and the Elm header. Gives a string error in the event of failure.