1{-# LANGUAGE TypeSynonymInstances, FlexibleInstances #-}
2{- | This module exports the functions necessary for compiling Elm code into the
3 respective HTML, JS and CSS code.
5 The type class @'ElmSource'@ requires an instance for all types that the Elm
6 compiler understands. The provided instances for String, Text and QuasiQuoted
7 Elm source code should be sufficient.
9 The documentation for the Elm language is available at
10 <http://elm-lang.org/Documentation.elm>, and many interactive examples are
11 available at <http://elm-lang.org/Examples.elm>
13 Example implementations using Yesod and Happstack are available
14 at <https://github.com/tazjin/Elm/tree/master/Examples>
22import qualified Ast as Ast
23import qualified Libraries as Libraries
24import Data.List (intercalate)
25import Data.Version (showVersion)
26import CompileToJS (showErr, jsModule)
30import Text.Blaze.Html (Html)
33-- |This function compiles Elm code to JavaScript.
34compile :: String -> String
35compile source = either showErr jsModule modul
36 where modul = buildFromSource True source
38-- |This function extracts the module name of a given source program.
39moduleName :: String -> String
40moduleName source = either (const "Main") getName modul
41 where modul = buildFromSource False source
42 getName (Ast.Module names _ _ _) = intercalate "." names
44-- |This function compiles Elm code into a full HTML page.
45toHtml :: String -- ^ Location of elm-min.js as expected by the browser
46 -> String -- ^ The page title
47 -> String -- ^ The elm source code
51-- |The absolute path to Elm's runtime system.
53runtime = getDataFileName "elm-runtime.js"
55-- |The absolute path to Elm's core library documentation.
57docs = getDataFileName "docs.json"
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list