@@ -15,9 +15,13 @@
16module Language.Elm (
16module Language.Elm (
17 compile, toHtml,
17 compile, toHtml,
18− runtimeLocation
18+ moduleName,
22+import qualified Ast as Ast
23+import qualified Libraries as Libraries
24+import Data.List (intercalate)
21import Data.Version (showVersion)
25import Data.Version (showVersion)
22import CompileToJS
26import CompileToJS
23import ExtractNoscript
27import ExtractNoscript
@@ -30,13 +34,17 @@ import Paths_Elm
30import qualified Data.Text as TS
34import qualified Data.Text as TS
31import qualified Data.Text.Lazy as TL
35import qualified Data.Text.Lazy as TL
33−-- |This function compiles Elm code to three separate parts: HTML, CSS,
37+-- |This function compiles Elm code to JavaScript.
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.
36compile :: String -> String
38compile :: String -> String
37−compile source = either showErr jsModule modul
39+compile source = either showErr (jsModule . Libraries.addPrelude) modul
38 where modul = buildFromSource source
40 where modul = buildFromSource source
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
40-- |This function compiles Elm code into a full HTML page.
48-- |This function compiles Elm code into a full HTML page.
41toHtml :: String -- ^ Location of elm-min.js as expected by the browser
49toHtml :: String -- ^ Location of elm-min.js as expected by the browser
42 -> String -- ^ The page title
50 -> String -- ^ The page title
@@ -45,6 +53,10 @@ toHtml :: String -- ^ Location of elm-min.js as expected by the browser
45toHtml = generateHtml
53toHtml = generateHtml
47-- |The absolute path to Elm's runtime system.
55-- |The absolute path to Elm's runtime system.
48−runtimeLocation :: IO FilePath
56+runtime :: IO FilePath
49−runtimeLocation = getDataFileName "elm-runtime.js"
57+runtime = getDataFileName "elm-runtime.js"
59+-- |The absolute path to Elm's core library documentation.
61+docs = getDataFileName "docs.json"