on 104faf1 help sign in
58 lines 2.1 kB history raw
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>
15-}
16module Language.Elm (
17 compile, toHtml,
18 moduleName,
19 runtime, docs
20 ) where
22import qualified Ast as Ast
23import qualified Libraries as Libraries
24import Data.List (intercalate)
25import Data.Version (showVersion)
26import CompileToJS (showErr, jsModule)
27import ExtractNoscript
28import GenerateHtml
29import Initialize
30import Text.Blaze.Html (Html)
31import Paths_Elm
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
48 -> Html
49toHtml = generateHtml
51-- |The absolute path to Elm's runtime system.
52runtime :: IO FilePath
53runtime = getDataFileName "elm-runtime.js"
55-- |The absolute path to Elm's core library documentation.
56docs :: IO FilePath
57docs = getDataFileName "docs.json"