@@ -15,9 +15,13 @@
1515-}
1616module Language.Elm (
1717 compile, toHtml,
18− runtimeLocation
18+ moduleName,
19+ runtime, docs
1920 ) where
2021
22+import qualified Ast as Ast
23+import qualified Libraries as Libraries
24+import Data.List (intercalate)
2125import Data.Version (showVersion)
2226import CompileToJS
2327import ExtractNoscript
@@ -30,13 +34,17 @@ import Paths_Elm
3034import qualified Data.Text as TS
3135import qualified Data.Text.Lazy as TL
3236
33−-- |This function compiles Elm code to three separate parts: HTML, CSS,
34−-- and JavaScript. The HTML is only the contents of the body, so the three
35−-- parts must be combined in a basic HTML skeleton.
37+-- |This function compiles Elm code to JavaScript.
3638compile :: String -> String
37−compile source = either showErr jsModule modul
39+compile source = either showErr (jsModule . Libraries.addPrelude) modul
3840 where modul = buildFromSource source
3941
42+-- |This function extracts the module name of a given source program.
43+moduleName :: String -> String
44+moduleName source = either (const "Main") getName modul
45+ where modul = buildFromSource source
46+ getName (Ast.Module names _ _ _) = intercalate "." names
47+
4048-- |This function compiles Elm code into a full HTML page.
4149toHtml :: String -- ^ Location of elm-min.js as expected by the browser
4250 -> String -- ^ The page title
@@ -45,6 +53,10 @@ toHtml :: String -- ^ Location of elm-min.js as expected by the browser
4553toHtml = generateHtml
4654
4755-- |The absolute path to Elm's runtime system.
48−runtimeLocation :: IO FilePath
49−runtimeLocation = getDataFileName "elm-runtime.js"
56+runtime :: IO FilePath
57+runtime = getDataFileName "elm-runtime.js"
58+
59+-- |The absolute path to Elm's core library documentation.
60+docs :: IO FilePath
61+docs = getDataFileName "docs.json"
5062