2012-05-30 17:59:54 +00:00
|
|
|
{-# LANGUAGE TypeSynonymInstances, FlexibleInstances #-}
|
2012-05-29 18:25:43 +00:00
|
|
|
{- | This module exports the functions necessary for compiling Elm code into the
|
2012-05-28 16:02:02 +00:00
|
|
|
respective HTML, JS and CSS code.
|
2012-05-28 14:43:56 +00:00
|
|
|
|
2013-03-11 01:52:16 +00:00
|
|
|
The type class @'ElmSource'@ requires an instance for all types that the Elm
|
|
|
|
compiler understands. The provided instances for String, Text and QuasiQuoted
|
|
|
|
Elm source code should be sufficient.
|
2012-05-28 16:33:15 +00:00
|
|
|
|
2013-03-11 01:52:16 +00:00
|
|
|
The documentation for the Elm language is available at
|
|
|
|
<http://elm-lang.org/Documentation.elm>, and many interactive examples are
|
|
|
|
available at <http://elm-lang.org/Examples.elm>
|
2012-05-30 20:24:33 +00:00
|
|
|
|
2013-03-11 01:52:16 +00:00
|
|
|
Example implementations using Yesod and Happstack are available
|
|
|
|
at <https://github.com/tazjin/Elm/tree/master/Examples>
|
2012-05-28 16:02:02 +00:00
|
|
|
-}
|
2012-05-28 14:43:56 +00:00
|
|
|
module Language.Elm (
|
2013-03-21 09:29:23 +00:00
|
|
|
compile, toHtml,
|
2013-04-04 17:37:43 +00:00
|
|
|
moduleName,
|
|
|
|
runtime, docs
|
2012-05-30 17:47:41 +00:00
|
|
|
) where
|
2012-05-28 14:43:56 +00:00
|
|
|
|
2013-04-04 17:37:43 +00:00
|
|
|
import qualified Ast as Ast
|
|
|
|
import qualified Libraries as Libraries
|
|
|
|
import Data.List (intercalate)
|
2012-10-03 07:17:09 +00:00
|
|
|
import Data.Version (showVersion)
|
2013-04-05 16:56:37 +00:00
|
|
|
import CompileToJS (showErr, jsModule)
|
2012-05-29 18:25:43 +00:00
|
|
|
import ExtractNoscript
|
|
|
|
import GenerateHtml
|
|
|
|
import Initialize
|
|
|
|
import Text.Blaze.Html (Html)
|
2012-10-03 06:47:46 +00:00
|
|
|
import Paths_Elm
|
2012-05-29 19:48:24 +00:00
|
|
|
|
2013-04-04 17:37:43 +00:00
|
|
|
-- |This function compiles Elm code to JavaScript.
|
2013-03-21 09:29:23 +00:00
|
|
|
compile :: String -> String
|
2013-04-08 08:48:30 +00:00
|
|
|
compile source = either showErr jsModule modul
|
|
|
|
where modul = buildFromSource True source
|
2013-03-21 09:29:23 +00:00
|
|
|
|
2013-04-04 17:37:43 +00:00
|
|
|
-- |This function extracts the module name of a given source program.
|
|
|
|
moduleName :: String -> String
|
|
|
|
moduleName source = either (const "Main") getName modul
|
2013-04-08 08:48:30 +00:00
|
|
|
where modul = buildFromSource False source
|
2013-04-04 17:37:43 +00:00
|
|
|
getName (Ast.Module names _ _ _) = intercalate "." names
|
|
|
|
|
2013-03-21 09:29:23 +00:00
|
|
|
-- |This function compiles Elm code into a full HTML page.
|
|
|
|
toHtml :: String -- ^ Location of elm-min.js as expected by the browser
|
|
|
|
-> String -- ^ The page title
|
|
|
|
-> String -- ^ The elm source code
|
|
|
|
-> Html
|
|
|
|
toHtml = generateHtml
|
|
|
|
|
2012-10-03 19:31:38 +00:00
|
|
|
-- |The absolute path to Elm's runtime system.
|
2013-04-04 17:37:43 +00:00
|
|
|
runtime :: IO FilePath
|
|
|
|
runtime = getDataFileName "elm-runtime.js"
|
|
|
|
|
|
|
|
-- |The absolute path to Elm's core library documentation.
|
|
|
|
docs :: IO FilePath
|
|
|
|
docs = getDataFileName "docs.json"
|
2012-10-03 06:47:46 +00:00
|
|
|
|