Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell98 |
A Haskell library wrapper around the Elm executable, to build files from within Haskell.
For more information on Elm, see http://elm-lang.org.
There are two main steps to using this library: converting Elm source to a Module structure, then compiling various modules.
To compile a string to a module, simply do
let auxModule = moduleFromString (pack "Aux") (pack $ "module Aux where\n" ++ "x = 3")
or
let mainModule = moduleFromString (pack "Main") (pack $ "import Aux\n" ++ "main = plainText (show Aux.x)")
Note that the first argument must match the name given in the module X where
declaration in your elm file.
Both arguments must be Text, not String.
You can use moduleFromFile
similarly.
Once you have some modules, you can compile them into JavaScript or HTML:
Right js <- buildModulesWithOptions defaultOptions mainModule [auxModule]
The first argument is always the module containing the main
definition for Elm.
The list is the list of all files which are dependencies of the main module.
Files are written to a temp directory, then compiled using the --make
option.
A current limitation is that only single-directory structures are supported.
- type Module = InternalModule
- type Javascript = Text
- data BuildOptions = BuildOptions {}
- type ModuleName = Text
- type ModuleSource = Text
- defaultOptions :: BuildOptions
- moduleFromString :: ModuleName -> ModuleSource -> Module
- moduleFromFile :: ModuleName -> FilePath -> IO Module
- buildModules :: Module -> [Module] -> IO (Either String Javascript)
- buildModulesWithOptions :: BuildOptions -> Module -> [Module] -> IO (Either String Javascript)
Documentation
type Javascript = Text Source
data BuildOptions Source
Abstraction for the options given to the elm executable Note that not all Elm options may be avaliable
type ModuleName = Text Source
type ModuleSource = Text Source
moduleFromString :: ModuleName -> ModuleSource -> Module Source
Generate a module with the given Module name (e.g. Foo
)
and the given source code
moduleFromFile :: ModuleName -> FilePath -> IO Module Source
Read a module from a file, with the given module name and file path
buildModules :: Module -> [Module] -> IO (Either String Javascript) Source
Build a group of elm modules with the elm
from the system `$PATH`
generating JavaScript using the default runtime location
buildModulesWithOptions :: BuildOptions -> Module -> [Module] -> IO (Either String Javascript) Source
Given an elm "main" module, and a list of other modules, compile them using the `--make` option and the given options